Re: [Qemu-devel] memcpy speed (Re: [PATCH v2] netmap backend (revised))

2013-01-24 Thread Paolo Bonzini
Il 23/01/2013 17:03, Luigi Rizzo ha scritto:
 On Wed, Jan 23, 2013 at 02:03:17PM +0100, Stefan Hajnoczi wrote:
 On Wed, Jan 23, 2013 at 12:50:26PM +0100, Luigi Rizzo wrote:
 On Wed, Jan 23, 2013 at 12:10:55PM +0100, Stefan Hajnoczi wrote:
 On Tue, Jan 22, 2013 at 08:12:15AM +0100, Luigi Rizzo wrote:
 ...
 +// a fast copy routine only for multiples of 64 bytes, non overlapped.
 +static inline void
 +pkt_copy(const void *_src, void *_dst, int l)
 ...
 +*dst++ = *src++;
 +}
 +}

 I wonder how different FreeBSD bcopy() is from glibc memcpy() and if the
 optimization is even a win.  The glibc code is probably hand-written
 assembly that CPU vendors have contributed for specific CPU model
 families.

 Did you compare glibc memcpy() against pkt_copy()?

 I haven't tried in detail on glibc but will run some tests.  In any
 case not all systems have glibc, and on FreeBSD this pkt_copy was
 a significant win for small packets (saving some 20ns each; of
 course this counts only when you approach the 10 Mpps range, which
 is what you get with netmap, and of course when data is in cache).

 One reason pkt_copy gains something is that if it can assume there
 is extra space in the buffer, it can work on large chunks avoiding the extra
 jumps and instructions for the remaining 1-2-4 bytes.

 I'd like to drop this code or at least make it FreeBSD-specific since
 there's no guarantee that this is a good idea on any other libc.

 I'm even doubtful that it's always a win on FreeBSD.  You have a
 threshold to fall back to bcopy() and who knows what the best value
 for various CPUs is.
 
 indeed.
 With the attached program (which however might be affected by the
 fact that data is not used after copying) it seems that on a recent
 linux (using gcc 4.6.2) the fastest is __builtin_memcpy()
 
   ./testlock -m __builtin_memcpy -l 64
 
 (by a factor of 2 or more) whereas all the other methods have
 approximately the same speed.
 
 On FreeBSD (with clang, gcc 4.2.1, gcc 4.6.4) the pkt_copy() above
 
   ./testlock -m fastcopy -l 64
 
 is largely better than other methods. I am a bit puzzled why
 the builtin method on FreeBSD is not effective, but i will check
 on some other forum...

Perhaps a different default for -march/-mtune?

Paolo




Re: [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place

2013-01-24 Thread Andreas Färber
Am 16.01.2013 16:11, schrieb Andreas Färber:
 +static void raven_pcihost_finalizefn(Object *obj)
 +{
 +PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
 +
 +object_unref(OBJECT(s-pci_bus));
 +object_unref(OBJECT(s-pci_dev));
  }
[snip]

For the record, Paolo suggested to drop this finalizer again since the
unref'ing will be obsoleted with his reference counting series. I'll
post and apply v3 shortly and have left the macio series mostly as-is.

Andreas



Re: [Qemu-devel] Generalize MDIO framework

2013-01-24 Thread Edgar E. Iglesias
On Wed, Jan 23, 2013 at 04:15:24PM +, Grant Likely wrote:
 Hopefully I've responded to everyone's comments here. Edgar, I did end
 up fixing up xilinx_axienet, so can you take a look and make sure it is
 correct?

It was something like that I had in mind, thanks.



Re: [Qemu-devel] [PATCH] aio-posix: Fix return value of aio_poll()

2013-01-24 Thread Paolo Bonzini
Il 24/01/2013 08:42, Dietmar Maurer ha scritto:
 But when I use a thread it triggers the bug in bdrv_drain_all(). So
 how can I fix  bdrv_drain_all() if I use a separate thread to write data?

 The bug is, in all likelihood, in your own code.  Sorry. :)
 
 yes. I still not fully understand that aio code.
 
 If I detect a incomplete write, I register an aio handler like this:
 
 ret = write(fd, buf, count) 
  if (ret  0  (errno == EAGAIN || errno == EWOULDBLOCK) ) {
   ...
   qemu_aio_set_fd_handler(fd, NULL, vma_co_continue_write,  NULL, 
 mydata);
   qemu_coroutine_yield();
 
 But seems that qemu_aio_wait() returns false after that.
 
 I thought that should return true instead?

You need a flush handler (fourth argument to qemu_aio_set_fd_handler)
that returns true.

Paolo



Re: [Qemu-devel] [PATCH V2 1/6] trivial: etraxfs_eth: Eliminate checkpatch errors

2013-01-24 Thread Edgar E. Iglesias
On Wed, Jan 23, 2013 at 04:15:25PM +, Grant Likely wrote:
 This is a trivial patch to harmonize the coding style on
 hw/etraxfs_eth.c. This is in preparation to split off the bitbang mdio
 code into a separate file.

I applied this one, thanks.



 
 Cc: Peter Maydell peter.mayd...@linaro.org
 Cc: Paul Brook p...@codesourcery.com
 Cc: Edgar E. Iglesias edgar.igles...@gmail.com
 Cc: Anthony Liguori aligu...@us.ibm.com
 Cc: Andreas Färber afaer...@suse.de
 Signed-off-by: Grant Likely grant.lik...@secretlab.ca
 ---
  hw/etraxfs_eth.c |  922 
 +++---
  1 file changed, 466 insertions(+), 456 deletions(-)
 
 diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
 index ec23fa6..0b474c0 100644
 --- a/hw/etraxfs_eth.c
 +++ b/hw/etraxfs_eth.c
 @@ -35,582 +35,592 @@
  #define ADVERTISE_100HALF   0x0080  /* Try for 100mbps half-duplex */
  #define ADVERTISE_100FULL   0x0100  /* Try for 100mbps full-duplex */
  
 -/* 
 - * The MDIO extensions in the TDK PHY model were reversed engineered from 
 the 
 +/*
 + * The MDIO extensions in the TDK PHY model were reversed engineered from the
   * linux driver (PHYID and Diagnostics reg).
   * TODO: Add friendly names for the register nums.
   */
  struct qemu_phy
  {
 - uint32_t regs[32];
 +uint32_t regs[32];
  
 - int link;
 +int link;
  
 - unsigned int (*read)(struct qemu_phy *phy, unsigned int req);
 - void (*write)(struct qemu_phy *phy, unsigned int req, 
 -   unsigned int data);
 +unsigned int (*read)(struct qemu_phy *phy, unsigned int req);
 +void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int data);
  };
  
  static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req)
  {
 - int regnum;
 - unsigned r = 0;
 -
 - regnum = req  0x1f;
 -
 - switch (regnum) {
 - case 1:
 - if (!phy-link)
 - break;
 - /* MR1.  */
 - /* Speeds and modes.  */
 - r |= (1  13) | (1  14);
 - r |= (1  11) | (1  12);
 - r |= (1  5); /* Autoneg complete.  */
 - r |= (1  3); /* Autoneg able.  */
 - r |= (1  2); /* link.  */
 - break;
 - case 5:
 - /* Link partner ability.
 -We are kind; always agree with whatever best mode
 -the guest advertises.  */
 - r = 1  14; /* Success.  */
 - /* Copy advertised modes.  */
 - r |= phy-regs[4]  (15  5);
 - /* Autoneg support.  */
 - r |= 1;
 - break;
 - case 18:
 - {
 - /* Diagnostics reg.  */
 - int duplex = 0;
 - int speed_100 = 0;
 -
 - if (!phy-link)
 - break;
 -
 - /* Are we advertising 100 half or 100 duplex ? */
 - speed_100 = !!(phy-regs[4]  ADVERTISE_100HALF);
 - speed_100 |= !!(phy-regs[4]  ADVERTISE_100FULL);
 -
 - /* Are we advertising 10 duplex or 100 duplex ? */
 - duplex = !!(phy-regs[4]  ADVERTISE_100FULL);
 - duplex |= !!(phy-regs[4]  ADVERTISE_10FULL);
 - r = (speed_100  10) | (duplex  11);
 - }
 - break;
 -
 - default:
 - r = phy-regs[regnum];
 - break;
 - }
 - D(printf(\n%s %x = reg[%d]\n, __func__, r, regnum));
 - return r;
 +int regnum;
 +unsigned r = 0;
 +
 +regnum = req  0x1f;
 +
 +switch (regnum) {
 +case 1:
 +if (!phy-link) {
 +break;
 +}
 +/* MR1. */
 +/* Speeds and modes.  */
 +r |= (1  13) | (1  14);
 +r |= (1  11) | (1  12);
 +r |= (1  5); /* Autoneg complete.  */
 +r |= (1  3); /* Autoneg able. */
 +r |= (1  2); /* link. */
 +break;
 +case 5:
 +/* Link partner ability.
 +   We are kind; always agree with whatever best mode
 +   the guest advertises.  */
 +r = 1  14; /* Success.  */
 +/* Copy advertised modes.  */
 +r |= phy-regs[4]  (15  5);
 +/* Autoneg support.  */
 +r |= 1;
 +break;
 +case 18:
 +{
 +/* Diagnostics reg.  */
 +int duplex = 0;
 +int speed_100 = 0;
 +
 +if (!phy-link) {
 +break;
 +}
 +
 +/* Are we advertising 100 half or 100 duplex ? */
 +speed_100 = !!(phy-regs[4]  ADVERTISE_100HALF);
 +speed_100 |= !!(phy-regs[4]  ADVERTISE_100FULL);
 +
 +/* Are we advertising 10 duplex or 100 duplex ? */
 +duplex = !!(phy-regs[4]  

[Qemu-devel] Where can I start?

2013-01-24 Thread 한상훈
 Hello, All
 
I want to analyze, Qemu Source Code, but It's too big and complex to start by 
myself.
Now, i'm trying to understand Make process and analyze 'Makefile'.
 
So, I'm writing this mail to get some advice as a new guy in Qemu-devel. 
I'm looking for the information about Whole QEMU architecture or process logic 
or build tree, kind of something. 
 
Please, help and let me get some useful information about Qemu source code. 
I want to understand the whole qemu logic.
I'll wait your help. 
 
Thanks.
 
내머릿속 난장판
오늘도 좋은 하루를 살 수 있기를

Re: [Qemu-devel] [PATCH V14 02/10] build: use check-clean in root Makefile

2013-01-24 Thread Paolo Bonzini
Il 24/01/2013 02:51, Wenchao Xia ha scritto:

 You can put the dependency in tests/Makefile.

 Paolo

   tests/Makefile would not be included, so it will directly fail.
 Actually I use this variable as a bridge between root Makefile and
 sub Makefile which would be included by root Makefile, just like
 $TOOL. In this way root Makefile can stay unchanged when new subdir
 is added, subdir's Makefile can add the step if it want been cleaned
 automatically when make clean is called in root dir.

What I mean is: add

clean: check-unit

in tests/Makefile.  You don't need a variable as an intermediate step.

Paolo



[Qemu-devel] [PATCH prep for-1.4 v3 2/2] prep_pci: Convert to QOM realizefn

2013-01-24 Thread Andreas Färber
SysBusDeviceClass' initfn merely calls SysBusDeviceClass::init, so we
can already hook up our own realizefn overwriting this behavior.

A symmetric unrealizefn is not necessary, knowing that the child's
unrealizefn is still no-op, too. Avoids ripping it out again when
recursive realization at DeviceState-level is implemented.

Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 hw/prep_pci.c |8 
 1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index e1420ca..52ee5d9 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -111,8 +111,9 @@ static void prep_set_irq(void *opaque, int irq_num, int 
level)
 qemu_set_irq(pic[irq_num] , level);
 }
 
-static int raven_pcihost_init(SysBusDevice *dev)
+static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
 {
+SysBusDevice *dev = SYS_BUS_DEVICE(d);
 PCIHostState *h = PCI_HOST_BRIDGE(dev);
 PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
 MemoryRegion *address_space_mem = get_system_memory();
@@ -141,7 +142,7 @@ static int raven_pcihost_init(SysBusDevice *dev)
 memory_region_add_subregion(address_space_mem, 0xbff0, s-intack);
 
 /* TODO Remove once realize propagates to child devices. */
-return qdev_init(DEVICE(s-pci_dev));
+object_property_set_bool(OBJECT(s-pci_dev), true, realized, errp);
 }
 
 static void raven_pcihost_initfn(Object *obj)
@@ -207,10 +208,9 @@ static const TypeInfo raven_info = {
 
 static void raven_pcihost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-k-init = raven_pcihost_init;
+dc-realize = raven_pcihost_realizefn;
 dc-fw_name = pci;
 dc-no_user = 1;
 }
-- 
1.7.10.4




[Qemu-devel] [PATCH prep for-1.4 v3 1/2] prep_pci: Create PCIBus and PCIDevice in-place

2013-01-24 Thread Andreas Färber
Prepares for QOM realizefn by removing object creation from qdev initfn.

Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 hw/prep_pci.c |   50 +-
 1 Datei geändert, 37 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)

diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index 212a2ac..e1420ca 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -2,6 +2,7 @@
  * QEMU PREP PCI host
  *
  * Copyright (c) 2006 Fabrice Bellard
+ * Copyright (c) 2011-2013 Andreas Färber
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the Software), to 
deal
@@ -24,12 +25,21 @@
 
 #include hw.h
 #include pci/pci.h
+#include pci/pci_bus.h
 #include pci/pci_host.h
 #include pc.h
 #include exec/address-spaces.h
 
+#define TYPE_RAVEN_PCI_DEVICE raven
 #define TYPE_RAVEN_PCI_HOST_BRIDGE raven-pcihost
 
+#define RAVEN_PCI_DEVICE(obj) \
+OBJECT_CHECK(RavenPCIState, (obj), TYPE_RAVEN_PCI_DEVICE)
+
+typedef struct RavenPCIState {
+PCIDevice dev;
+} RavenPCIState;
+
 #define RAVEN_PCI_HOST_BRIDGE(obj) \
 OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE)
 
@@ -38,12 +48,10 @@ typedef struct PRePPCIState {
 
 MemoryRegion intack;
 qemu_irq irq[4];
+PCIBus pci_bus;
+RavenPCIState pci_dev;
 } PREPPCIState;
 
-typedef struct RavenPCIState {
-PCIDevice dev;
-} RavenPCIState;
-
 static inline uint32_t PPC_PCIIO_config(hwaddr addr)
 {
 int i;
@@ -108,18 +116,13 @@ static int raven_pcihost_init(SysBusDevice *dev)
 PCIHostState *h = PCI_HOST_BRIDGE(dev);
 PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
 MemoryRegion *address_space_mem = get_system_memory();
-MemoryRegion *address_space_io = get_system_io();
-PCIBus *bus;
 int i;
 
 for (i = 0; i  4; i++) {
 sysbus_init_irq(dev, s-irq[i]);
 }
 
-bus = pci_register_bus(DEVICE(dev), NULL,
-   prep_set_irq, prep_map_irq, s-irq,
-   address_space_mem, address_space_io, 0, 4);
-h-bus = bus;
+pci_bus_irqs(s-pci_bus, prep_set_irq, prep_map_irq, s-irq, 4);
 
 memory_region_init_io(h-conf_mem, pci_host_conf_be_ops, s,
   pci-conf-idx, 1);
@@ -136,9 +139,29 @@ static int raven_pcihost_init(SysBusDevice *dev)
 
 memory_region_init_io(s-intack, PPC_intack_ops, s, pci-intack, 1);
 memory_region_add_subregion(address_space_mem, 0xbff0, s-intack);
-pci_create_simple(bus, 0, raven);
 
-return 0;
+/* TODO Remove once realize propagates to child devices. */
+return qdev_init(DEVICE(s-pci_dev));
+}
+
+static void raven_pcihost_initfn(Object *obj)
+{
+PCIHostState *h = PCI_HOST_BRIDGE(obj);
+PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
+MemoryRegion *address_space_mem = get_system_memory();
+MemoryRegion *address_space_io = get_system_io();
+DeviceState *pci_dev;
+
+pci_bus_new_inplace(s-pci_bus, DEVICE(obj), NULL,
+address_space_mem, address_space_io, 0);
+h-bus = s-pci_bus;
+
+object_initialize(s-pci_dev, TYPE_RAVEN_PCI_DEVICE);
+pci_dev = DEVICE(s-pci_dev);
+qdev_set_parent_bus(pci_dev, BUS(s-pci_bus));
+object_property_set_int(OBJECT(s-pci_dev), PCI_DEVFN(0, 0), addr,
+NULL);
+qdev_prop_set_bit(pci_dev, multifunction, false);
 }
 
 static int raven_init(PCIDevice *d)
@@ -176,7 +199,7 @@ static void raven_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo raven_info = {
-.name = raven,
+.name = TYPE_RAVEN_PCI_DEVICE,
 .parent = TYPE_PCI_DEVICE,
 .instance_size = sizeof(RavenPCIState),
 .class_init = raven_class_init,
@@ -196,6 +219,7 @@ static const TypeInfo raven_pcihost_info = {
 .name = TYPE_RAVEN_PCI_HOST_BRIDGE,
 .parent = TYPE_PCI_HOST_BRIDGE,
 .instance_size = sizeof(PREPPCIState),
+.instance_init = raven_pcihost_initfn,
 .class_init = raven_pcihost_class_init,
 };
 
-- 
1.7.10.4




[Qemu-devel] [PATCH prep for-1.4 v3 0/2] prep_pci: Prepare for QOM realize

2013-01-24 Thread Andreas Färber
Hello,

I'm going to apply the following slightly modified version to prep-up for 1.4.
It then represents the first fully QOM'ified PCI host bridge / SysBus device.

Regards,
Andreas

v2 - v3:
* Drop finalizefn, suggested by Paolo (a series of his will obsolete unref'ing).
  Since we don't hot-unplug the device, this avoids refactoring that code again.

v1 - v2:
* Rebased onto PCI header reorganization (pci_internal.h - pci/pci_bus.h).
* Replaced privatized object_finalize() with object_unref().
* Added patch converting initfn to realizefn.

Cc: Anthony Liguori anth...@codemonkey.ws
Cc: Paolo Bonzini pbonz...@redhat.com
Cc: Markus Armbruster arm...@redhat.com
Cc: Alexander Graf ag...@suse.de
Cc: Hervé Poussineau hpous...@reactos.org

Andreas Färber (2):
  prep_pci: Create PCIBus and PCIDevice in-place
  prep_pci: Convert to QOM realizefn

 hw/prep_pci.c |   56 
 1 Datei geändert, 40 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)

-- 
1.7.10.4




Re: [Qemu-devel] memcpy speed (Re: [PATCH v2] netmap backend (revised))

2013-01-24 Thread Stefan Hajnoczi
On Wed, Jan 23, 2013 at 06:55:59PM -0800, Luigi Rizzo wrote:
 On Wed, Jan 23, 2013 at 8:03 AM, Luigi Rizzo ri...@iet.unipi.it wrote:
 
   I'm even doubtful that it's always a win on FreeBSD.  You have a
   threshold to fall back to bcopy() and who knows what the best value
   for various CPUs is.
 
  indeed.
  With the attached program (which however might be affected by the
  fact that data is not used after copying) it seems that on a recent
  linux (using gcc 4.6.2) the fastest is __builtin_memcpy()
 
  ./testlock -m __builtin_memcpy -l 64
 
  (by a factor of 2 or more) whereas all the other methods have
  approximately the same speed.
 
 
 never mind, pilot error. in my test program i had swapped the
 arguments to __builtin_memcpy(). With the correct ones,
 __builtin_memcpy()  == bcopy == memcpy on both machines,
 and never faster than the pkt_copy().

Are the bcopy()/memcpy() calls given a length that is a multiple of 64 bytes?

IIUC pkt_copy() assumes 64-byte multiple lengths and that optimization
can matches with memcpy(dst, src, (len + 63)  ~63).  Maybe it helps and
at least ensures they are doing equal amounts of byte copying.

Stefan



[Qemu-devel] [PATCH for-1.4 v4 10/12] adb: QOM'ify Apple Desktop Bus

2013-01-24 Thread Andreas Färber
It was not a qbus before, turn it into a first-class bus and initialize
it properly from CUDA. Leave it a global variable as long as devices are
not QOM'ified yet.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/adb.c  |   14 ++
 hw/adb.h  |   16 +---
 hw/cuda.c |3 +++
 3 Dateien geändert, 30 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

diff --git a/hw/adb.c b/hw/adb.c
index cc8ad8e..5d46f59 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -126,6 +126,12 @@ static ADBDevice *adb_register_device(ADBBusState *s, int 
devaddr,
 return d;
 }
 
+static const TypeInfo adb_bus_type_info = {
+.name = TYPE_ADB_BUS,
+.parent = TYPE_BUS,
+.instance_size = sizeof(ADBBusState),
+};
+
 /***/
 /* Keyboard ADB device */
 
@@ -453,3 +459,11 @@ void adb_mouse_init(ADBBusState *bus)
 qemu_add_mouse_event_handler(adb_mouse_event, d, 0, QEMU ADB Mouse);
 vmstate_register(NULL, -1, vmstate_adb_mouse, s);
 }
+
+
+static void adb_register_types(void)
+{
+type_register_static(adb_bus_type_info);
+}
+
+type_init(adb_register_types)
diff --git a/hw/adb.h b/hw/adb.h
index 5b27da2..c23f804 100644
--- a/hw/adb.h
+++ b/hw/adb.h
@@ -26,10 +26,13 @@
 #if !defined(__ADB_H__)
 #define __ADB_H__
 
+#include qdev.h
+
 #define MAX_ADB_DEVICES 16
 
 #define ADB_MAX_OUT_LEN 16
 
+typedef struct ADBBusState ADBBusState;
 typedef struct ADBDevice ADBDevice;
 
 /* buf = NULL means polling */
@@ -38,7 +41,7 @@ typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
 typedef int ADBDeviceReset(ADBDevice *d);
 
 struct ADBDevice {
-struct ADBBusState *bus;
+ADBBusState *bus;
 int devaddr;
 int handler;
 ADBDeviceRequest *devreq;
@@ -46,11 +49,18 @@ struct ADBDevice {
 void *opaque;
 };
 
-typedef struct ADBBusState {
+#define TYPE_ADB_BUS apple-desktop-bus
+#define ADB_BUS(obj) OBJECT_CHECK(ADBBusState, (obj), TYPE_ADB_BUS)
+
+struct ADBBusState {
+/* private */
+BusState parent_obj;
+/* public */
+
 ADBDevice devices[MAX_ADB_DEVICES];
 int nb_devices;
 int poll_index;
-} ADBBusState;
+};
 
 int adb_request(ADBBusState *s, uint8_t *buf_out,
 const uint8_t *buf, int len);
diff --git a/hw/cuda.c b/hw/cuda.c
index f863c38..b3a875c 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -712,6 +712,9 @@ static void cuda_initfn(Object *obj)
 for (i = 0; i  ARRAY_SIZE(s-timers); i++) {
 s-timers[i].index = i;
 }
+
+qbus_create_inplace((BusState *)adb_bus, TYPE_ADB_BUS, DEVICE(obj),
+adb.0);
 }
 
 static void cuda_class_init(ObjectClass *oc, void *data)
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4 v4 02/12] macio: QOM'ify some more

2013-01-24 Thread Andreas Färber
Move bar MemoryRegion initialization to an instance_init.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c |   25 +++--
 1 Datei geändert, 19 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index f01fc57..770e3bd 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -27,9 +27,15 @@
 #include pci/pci.h
 #include escc.h
 
+#define TYPE_MACIO macio
+#define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
+
 typedef struct MacIOState
 {
+/* private */
 PCIDevice parent;
+/* public */
+
 int is_oldworld;
 MemoryRegion bar;
 MemoryRegion *pic_mem;
@@ -46,7 +52,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 int i;
 MemoryRegion *bar = macio_state-bar;
 
-memory_region_init(bar, macio, 0x8);
 if (macio_state-pic_mem) {
 if (macio_state-is_oldworld) {
 /* Heathrow PIC */
@@ -81,6 +86,13 @@ static int macio_initfn(PCIDevice *d)
 return 0;
 }
 
+static void macio_instance_init(Object *obj)
+{
+MacIOState *s = MACIO(obj);
+
+memory_region_init(s-bar, macio, 0x8);
+}
+
 static void macio_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -90,16 +102,17 @@ static void macio_class_init(ObjectClass *klass, void 
*data)
 k-class_id = PCI_CLASS_OTHERS  8;
 }
 
-static const TypeInfo macio_info = {
-.name  = macio,
+static const TypeInfo macio_type_info = {
+.name  = TYPE_MACIO,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(MacIOState),
+.instance_init = macio_instance_init,
 .class_init= macio_class_init,
 };
 
 static void macio_register_types(void)
 {
-type_register_static(macio_info);
+type_register_static(macio_type_info);
 }
 
 type_init(macio_register_types)
@@ -114,9 +127,9 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 MacIOState *macio_state;
 int i;
 
-d = pci_create_simple(bus, -1, macio);
+d = pci_create_simple(bus, -1, TYPE_MACIO);
 
-macio_state = DO_UPCAST(MacIOState, parent, d);
+macio_state = MACIO(d);
 macio_state-is_oldworld = is_oldworld;
 macio_state-pic_mem = pic_mem;
 macio_state-dbdma_mem = dbdma_mem;
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4 v4 07/12] mac_nvram: QOM'ify MacIO NVRAM

2013-01-24 Thread Andreas Färber
It was not qdev'ified before. Turn it into a SysBusDevice and
initialize it via static properties.

Prepare Old World specific MacIO state and embed the NVRAM state there.

Drop macio_nvram_setup_bar() in favor of sysbus_mmio_map() or
direct use of Memory API.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c|   63 -
 hw/macio.c|   41 
 hw/ppc/mac.h  |   23 +-
 hw/ppc/mac_newworld.c |   10 +---
 hw/ppc/mac_oldworld.c |6 +
 5 Dateien geändert, 102 Zeilen hinzugefügt(+), 41 Zeilen entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 0a22e66..25121fa 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -37,13 +37,6 @@
 #define NVR_DPRINTF(fmt, ...)
 #endif
 
-struct MacIONVRAMState {
-uint32_t size;
-MemoryRegion mem;
-unsigned int it_shift;
-uint8_t *data;
-};
-
 #define DEF_SYSTEM_SIZE 0xc10
 
 /* Direct access to NVRAM */
@@ -111,32 +104,56 @@ static const VMStateDescription vmstate_macio_nvram = {
 };
 
 
-static void macio_nvram_reset(void *opaque)
+static void macio_nvram_reset(DeviceState *dev)
 {
 }
 
-MacIONVRAMState *macio_nvram_init (hwaddr size,
-   unsigned int it_shift)
+static void macio_nvram_realizefn(DeviceState *dev, Error **errp)
 {
-MacIONVRAMState *s;
+SysBusDevice *d = SYS_BUS_DEVICE(dev);
+MacIONVRAMState *s = MACIO_NVRAM(dev);
 
-s = g_malloc0(sizeof(MacIONVRAMState));
-s-data = g_malloc0(size);
-s-size = size;
-s-it_shift = it_shift;
+s-data = g_malloc0(s-size);
 
 memory_region_init_io(s-mem, macio_nvram_ops, s, macio-nvram,
-  size  it_shift);
-vmstate_register(NULL, -1, vmstate_macio_nvram, s);
-qemu_register_reset(macio_nvram_reset, s);
+  s-size  s-it_shift);
+sysbus_init_mmio(d, s-mem);
+}
+
+static void macio_nvram_unrealizefn(DeviceState *dev, Error **errp)
+{
+MacIONVRAMState *s = MACIO_NVRAM(dev);
+
+g_free(s-data);
+}
 
-return s;
+static Property macio_nvram_properties[] = {
+DEFINE_PROP_UINT32(size, MacIONVRAMState, size, 0),
+DEFINE_PROP_UINT32(it_shift, MacIONVRAMState, it_shift, 0),
+DEFINE_PROP_END_OF_LIST()
+};
+
+static void macio_nvram_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
+
+dc-realize = macio_nvram_realizefn;
+dc-unrealize = macio_nvram_unrealizefn;
+dc-reset = macio_nvram_reset;
+dc-vmsd = vmstate_macio_nvram;
+dc-props = macio_nvram_properties;
 }
 
-void macio_nvram_setup_bar(MacIONVRAMState *s, MemoryRegion *bar,
-   hwaddr mem_base)
+static const TypeInfo macio_nvram_type_info = {
+.name = TYPE_MACIO_NVRAM,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(MacIONVRAMState),
+.class_init = macio_nvram_class_init,
+};
+
+static void macio_nvram_register_types(void)
 {
-memory_region_add_subregion(bar, mem_base, s-mem);
+type_register_static(macio_nvram_type_info);
 }
 
 /* Set up a system OpenBIOS NVRAM partition */
@@ -175,3 +192,5 @@ void pmac_format_nvram_partition (MacIONVRAMState *nvr, int 
len)
 end = len;
 OpenBIOS_finish_partition(part_header, end - start);
 }
+
+type_init(macio_nvram_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 0e6fc8d..32f359c 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -41,11 +41,21 @@ typedef struct MacIOState
 MemoryRegion *dbdma_mem;
 MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
-void *nvram;
 int nb_ide;
 MemoryRegion *ide_mem[4];
 } MacIOState;
 
+#define OLDWORLD_MACIO(obj) \
+OBJECT_CHECK(OldWorldMacIOState, (obj), TYPE_OLDWORLD_MACIO)
+
+typedef struct OldWorldMacIOState {
+/* private */
+MacIOState parent_obj;
+/* public */
+
+MacIONVRAMState nvram;
+} OldWorldMacIOState;
+
 static void macio_bar_setup(MacIOState *macio_state)
 {
 int i;
@@ -66,8 +76,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 macio_state-ide_mem[i]);
 }
 }
-if (macio_state-nvram != NULL)
-macio_nvram_setup_bar(macio_state-nvram, bar, 0x6);
 }
 
 static int macio_common_initfn(PCIDevice *d)
@@ -85,11 +93,22 @@ static int macio_common_initfn(PCIDevice *d)
 static int macio_oldworld_initfn(PCIDevice *d)
 {
 MacIOState *s = MACIO(d);
+OldWorldMacIOState *os = OLDWORLD_MACIO(d);
+SysBusDevice *sysbus_dev;
 int ret = macio_common_initfn(d);
 if (ret  0) {
 return ret;
 }
 
+ret = qdev_init(DEVICE(os-nvram));
+if (ret  0) {
+return ret;
+}
+sysbus_dev = SYS_BUS_DEVICE(os-nvram);
+memory_region_add_subregion(s-bar, 0x6,
+sysbus_mmio_get_region(sysbus_dev, 0));
+pmac_format_nvram_partition(os-nvram, os-nvram.size);
+
 if (s-pic_mem) {
 /* Heathrow PIC */
 

[Qemu-devel] [PATCH for-1.4 v4 11/12] adb: QOM'ify ADB devices

2013-01-24 Thread Andreas Färber
They were not qdev'ified before. Derive ADBDevice from DeviceState and
convert reset callbacks to DeviceClass::reset, ADBDevice::opaque pointer
to ADBDevice subtypes for mouse and keyboard and adb_{kbd,mouse}_init()
to regular qdev functions.

Fixing Coding Style issues and splitting keyboard and mouse off into
their own files is left for a later point in time.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/adb.c  |  244 -
 hw/adb.h  |   31 +--
 hw/ppc/mac_newworld.c |6 +-
 hw/ppc/mac_oldworld.c |6 +-
 4 Dateien geändert, 209 Zeilen hinzugefügt(+), 78 Zeilen entfernt(-)

diff --git a/hw/adb.c b/hw/adb.c
index 5d46f59..6cf5465 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -48,16 +48,21 @@ do { printf(ADB:  fmt , ## __VA_ARGS__); } while (0)
 #define ADB_CMD_CHANGE_ID_AND_ENABLE   0x00
 
 /* ADB default device IDs (upper 4 bits of ADB command byte) */
-#define ADB_DONGLE 1
-#define ADB_KEYBOARD   2
-#define ADB_MOUSE  3
-#define ADB_TABLET 4
-#define ADB_MODEM  5
-#define ADB_MISC   7
+#define ADB_DEVID_DONGLE   1
+#define ADB_DEVID_KEYBOARD 2
+#define ADB_DEVID_MOUSE3
+#define ADB_DEVID_TABLET   4
+#define ADB_DEVID_MODEM5
+#define ADB_DEVID_MISC 7
 
 /* error codes */
 #define ADB_RET_NOTPRESENT (-2)
 
+static void adb_device_reset(ADBDevice *d)
+{
+qdev_reset_all(DEVICE(d));
+}
+
 int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len)
 {
 ADBDevice *d;
@@ -66,18 +71,17 @@ int adb_request(ADBBusState *s, uint8_t *obuf, const 
uint8_t *buf, int len)
 cmd = buf[0]  0xf;
 if (cmd == ADB_BUSRESET) {
 for(i = 0; i  s-nb_devices; i++) {
-d = s-devices[i];
-if (d-devreset) {
-d-devreset(d);
-}
+d = s-devices[i];
+adb_device_reset(d);
 }
 return 0;
 }
 devaddr = buf[0]  4;
 for(i = 0; i  s-nb_devices; i++) {
-d = s-devices[i];
+d = s-devices[i];
 if (d-devaddr == devaddr) {
-return d-devreq(d, obuf, buf, len);
+ADBDeviceClass *adc = ADB_DEVICE_GET_CLASS(d);
+return adc-devreq(d, obuf, buf, len);
 }
 }
 return ADB_RET_NOTPRESENT;
@@ -94,7 +98,7 @@ int adb_poll(ADBBusState *s, uint8_t *obuf)
 for(i = 0; i  s-nb_devices; i++) {
 if (s-poll_index = s-nb_devices)
 s-poll_index = 0;
-d = s-devices[s-poll_index];
+d = s-devices[s-poll_index];
 buf[0] = ADB_READREG | (d-devaddr  4);
 olen = adb_request(s, obuf + 1, buf, 1);
 /* if there is data, we poll again the same device */
@@ -108,38 +112,67 @@ int adb_poll(ADBBusState *s, uint8_t *obuf)
 return olen;
 }
 
-static ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
-  ADBDeviceRequest *devreq,
-  ADBDeviceReset *devreset,
-  void *opaque)
-{
-ADBDevice *d;
-if (s-nb_devices = MAX_ADB_DEVICES)
-return NULL;
-d = s-devices[s-nb_devices++];
-d-bus = s;
-d-devaddr = devaddr;
-d-devreq = devreq;
-d-devreset = devreset;
-d-opaque = opaque;
-qemu_register_reset((QEMUResetHandler *)devreset, d);
-return d;
-}
-
 static const TypeInfo adb_bus_type_info = {
 .name = TYPE_ADB_BUS,
 .parent = TYPE_BUS,
 .instance_size = sizeof(ADBBusState),
 };
 
+static void adb_device_realizefn(DeviceState *dev, Error **errp)
+{
+ADBDevice *d = ADB_DEVICE(dev);
+ADBBusState *bus = ADB_BUS(qdev_get_parent_bus(dev));
+
+if (bus-nb_devices = MAX_ADB_DEVICES) {
+return;
+}
+
+bus-devices[bus-nb_devices++] = d;
+}
+
+static void adb_device_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
+
+dc-realize = adb_device_realizefn;
+dc-bus_type = TYPE_ADB_BUS;
+}
+
+static const TypeInfo adb_device_type_info = {
+.name = TYPE_ADB_DEVICE,
+.parent = TYPE_DEVICE,
+.instance_size = sizeof(ADBDevice),
+.abstract = true,
+.class_init = adb_device_class_init,
+};
+
 /***/
 /* Keyboard ADB device */
 
+#define ADB_KEYBOARD(obj) OBJECT_CHECK(KBDState, (obj), TYPE_ADB_KEYBOARD)
+
 typedef struct KBDState {
+/* private */
+ADBDevice parent_obj;
+/* public */
+
 uint8_t data[128];
 int rptr, wptr, count;
 } KBDState;
 
+#define ADB_KEYBOARD_CLASS(class) \
+OBJECT_CLASS_CHECK(ADBKeyboardClass, (class), TYPE_ADB_KEYBOARD)
+#define ADB_KEYBOARD_GET_CLASS(obj) \
+OBJECT_GET_CLASS(ADBKeyboardClass, (obj), TYPE_ADB_KEYBOARD)
+
+typedef struct ADBKeyboardClass {
+/* private */
+ADBDeviceClass parent_class;
+/* public */
+
+DeviceRealize parent_realize;
+} ADBKeyboardClass;
+
 static const uint8_t pc_to_adb_keycode[256] = {
   0, 53, 18, 19, 20, 21, 23, 

Re: [Qemu-devel] Apparent udev hang during reboot of guest which has been up for some time.

2013-01-24 Thread Stefan Hajnoczi
On Wed, Jan 23, 2013 at 11:08:59AM -0500, Oisin Feeley wrote:
 We have experienced symptoms very similar to those described[1] by
 Kenton Cabiness in 2011:  guests which have been up for some time
 (we're working on trying to find out exactly how long, but anecdotally
 it's about a week or more) will take up to several hours in the udev
 phase when rebooting.  However, freshly created instances of the exact
 same image on the exact same hardware will not display this hang.
[...]
 Guest:
 Speculatively: CentOS-5.8-x86_64
 Definitely based on some version of RHEL

Sounds like udev is the best starting point.  Here is a link on
increasing the udev log verbosity level:

http://www.novell.com/support/kb/doc.php?id=7000506

 Does anyone have suggestions about how we should go about bisecting
 this problem?

Bisecting is useful if the bug is a regression (it used to work but now
fails in a new version).  Do you have a known-good configuration where
this problem doesn't happen?

 dependent on how long the guest has been running and then stracing kvm
 for another instance which crashes.

Stracing kvm is unlikely to show anything useful since the problem is
inside the guest.  The strace output will probably be too low-level to
figure out what is happening inside the guest.

Stracing udev inside the guest might be interesting.  Not sure how easy
it is to do that in the CentOS 5.8 boot process.

Good luck,
Stefan



[Qemu-devel] Display Resolution in Windows Server 2012

2013-01-24 Thread Peter Lieven

Hi,

does anyone know why its only possible to select 1024x768 as resolution in 
Windows Server 2012 (not tested Windows 8)
with -vga std? In older windows releases it was possible to select up to 
2560x1920 with that setting.
-vga cirrus works, but does only allow up to 1280x1024 due to VGA RAM size 
limits.

Thanks,
Peter



Re: [Qemu-devel] [PATCH V2 1/6] trivial: etraxfs_eth: Eliminate checkpatch errors

2013-01-24 Thread Andreas Färber
Am 23.01.2013 17:15, schrieb Grant Likely:
 This is a trivial patch to harmonize the coding style on
 hw/etraxfs_eth.c. This is in preparation to split off the bitbang mdio
 code into a separate file.
 
 Cc: Peter Maydell peter.mayd...@linaro.org
 Cc: Paul Brook p...@codesourcery.com
 Cc: Edgar E. Iglesias edgar.igles...@gmail.com
 Cc: Anthony Liguori aligu...@us.ibm.com
 Cc: Andreas Färber afaer...@suse.de
 Signed-off-by: Grant Likely grant.lik...@secretlab.ca

In the future please don't prefix patches with trivial:  - if they're
truely trivial and the code is unmaintained (i.e., not in this case) you
should cc qemu-triv...@nongnu.org instead. extraxfs_eth: ... as
subject would've been sufficient.

Cheers,
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] Where can I start?

2013-01-24 Thread Stefan Hajnoczi
On Thu, Jan 24, 2013 at 05:27:00PM +0900, 한상훈 wrote:
 I want to analyze, Qemu Source Code, but It's too big and complex to start by 
 myself.
 Now, i'm trying to understand Make process and analyze 'Makefile'.
  
 So, I'm writing this mail to get some advice as a new guy in Qemu-devel. 
 I'm looking for the information about Whole QEMU architecture or process 
 logic or build tree, kind of something. 
  
 Please, help and let me get some useful information about Qemu source code. 
 I want to understand the whole qemu logic.

There is no up-to-date official documentation that will teach you the
QEMU source code.

Start in vl.c:main() and read the code.  See how vcpus are set up and
follow the main loop.

Focus on the aspects that interest you, for example TCG ARM emulation or
kvm on x86_64.  Don't try to follow all code paths at once, just focus
on one configuration.

If you want to understand the Makefile, build with the verbose option so
you can see each command-line:
$ make V=1

Here is a high-level overview of QEMU's architecture:
http://blog.vmsplice.net/2011/03/qemu-internals-big-picture-overview.html
http://blog.vmsplice.net/2011/03/qemu-internals-overall-architecture-and.html

Jan's KVM architecture talk is excellent:
http://www.linux-kongress.org/2010/slides/KVM-Architecture-LK2010.pdf

The best way to get started is by fixing a bug or adding a new feature.
It will give you a real problem to work on and you can learn the
codebase gradually.  The catch is that you need to decide what to work
on yourself, maybe start with the QEMU bug tracker:
https://bugs.launchpad.net/qemu.

Stefan



Re: [Qemu-devel] [RFC] Virtio-desktop: Virtio-based virtual desktop

2013-01-24 Thread Stefan Hajnoczi
On Thu, Jan 24, 2013 at 11:40:24AM +0530, Anup Patel wrote:
 IMHO, If we have something like Virtio-desktop specification then all
 possible guest OSes can have support for it and different hypervisor can
 emulate it without worrying about guest support.

At this point x86 virtualization is mature and working with a mix of
emulated x86 architecture pieces and virtio devices for
performance-critical or open-ended functionality that we want to be able
to extend.

ARM is getting KVM and virtio-mmio support.  It will be in a similar
position soon.

Virtio guest drivers have not been implemented widely.  The Linux and
Windows efforts are driven by the folks who were behind virtio from the
start, but Solaris, FreeBSD, and others didn't really jump on the virtio
bandwagon.

Given this landscape, what is the advantage of doing a virtio-desktop?
It will still need to fall back on ARM or x86 which is already being
virtualized and emulated.

Depending on how you see it we either have virtio-desktop already or,
if not, I think the experience with virtio adoption suggests other
hypervisors and guest OSes will not trip over themselves to implement
virtio-desktop.

What's the advantage over virtualizating an existing ARM or x86 platform
and using virtio devices where appropriate?

Stefan



[Qemu-devel] [PATCH v3] PIIX3: reset the VM when the Reset Control Register's RCPU bit gets set

2013-01-24 Thread Laszlo Ersek
From http://mjg59.dreamwidth.org/3561.html:

  Traditional PCI config space access is achieved by writing a 32 bit
  value to io port 0xcf8 to identify the bus, device, function and config
  register. Port 0xcfc then contains the register in question. But if you
  write the appropriate pair of magic values to 0xcf9, the machine will
  reboot. Spectacular! And not standardised in any way (certainly not part
  of the PCI spec), so different chipsets may have different requirements.
  Booo.

In the PIIX3 spec, IO port 0xcf9 is specified as the Reset Control
Register. Bit 1 (System Reset, SRST) would normally differentiate between
soft reset and hard reset, but we ignore the difference beyond allowing
the guest to read it back.

RHBZ reference: 890459

This patch introduces the following overlap between the preexistent
pci-conf-idx region and the piix3-reset-control region just being
added. Partial output from info mtree:

  I/O
  - (prio 0, RW): io
0cf8-0cfb (prio 0, RW): pci-conf-idx
0cf9-0cf9 (prio 1, RW): piix3-reset-control

I sanity-checked the patch by booting a RHEL-6.3 guest and found no
problems. I summoned gdb and set a breakpoint on rcr_write() in order to
gather a bit more confidence. Relevant frames of the stack:

  kvm_handle_io (port=3321, data=0x7f3f5f3de000, direction=1, size=1,
 count=1) [kvm-all.c:1422]
cpu_outb (addr=3321, val=6 '\006')  [ioport.c:289]
  ioport_write (index=0, address=3321, data=6)   [ioport.c:83]
ioport_writeb_thunk (opaque=0x7f3f622c4680, addr=3321, data=6)
[ioport.c:212]
  memory_region_iorange_write (iorange=0x7f3f622c4680, offset=0,
   width=1, data=6) [memory.c:439]
access_with_adjusted_size (addr=0, value=0x7f3f531fbac0,
   size=1, access_size_min=1,
   access_size_max=4,
   access=0x7f3f5f6e0f90
   memory_region_write_accessor,
   opaque=0x7f3f6227b668)
[memory.c:364]
  memory_region_write_accessor (opaque=0x7f3f6227b668, addr=0,
value=0x7f3f531fbac0, size=1,
shift=0, mask=255)
[memory.c:334]
rcr_write (opaque=0x7f3f6227afb0, addr=0, val=6, len=1)
   [hw/piix_pci.c:498]

The dispatch happens in ioport_write(); index=0 means byte-wide access:

static void ioport_write(int index, uint32_t address, uint32_t data)
{
static IOPortWriteFunc * const default_func[3] = {
default_ioport_writeb,
default_ioport_writew,
default_ioport_writel
};
IOPortWriteFunc *func = ioport_write_table[index][address];
if (!func)
func = default_func[index];
func(ioport_opaque[address], address, data);
}

The ioport_write_table and ioport_opaque arrays describe the flattened
IO port space. The first array is less interesting (it selects a thunk
function). The ioport_opaque array is interesting because it decides how
writing to the port is implemented ultimately.

4-byte wide access to 0xcf8 (pci-conf-idx):

  (gdb) print ioport_write_table[2][0xcf8]
  $1 = (IOPortWriteFunc *) 0x7f3f5f6d99ba ioport_writel_thunk

  (gdb) print \
((struct MemoryRegionIORange*)ioport_opaque[0xcf8])-mr-ops.write
  $2 = (void (*)(void *, hwaddr, uint64_t, unsigned int))
   0x7f3f5f5575cb pci_host_config_write

1-byte wide access to 0xcf9 (piix3-reset-control):

  (gdb) print ioport_write_table[0][0xcf9]
  $3 = (IOPortWriteFunc *) 0x7f3f5f6d98d0 ioport_writeb_thunk

  (gdb) print \
((struct MemoryRegionIORange*)ioport_opaque[0xcf9])-mr-ops.write
  $4 = (void (*)(void *, hwaddr, uint64_t, unsigned int))
   0x7f3f5f6b42f1 rcr_write

The higher priority of piix3-reset-control ensures that the 0xcf9
entries in ioport_write_table / ioport_opaque will always belong to it,
independently of its relative registration order versus pci-conf-idx.

Signed-off-by: Laszlo Ersek ler...@redhat.com
---
v2-v3:
- don't touch piix3_post_load(); take the RCR as it comes (Stefan).
  Diff against v2:

  diff --git a/hw/piix_pci.c b/hw/piix_pci.c
  index 38a1027..4c97a84 100644
  --- a/hw/piix_pci.c
  +++ b/hw/piix_pci.c
  @@ -462,7 +462,6 @@ static int piix3_post_load(void *opaque, int version_id)
   {
   PIIX3State *piix3 = opaque;
   piix3_update_irq_levels(piix3);
  -piix3-rcr = 2; /* keep System Reset type only */
   return 0;
   }

v1-v2:
- 

Re: [Qemu-devel] [PATCH v9 3/7] trace: Provide a detailed event control interface

2013-01-24 Thread Stefan Hajnoczi
On Wed, Jan 23, 2013 at 06:11:19PM +0100, Lluís Vilanova wrote:
 Stefan Hajnoczi writes:
 
  On Thu, Jan 10, 2013 at 08:23:13PM +0100, Lluís Vilanova wrote:
  diff --git a/trace/control-internal.h b/trace/control-internal.h
  new file mode 100644
  index 000..188253a
  --- /dev/null
  +++ b/trace/control-internal.h
  @@ -0,0 +1,67 @@
  +/*
  + * Interface for configuring and controlling the state of tracing events.
  + *
  + * Copyright (C) 2011-2012 Lluís Vilanova vilan...@ac.upc.edu
  + *
  + * This work is licensed under the terms of the GNU GPL, version 2 or 
  later.
  + * See the COPYING file in the top-level directory.
  + */
 
  Please add an include guard.
 
 It is only meant to be included from trace/control.h, and only for the sake 
 of
 maintaining declarations separated from inlined definitions.

For sanity I'd still add an include guard.

  +/**
  + * trace_print_events:
  + *
  + * Print the state of all events.
  + *
  + * Warning: This function must be implemented by each tracing backend.
  + *
  + * TODO: Should this be moved to generic code?
 
  This is generic code so the TODO can be removed?
 
 No, I meant the opposite. That maybe this should *not* be in the generic 
 control
 interface, but I don't know where it should be moved to then, as it's used in
 the simple, default and stderr backends, as well as in the monitor.

I see.  For now I think this is okay and the comment can be dropped.

Stefan



Re: [Qemu-devel] [PATCH 00/57] target-i386 eflags cleanup and bmi/adx extensions

2013-01-24 Thread Andreas Färber
Am 24.01.2013 05:02, schrieb Richard Henderson:
  target-i386/cpu.c   |   18 +-
  target-i386/cpu.h   |   24 +-

You forgot to CC me: Please point me to where in those 57 patches you
are touching the core CPU code.

Given the size of the series I assume this is 1.5 material?

Thanks,
Andreas

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



[Qemu-devel] [PATCH for-1.4 v4 01/12] ppc: Move Mac machines to hw/ppc/

2013-01-24 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/cuda.c |2 +-
 hw/grackle_pci.c  |2 +-
 hw/heathrow_pic.c |2 +-
 hw/ide/macio.c|6 +++---
 hw/mac_nvram.c|2 +-
 hw/macio.c|2 +-
 hw/openpic.c  |2 +-
 hw/ppc/Makefile.objs  |9 +
 hw/{ppc_mac.h = ppc/mac.h}   |0
 hw/{ppc_newworld.c = ppc/mac_newworld.c} |   28 ++--
 hw/{ppc_oldworld.c = ppc/mac_oldworld.c} |   26 +-
 hw/unin_pci.c |2 +-
 12 Dateien geändert, 42 Zeilen hinzugefügt(+), 41 Zeilen entfernt(-)
 rename hw/{ppc_mac.h = ppc/mac.h} (100%)
 rename hw/{ppc_newworld.c = ppc/mac_newworld.c} (98%)
 rename hw/{ppc_oldworld.c = ppc/mac_oldworld.c} (97%)

diff --git a/hw/cuda.c b/hw/cuda.c
index d59e0ae..bbd1fda 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include adb.h
 #include qemu/timer.h
 #include sysemu/sysemu.h
diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 9484166..95639d5 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -24,7 +24,7 @@
  */
 
 #include pci/pci_host.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 
 /* debug Grackle */
diff --git a/hw/heathrow_pic.c b/hw/heathrow_pic.c
index b9ec8e7..c0a71c3 100644
--- a/hw/heathrow_pic.c
+++ b/hw/heathrow_pic.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 
 /* debug PIC */
 //#define DEBUG_PIC
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index d8f9b4b..e0f04dc 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -22,9 +22,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include hw/hw.h
-#include hw/ppc_mac.h
-#include hw/mac_dbdma.h
+#include hw/hw.h
+#include hw/ppc/mac.h
+#include hw/mac_dbdma.h
 #include block/block.h
 #include sysemu/dma.h
 
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 71093c2..eec7ca4 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -25,7 +25,7 @@
 #include hw.h
 #include firmware_abi.h
 #include sysemu/sysemu.h
-#include ppc_mac.h
+#include ppc/mac.h
 
 /* debug NVR */
 //#define DEBUG_NVR
diff --git a/hw/macio.c b/hw/macio.c
index 675a71c..f01fc57 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 #include escc.h
 
diff --git a/hw/openpic.c b/hw/openpic.c
index d414f47..25aa9bf 100644
--- a/hw/openpic.c
+++ b/hw/openpic.c
@@ -34,7 +34,7 @@
  *
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 #include openpic.h
 #include sysbus.h
diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index afdcc0e..462146b 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -3,10 +3,6 @@ obj-y = ppc.o ppc_booke.o
 # PREP target
 obj-y += mc146818rtc.o
 obj-y += ppc_prep.o
-# OldWorld PowerMac
-obj-y += ppc_oldworld.o
-# NewWorld PowerMac
-obj-y += ppc_newworld.o
 # IBM pSeries (sPAPR)
 obj-$(CONFIG_PSERIES) += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o
 obj-$(CONFIG_PSERIES) += xics.o spapr_vty.o spapr_llan.o spapr_vscsi.o
@@ -28,4 +24,9 @@ obj-y += xilinx_ethlite.o
 
 obj-y := $(addprefix ../,$(obj-y))
 
+# OldWorld PowerMac
+obj-y += mac_oldworld.o
+# NewWorld PowerMac
+obj-y += mac_newworld.o
+# e500
 obj-$(CONFIG_FDT) += e500.o mpc8544ds.o e500plat.o
diff --git a/hw/ppc_mac.h b/hw/ppc/mac.h
similarity index 100%
rename from hw/ppc_mac.h
rename to hw/ppc/mac.h
diff --git a/hw/ppc_newworld.c b/hw/ppc/mac_newworld.c
similarity index 98%
rename from hw/ppc_newworld.c
rename to hw/ppc/mac_newworld.c
index b1973f1..f3c01bf 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -46,28 +46,28 @@
  * 0001:05:0c.0 IDE interface [0101]: Broadcom K2 SATA [1166:0240]
  *
  */
-#include hw.h
-#include ppc.h
-#include ppc_mac.h
-#include adb.h
-#include mac_dbdma.h
-#include nvram.h
-#include pci/pci.h
+#include hw/hw.h
+#include hw/ppc.h
+#include hw/ppc/mac.h
+#include hw/adb.h
+#include hw/mac_dbdma.h
+#include hw/nvram.h
+#include hw/pci/pci.h
 #include net/net.h
 #include sysemu/sysemu.h
-#include boards.h
-#include fw_cfg.h
-#include escc.h
-#include openpic.h
-#include ide.h
-#include loader.h
+#include hw/boards.h
+#include hw/fw_cfg.h
+#include hw/escc.h
+#include hw/openpic.h
+#include hw/ide.h
+#include hw/loader.h
 #include elf.h
 #include sysemu/kvm.h
 #include kvm_ppc.h
 #include hw/usb.h
 #include sysemu/blockdev.h
 #include exec/address-spaces.h
-#include sysbus.h
+#include hw/sysbus.h
 
 #define MAX_IDE_BUS 2
 #define CFG_ADDR 0xf510
diff --git a/hw/ppc_oldworld.c b/hw/ppc/mac_oldworld.c
similarity index 97%
rename from hw/ppc_oldworld.c

Re: [Qemu-devel] [PATCH v9 4/7] trace: [monitor] Use new event control interface

2013-01-24 Thread Stefan Hajnoczi
On Wed, Jan 23, 2013 at 06:01:29PM +0100, Lluís Vilanova wrote:
 Stefan Hajnoczi writes:
 
  On Thu, Jan 10, 2013 at 08:23:19PM +0100, Lluís Vilanova wrote:
  Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
  ---
  monitor.c |   20 +---
  1 file changed, 17 insertions(+), 3 deletions(-)
  
  diff --git a/monitor.c b/monitor.c
  index 9cf419b..4c40541 100644
  --- a/monitor.c
  +++ b/monitor.c
  @@ -735,10 +735,24 @@ static void do_trace_event_set_state(Monitor *mon, 
  const QDict *qdict)
  {
  const char *tp_name = qdict_get_str(qdict, name);
  bool new_state = qdict_get_bool(qdict, option);
  -int ret = trace_event_set_state(tp_name, new_state);
  
  -if (!ret) {
  -monitor_printf(mon, unknown event name \%s\\n, tp_name);
  +if (trace_event_is_pattern(tp_name)) {
  +TraceEvent *ev = NULL;
  +while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
  +if (!trace_event_get_state_static(ev)) {
  +monitor_printf(mon, event \%s\ is not traceable\n, 
  tp_name);
  +}
  +trace_event_set_state_dynamic(ev, new_state);
  +}
  +} else {
  +TraceEvent *ev = trace_event_name(tp_name);
  +if (ev == NULL) {
  +monitor_printf(mon, unknown event name \%s\\n, tp_name);
  +} else if (!trace_event_get_state_static(ev)) {
  +monitor_printf(mon, event \%s\ is not traceable\n, 
  tp_name);
  +} else {
  +trace_event_set_state_dynamic(ev, new_state);
  +}
 
  Do we need to duplicate the pattern vs not-a-pattern case?
 
  We can loop with trace_event_pattern() and print the unknown event
  name only if !trace_event_is_pattern().
 
 You mean something like this?
 
 
 #v+
 bool found = false;
 TraceEvent *ev = NULL;
 while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
 found = true;
 if (!trace_event_get_state_static(ev)) {
 monitor_printf(mon, event \%s\ is not traceable\n, tp_name);
 } else {
 trace_event_set_state_dynamic(ev, new_state);
 }
 }
 if (!trace_event_is_pattern(tp_name)  !found) {
 monitor_printf(mon, unknown event name \%s\\n, tp_name);
 }
 #v-

Yes, exactly.  It's nice to have a single code path.

Stefan



[Qemu-devel] [PATCH for-1.4 v4 12/12] cuda: Move ADB bus into CUDA state

2013-01-24 Thread Andreas Färber
Replace the global adb_bus with a CUDA-internal one, accessed using
regular qdev child bus accessor.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/adb.h  |1 -
 hw/cuda.c |8 +++-
 hw/ppc/mac.h  |2 ++
 hw/ppc/mac_newworld.c |7 +--
 hw/ppc/mac_oldworld.c |7 +--
 5 Dateien geändert, 15 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)

diff --git a/hw/adb.h b/hw/adb.h
index 2fe981f..721f1ac 100644
--- a/hw/adb.h
+++ b/hw/adb.h
@@ -84,5 +84,4 @@ int adb_poll(ADBBusState *s, uint8_t *buf_out);
 #define TYPE_ADB_KEYBOARD adb-keyboard
 #define TYPE_ADB_MOUSE adb-mouse
 
-extern ADBBusState adb_bus;
 #endif /* !defined(__ADB_H__) */
diff --git a/hw/cuda.c b/hw/cuda.c
index b3a875c..b36c535 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -108,8 +108,6 @@
 /* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
 #define RTC_OFFSET  2082844800
 
-ADBBusState adb_bus;
-
 static void cuda_update(CUDAState *s);
 static void cuda_receive_packet_from_host(CUDAState *s,
   const uint8_t *data, int len);
@@ -459,7 +457,7 @@ static void cuda_adb_poll(void *opaque)
 uint8_t obuf[ADB_MAX_OUT_LEN + 2];
 int olen;
 
-olen = adb_poll(adb_bus, obuf + 2);
+olen = adb_poll(s-adb_bus, obuf + 2);
 if (olen  0) {
 obuf[0] = ADB_PACKET;
 obuf[1] = 0x40; /* polled data */
@@ -555,7 +553,7 @@ static void cuda_receive_packet_from_host(CUDAState *s,
 {
 uint8_t obuf[ADB_MAX_OUT_LEN + 2];
 int olen;
-olen = adb_request(adb_bus, obuf + 2, data + 1, len - 1);
+olen = adb_request(s-adb_bus, obuf + 2, data + 1, len - 1);
 if (olen  0) {
 obuf[0] = ADB_PACKET;
 obuf[1] = 0x00;
@@ -713,7 +711,7 @@ static void cuda_initfn(Object *obj)
 s-timers[i].index = i;
 }
 
-qbus_create_inplace((BusState *)adb_bus, TYPE_ADB_BUS, DEVICE(obj),
+qbus_create_inplace((BusState *)s-adb_bus, TYPE_ADB_BUS, DEVICE(obj),
 adb.0);
 }
 
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 26cb497..b17107b 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -28,6 +28,7 @@
 #include exec/memory.h
 #include hw/sysbus.h
 #include hw/ide/internal.h
+#include hw/adb.h
 
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
@@ -93,6 +94,7 @@ typedef struct CUDAState {
 uint8_t ier;
 uint8_t anh;
 
+ADBBusState adb_bus;
 CUDATimer timers[2];
 
 uint32_t tick_offset;
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 2892b36..6de810b 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -149,6 +149,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)
 PCIBus *pci_bus;
 PCIDevice *macio;
 MACIOIDEState *macio_ide;
+BusState *adb_bus;
 MacIONVRAMState *nvr;
 int bios_size;
 MemoryRegion *pic_mem, *escc_mem;
@@ -381,9 +382,11 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)
 ide[1]));
 macio_ide_init_drives(macio_ide, hd[MAX_IDE_DEVS]);
 
-dev = qdev_create(BUS(adb_bus), TYPE_ADB_KEYBOARD);
+dev = DEVICE(object_resolve_path_component(OBJECT(macio), cuda));
+adb_bus = qdev_get_child_bus(dev, adb.0);
+dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD);
 qdev_init_nofail(dev);
-dev = qdev_create(BUS(adb_bus), TYPE_ADB_MOUSE);
+dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
 qdev_init_nofail(dev);
 
 if (usb_enabled(machine_arch == ARCH_MAC99_U3)) {
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 59b7199..9ed303a 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -92,6 +92,7 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)
 PCIDevice *macio;
 MACIOIDEState *macio_ide;
 DeviceState *dev;
+BusState *adb_bus;
 int bios_size;
 MemoryRegion *pic_mem;
 MemoryRegion *escc_mem, *escc_bar = g_new(MemoryRegion, 1);
@@ -281,9 +282,11 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)
 hd[3] = hd[2] = NULL;
 pci_cmd646_ide_init(pci_bus, hd, 0);
 
-dev = qdev_create(BUS(adb_bus), TYPE_ADB_KEYBOARD);
+dev = DEVICE(object_resolve_path_component(OBJECT(macio), cuda));
+adb_bus = qdev_get_child_bus(dev, adb.0);
+dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD);
 qdev_init_nofail(dev);
-dev = qdev_create(BUS(adb_bus), TYPE_ADB_MOUSE);
+dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
 qdev_init_nofail(dev);
 
 if (usb_enabled(false)) {
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4] target-cris: Fix typo in D_LOG() macro

2013-01-24 Thread Andreas Färber
It's __VAR_ARGS__. Fixes the build with CRIS_[OP_]HELPER_DEBUG defined.

Broken since r6338 / 93fcfe39a0383377e647b821c9f165fd927cd4e0 (Convert
references to logfile/loglevel to use qemu_log*() macros).

Cc: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-cris/helper.c|2 +-
 target-cris/op_helper.c |2 +-
 2 Dateien geändert, 2 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

diff --git a/target-cris/helper.c b/target-cris/helper.c
index 8407a6d..6e75e98 100644
--- a/target-cris/helper.c
+++ b/target-cris/helper.c
@@ -28,7 +28,7 @@
 
 #ifdef CRIS_HELPER_DEBUG
 #define D(x) x
-#define D_LOG(...) qemu_log(__VA__ARGS__)
+#define D_LOG(...) qemu_log(__VA_ARGS__)
 #else
 #define D(x)
 #define D_LOG(...) do { } while (0)
diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
index 79bff38..0f6a1ee 100644
--- a/target-cris/op_helper.c
+++ b/target-cris/op_helper.c
@@ -28,7 +28,7 @@
 
 #ifdef CRIS_OP_HELPER_DEBUG
 #define D(x) x
-#define D_LOG(...) qemu_log(__VA__ARGS__)
+#define D_LOG(...) qemu_log(__VA_ARGS__)
 #else
 #define D(x)
 #define D_LOG(...) do { } while (0)
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4 v4 00/12] target-ppc: MacIO QOM'ification

2013-01-24 Thread Andreas Färber
Hello,

Here's an updated MacIO conversion, now including Apple Desktop Bus (ADB).
MacIO IDE QOM'ification was requested by Markus as a prerequisite for some
to be performed change in the IDE code.

Alex, please apply through your ppc tree.

Regards,
Andreas

v3 - v4:
* object_resolve_path_component() prereq was applied through qemu-trivial.
* Updated SysBus devices to QOM realizefn.
* Not adding finalizers for unref'ing, as those would be obsoleted by Paolo's
  reference counting changes. (cf. prep_pci patches)
* Added patches QOM'ifying ADB bus, devices and CUDA's bus hosting.

v2 - v3:
* Redone using QOM, split up into three patches for better reviewability.
* Moved Mac machines to hw/ppc/.
* Added QOM'ification patches for NVRAM, IDE and CUDA.

v1 - v2:
 * qdev'ification patch was ignored for QOM 2nd series: Rebased onto Anthony's.

Cc: Alexander Graf ag...@suse.de
Cc: qemu-ppc qemu-...@nongnu.org

Cc: Markus Armbruster arm...@redhat.com
Cc: Kevin Wolf kw...@redhat.com
Cc: Hervé Poussineau hpous...@reactos.org
Cc: Paolo Bonzini pbonz...@redhat.com
Cc: Mark Cave-Ayland mark.cave-ayl...@ilande.co.uk (FYI: ADB conversion)

Andreas Färber (12):
  ppc: Move Mac machines to hw/ppc/
  macio: QOM'ify some more
  macio: Delay qdev init until all fields are initialized
  macio: Split MacIO in two
  mac_nvram: Clean up public API
  mac_nvram: Mark as Big Endian
  mac_nvram: QOM'ify MacIO NVRAM
  ide/macio: QOM'ify MacIO IDE
  cuda: QOM'ify CUDA
  adb: QOM'ify Apple Desktop Bus
  adb: QOM'ify ADB devices
  cuda: Move ADB bus into CUDA state

 hw/adb.c  |  252 ++---
 hw/adb.h  |   46 +++--
 hw/cuda.c |  106 +--
 hw/grackle_pci.c  |2 +-
 hw/heathrow_pic.c |2 +-
 hw/ide.h  |4 -
 hw/ide/macio.c|   84 ++---
 hw/mac_nvram.c|   88 +
 hw/macio.c|  289 ++---
 hw/openpic.c  |2 +-
 hw/ppc/Makefile.objs  |9 +-
 hw/ppc/mac.h  |  181 ++
 hw/{ppc_newworld.c = ppc/mac_newworld.c} |   74 +---
 hw/{ppc_oldworld.c = ppc/mac_oldworld.c} |   65 +++
 hw/ppc_mac.h  |   81 
 hw/unin_pci.c |2 +-
 16 Dateien geändert, 879 Zeilen hinzugefügt(+), 408 Zeilen entfernt(-)
 create mode 100644 hw/ppc/mac.h
 rename hw/{ppc_newworld.c = ppc/mac_newworld.c} (89%)
 rename hw/{ppc_oldworld.c = ppc/mac_oldworld.c} (90%)
 delete mode 100644 hw/ppc_mac.h

-- 
1.7.10.4




Re: [Qemu-devel] [RFC] qemu snapshot enchancement

2013-01-24 Thread Stefan Hajnoczi
On Thu, Jan 24, 2013 at 11:14:31AM +0800, Wenchao Xia wrote:
 
 I like the use cases section.  I think it would be best to start there
 and fill in the details all the way down to the QMP API calls that need
 to be made.
 
 At that point we can be sure the use cases are covered and the API
 proposal will be easy to put together from the wiki page.
 
 Comments about the use cases:
 
 Case 1:
 
   * Step 3: Copy out data may take some time.  It must be possible to
 resume the guest before Step 3 completes.  This can be supported
 easily since backing files are read-only (but care needs to be taken
 with the commit blockjob and anything else which might write to the
 backing file).
 
   My understanding is that it is ready in qemu now, only problems are
 vmstatesize, speed of merging on host server, and speed of block access
 on host(must keep an external chain with length of two always).

Yes, this use case is possible today with external snapshots and without
vmstate.

I think it's important the we do not wait for Step 3 to complete before
resuming the VM.  Copying data out of the snapshots could take a long
time, the guest must continue running as soon as possible.

 Case 3:
 
   * What does blank data mean?  Besides that the use case
 makes sense.
 
   Will remove the words.
 
   * When discussing this use case in the past it was suggested that the
 guest doesn't need to be paused during the LVM snapshot.  Instead the
 QEMU block layer might be able to queue I/O requests, allowing the
 guest to run.
 
   That is a good idea, but seems need more work(event, block layer...),
 hope it can be added as an enchancement of this case. Now let the
 dedicated storage software/hardware take the job by pausing for a while
 (200ms?)

Yes, allowing the guest to continue but queuing I/O will require extra
block layer work and maybe a QMP command.  There is a also a risk: if
the snapshot takes too long to complete, the guest may notice that its
I/O request are taking a long time.  It may decide that they have timed
out and report an error to the application or in the message logs.

In the beginning it's easier to pause the VM but let's keep queuing I/O
in mind so it can be added later, if necessary.

   * What is the async API for external data?
 
   API to start and query the progress, and related event should be
 provided, now qemu have migration to file API, it will be enchanced or
 most likely a new API dedicated for vmstate saving will be added.

Okay, I understand.

   * What is the size problem?
 
   Now qemu streaming vmstate to file, that means file size will continue
 growing before complete, and if the progress take too long there will
 be many duplicated data got written, and the size may be too large.

Ah, I remember.  Thanks for explaining.

Stefan



[Qemu-devel] [PATCH for-1.4 v4 08/12] ide/macio: QOM'ify MacIO IDE

2013-01-24 Thread Andreas Färber
It was not qdev'ified before. Turn it into a SysBusDevice.
Embed them into the MacIO devices.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Markus Armbruster arm...@redhat.com
---
 hw/ide.h  |4 --
 hw/ide/macio.c|   78 ++---
 hw/macio.c|  102 ++---
 hw/ppc/mac.h  |   25 +++-
 hw/ppc/mac_newworld.c |   28 --
 hw/ppc/mac_oldworld.c |   36 -
 6 Dateien geändert, 195 Zeilen hinzugefügt(+), 78 Zeilen entfernt(-)

diff --git a/hw/ide.h b/hw/ide.h
index 7e23cda..9b357c0 100644
--- a/hw/ide.h
+++ b/hw/ide.h
@@ -19,10 +19,6 @@ PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo 
**hd_table, int devfn);
 PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
 
-/* ide-macio.c */
-MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
-  void *dbdma, int channel, qemu_irq dma_irq);
-
 /* ide-mmio.c */
 void mmio_ide_init (hwaddr membase, hwaddr membase2,
 MemoryRegion *address_space,
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index e0f04dc..375c46f 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -33,12 +33,6 @@
 /***/
 /* MacIO based PowerPC IDE */
 
-typedef struct MACIOIDEState {
-MemoryRegion mem;
-IDEBus bus;
-BlockDriverAIOCB *aiocb;
-} MACIOIDEState;
-
 #define MACIO_PAGE_SIZE 4096
 
 static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
@@ -321,30 +315,70 @@ static const VMStateDescription vmstate_pmac = {
 }
 };
 
-static void pmac_ide_reset(void *opaque)
+static void macio_ide_reset(DeviceState *dev)
 {
-MACIOIDEState *d = opaque;
+MACIOIDEState *d = MACIO_IDE(dev);
 
 ide_bus_reset(d-bus);
 }
 
-/* hd_table must contain 4 block drivers */
-/* PowerMac uses memory mapped registers, not I/O. Return the memory
-   I/O index to access the ide. */
-MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
- void *dbdma, int channel, qemu_irq dma_irq)
+static void macio_ide_realizefn(DeviceState *dev, Error **errp)
 {
-MACIOIDEState *d;
+MACIOIDEState *s = MACIO_IDE(dev);
+
+ide_init2(s-bus, s-irq);
+}
+
+static void macio_ide_initfn(Object *obj)
+{
+SysBusDevice *d = SYS_BUS_DEVICE(obj);
+MACIOIDEState *s = MACIO_IDE(obj);
+
+ide_bus_new(s-bus, DEVICE(obj), 0);
+memory_region_init_io(s-mem, pmac_ide_ops, s, pmac-ide, 0x1000);
+sysbus_init_mmio(d, s-mem);
+sysbus_init_irq(d, s-irq);
+sysbus_init_irq(d, s-dma_irq);
+}
+
+static void macio_ide_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
+
+dc-realize = macio_ide_realizefn;
+dc-reset = macio_ide_reset;
+dc-vmsd = vmstate_pmac;
+}
 
-d = g_malloc0(sizeof(MACIOIDEState));
-ide_init2_with_non_qdev_drives(d-bus, hd_table[0], hd_table[1], irq);
+static const TypeInfo macio_ide_type_info = {
+.name = TYPE_MACIO_IDE,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(MACIOIDEState),
+.instance_init = macio_ide_initfn,
+.class_init = macio_ide_class_init,
+};
 
-if (dbdma)
-DBDMA_register_channel(dbdma, channel, dma_irq, pmac_ide_transfer, 
pmac_ide_flush, d);
+static void macio_ide_register_types(void)
+{
+type_register_static(macio_ide_type_info);
+}
 
-memory_region_init_io(d-mem, pmac_ide_ops, d, pmac-ide, 0x1000);
-vmstate_register(NULL, 0, vmstate_pmac, d);
-qemu_register_reset(pmac_ide_reset, d);
+/* hd_table must contain 4 block drivers */
+void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
+{
+int i;
 
-return d-mem;
+for (i = 0; i  2; i++) {
+if (hd_table[i]) {
+ide_create_drive(s-bus, i, hd_table[i]);
+}
+}
 }
+
+void macio_ide_register_dma(MACIOIDEState *s, void *dbdma, int channel)
+{
+DBDMA_register_channel(dbdma, channel, s-dma_irq,
+   pmac_ide_transfer, pmac_ide_flush, s);
+}
+
+type_init(macio_ide_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 32f359c..36c00e3 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -25,6 +25,7 @@
 #include hw.h
 #include ppc/mac.h
 #include pci/pci.h
+#include mac_dbdma.h
 #include escc.h
 
 #define TYPE_MACIO macio
@@ -37,12 +38,10 @@ typedef struct MacIOState
 /* public */
 
 MemoryRegion bar;
+void *dbdma;
 MemoryRegion *pic_mem;
-MemoryRegion *dbdma_mem;
 MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
-int nb_ide;
-MemoryRegion *ide_mem[4];
 } MacIOState;
 
 #define OLDWORLD_MACIO(obj) \
@@ -53,29 +52,33 @@ typedef struct OldWorldMacIOState {
 MacIOState parent_obj;
 /* public */
 
+qemu_irq irqs[2];
+
 MacIONVRAMState nvram;
+MACIOIDEState ide;
 } OldWorldMacIOState;
 
+#define 

Re: [Qemu-devel] [PATCH 1.4 0/2] iscsi: add support for iovectors

2013-01-24 Thread Peter Lieven

Hi Paolo,

it doesn't compile for LIBISCSI_FEATURE_IOVECTOR set.

you need to put this around every access to acb-buf
#if !defined(LIBISCSI_FEATURE_IOVECTOR)
   acb-buf 
#endif

lieven@lieven-pc:~/git/qemu$ LANG=C sudo make -j8 install
  CCqapi-types.o
  CCqapi-visit.o
  CCqga/commands.o
  CCqga/guest-agent-command-state.o
  CCqga/main.o
  CCqga/commands-posix.o
  CCqga/channel-posix.o
  CCqga/qapi-generated/qga-qapi-types.o
  CCqga/qapi-generated/qga-qapi-visit.o
  CCqga/qapi-generated/qga-qmp-marshal.o
  CCtrace/generated-tracers.o
  ARlibqemustub.a
  CCthread-pool.o
  CCblock.o
  CCblockjob.o
  CCqemu-timer.o
  CCblock/iscsi.o
  CCfsdev/virtfs-proxy-helper.o
  CCfsdev/virtio-9p-marshal.o
  CCqemu-bridge-helper.o
block/iscsi.c: In function 'iscsi_bh_cb':
block/iscsi.c:82:15: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c:83:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_write16_cb':
block/iscsi.c:205:15: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c:206:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_writev':
block/iscsi.c:253:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c:303:19: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_readv':
block/iscsi.c:368:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_flush':
block/iscsi.c:474:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_discard':
block/iscsi.c:528:8: error: 'IscsiAIOCB' has no member named 'buf'
block/iscsi.c: In function 'iscsi_aio_ioctl':
block/iscsi.c:604:8: error: 'IscsiAIOCB' has no member named 'buf'
  CCqemu-log.o
make: *** [block/iscsi.o] Error 1
make: *** Waiting for unfinished jobs

Peter

On 22.01.2013 17:37, Paolo Bonzini wrote:

Help testing these patches is welcome.

Paolo Bonzini (1):
   iscsi: do not leak acb-buf when commands are aborted

Peter Lieven (1):
   iscsi: add support for iovectors

  block/iscsi.c | 53 +++--
  1 file changed, 43 insertions(+), 10 deletions(-)






Re: [Qemu-devel] [PATCH 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Peter Lieven

Latest git doesn't compile with this patch:

hw/fw_cfg.c: In function 'fw_cfg_write':
hw/fw_cfg.c:207:5: error: implicit declaration of function 'trace_fw_cfg_write' 
[-Werror=implicit-function-declaration]
hw/fw_cfg.c:207:5: error: nested extern declaration of 'trace_fw_cfg_write' 
[-Werror=nested-externs]
hw/fw_cfg.c: In function 'fw_cfg_select':
hw/fw_cfg.c:232:5: error: implicit declaration of function 
'trace_fw_cfg_select' [-Werror=implicit-function-declaration]
hw/fw_cfg.c:232:5: error: nested extern declaration of 'trace_fw_cfg_select' 
[-Werror=nested-externs]
hw/fw_cfg.c: In function 'fw_cfg_read':
hw/fw_cfg.c:247:5: error: implicit declaration of function 'trace_fw_cfg_read' 
[-Werror=implicit-function-declaration]
hw/fw_cfg.c:247:5: error: nested extern declaration of 'trace_fw_cfg_read' 
[-Werror=nested-externs]
hw/fw_cfg.c: In function 'fw_cfg_add_file':
hw/fw_cfg.c:460:13: error: implicit declaration of function 
'trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
hw/fw_cfg.c:460:13: error: nested extern declaration of 
'trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
hw/fw_cfg.c:467:5: error: implicit declaration of function 
'trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
hw/fw_cfg.c:467:5: error: nested extern declaration of 'trace_fw_cfg_add_file' 
[-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [hw/fw_cfg.o] Error 1

Peter

On 16.01.2013 14:50, Markus Armbruster wrote:

Signed-off-by: Markus Armbruster arm...@redhat.com
---
  hw/fw_cfg.c  | 25 ++---
  trace-events |  7 +++
  2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 7c9480c..2fadf36 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,19 +26,10 @@
  #include isa.h
  #include fw_cfg.h
  #include sysbus.h
+#include trace.h
  #include qemu/error-report.h
  #include qemu/config-file.h
  
-/* debug firmware config */

-//#define DEBUG_FW_CFG
-
-#ifdef DEBUG_FW_CFG
-#define FW_CFG_DPRINTF(fmt, ...)\
-do { printf(FW_CFG:  fmt , ## __VA_ARGS__); } while (0)
-#else
-#define FW_CFG_DPRINTF(fmt, ...)
-#endif
-
  #define FW_CFG_SIZE 2
  #define FW_CFG_DATA_SIZE 1
  
@@ -213,7 +204,7 @@ static void fw_cfg_write(FWCfgState *s, uint8_t value)

  int arch = !!(s-cur_entry  FW_CFG_ARCH_LOCAL);
  FWCfgEntry *e = s-entries[arch][s-cur_entry  FW_CFG_ENTRY_MASK];
  
-FW_CFG_DPRINTF(write %d\n, value);

+trace_fw_cfg_write(s, value);
  
  if (s-cur_entry  FW_CFG_WRITE_CHANNEL  e-callback 

  s-cur_offset  e-len) {
@@ -238,8 +229,7 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
  ret = 1;
  }
  
-FW_CFG_DPRINTF(select key %d (%sfound)\n, key, ret ?  : not );

-
+trace_fw_cfg_select(s, key, ret);
  return ret;
  }
  
@@ -254,8 +244,7 @@ static uint8_t fw_cfg_read(FWCfgState *s)

  else
  ret = e-data[s-cur_offset++];
  
-FW_CFG_DPRINTF(read %d\n, ret);

-
+trace_fw_cfg_read(s, ret);
  return ret;
  }
  
@@ -470,16 +459,14 @@ int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,

  filename);
  for (i = 0; i  index; i++) {
  if (strcmp(s-files-f[index].name, s-files-f[i].name) == 0) {
-FW_CFG_DPRINTF(%s: skip duplicate: %s\n, __FUNCTION__,
-   s-files-f[index].name);
+trace_fw_cfg_add_file_dupe(s, s-files-f[index].name);
  return 1;
  }
  }
  
  s-files-f[index].size   = cpu_to_be32(len);

  s-files-f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
-FW_CFG_DPRINTF(%s: #%d: %s (%d bytes)\n, __FUNCTION__,
-   index, s-files-f[index].name, len);
+trace_fw_cfg_add_file(s, index, s-files-f[index].name, len);
  
  s-files-count = cpu_to_be32(index+1);

  return 1;
diff --git a/trace-events b/trace-events
index 6eabbac..cf76a11 100644
--- a/trace-events
+++ b/trace-events
@@ -167,6 +167,13 @@ ecc_mem_readl_ecr1(uint32_t ret) Read event count 2 %08x
  ecc_diag_mem_writeb(uint64_t addr, uint32_t val) Write diagnostic %PRId64 = 
%02x
  ecc_diag_mem_readb(uint64_t addr, uint32_t ret) Read diagnostic %PRId64= 
%02x
  
+# hw/fw_cfg.c

+fw_cfg_write(void *s, uint8_t value) %p %d
+fw_cfg_select(void *s, uint16_t key, int ret) %p key %d = %d
+fw_cfg_read(void *s, uint8_t ret) %p = %d
+fw_cfg_add_file_dupe(void *s, char *name) %p %s
+fw_cfg_add_file(void *s, int index, char *name, uint32_t len) %p #%d: %s (%d 
bytes)
+
  # hw/hd-geometry.c
  hd_geometry_lchs_guess(void *bs, int cyls, int heads, int secs) bs %p LCHS %d %d 
%d
  hd_geometry_guess(void *bs, uint32_t cyls, uint32_t heads, uint32_t secs, int trans) 
bs %p CHS %u %u %u trans %d





Re: [Qemu-devel] [Qemu-stable] [PATCH] Revert serial: fix retry logic

2013-01-24 Thread Andreas Färber
Am 22.01.2013 12:01, schrieb Michael Tokarev:
 Ping^3?
 
 This issue is still present in qemu 1.3 and current git (1.4-tobe)
 versions,
 and the said commit is still revertable, and reverting it still fixes the
 problem...
 
 I wonder why only debian users suffer from this problem ;)

It was reported for openSUSE as well [1], but Anthony promised me it
would get reverted for 1.3... I admit, I simply assumed it to be fixed
with v1.3.0.

Regards,
Andreas

[1] https://bugzilla.novell.com/show_bug.cgi?id=779727

 
 Thanks,
 
 /mjt
 
 12.11.2012 19:13, Michael Tokarev wrote:
 Ping^2 ?

 /mjt

 27.10.2012 12:31, Michael Tokarev wrote:
 Ping?

 On 19.09.2012 12:08, Michael Tokarev wrote:
 This reverts commit 67c5322d7000fd105a926eec44bc1765b7d70bdd:

  I'm not sure if the retry logic has ever worked when not using
 FIFO mode.  I
  found this while writing a test case although code inspection
 confirms it is
  definitely broken.

  The TSR retry logic will never actually happen because it is
 guarded by an
  'if (s-tsr_rety  0)' but this is the only place that can ever
 make the
  variable greater than zero.  That effectively makes the retry
 logic an 'if (0)

  I believe this is a typo and the intention was = 0.  Once this
 is fixed thoug
  I see double transmits with my test case.  This is because in
 the non FIFO
  case, serial_xmit may get invoked while LSR.THRE is still high
 because the
  character was processed but the retransmit timer was still active.

  We can handle this by simply checking for LSR.THRE and
 returning early.  It's
  possible that the FIFO paths also need some attention.

  Cc: Stefano Stabellini stefano.stabell...@eu.citrix.com
  Signed-off-by: Anthony Liguori aligu...@us.ibm.com

 Even if the previous logic was never worked, new logic breaks stuff -
 namely,

   qemu -enable-kvm -nographic -kernel /boot/vmlinuz-$(uname -r)
 -append console=ttyS0 -serial pty

 the above command will cause the virtual machine to stuck at startup
 using 100% CPU till one connects to the pty and sends any char to it.

 Note this is rather typical invocation for various headless virtual
 machines by libvirt.

 So revert this change for now, till a better solution will be found.

 Signed-off-by: Michael Tokarev m...@tls.msk.ru
 ---
   hw/serial.c |4 +---
   1 file changed, 1 insertion(+), 3 deletions(-)

 diff --git a/hw/serial.c b/hw/serial.c
 index a421d1e..df54de2 100644
 --- a/hw/serial.c
 +++ b/hw/serial.c
 @@ -327,8 +327,6 @@ static void serial_xmit(void *opaque)
   s-tsr = fifo_get(s,XMIT_FIFO);
   if (!s-xmit_fifo.count)
   s-lsr |= UART_LSR_THRE;
 -} else if ((s-lsr  UART_LSR_THRE)) {
 -return;
   } else {
   s-tsr = s-thr;
   s-lsr |= UART_LSR_THRE;
 @@ -340,7 +338,7 @@ static void serial_xmit(void *opaque)
   /* in loopback mode, say that we just received a char */
   serial_receive1(s, s-tsr, 1);
   } else if (qemu_chr_fe_write(s-chr, s-tsr, 1) != 1) {
 -if ((s-tsr_retry = 0)  (s-tsr_retry = MAX_XMIT_RETRY)) {
 +if ((s-tsr_retry  0)  (s-tsr_retry = MAX_XMIT_RETRY)) {
   s-tsr_retry++;
   qemu_mod_timer(s-transmit_timer,  new_xmit_ts +
 s-char_transmit_time);
   return;




 
 


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



Re: [Qemu-devel] [PATCH 1.4 0/2] iscsi: add support for iovectors

2013-01-24 Thread Paolo Bonzini
Il 24/01/2013 11:03, Peter Lieven ha scritto:
 Hi Paolo,
 
 it doesn't compile for LIBISCSI_FEATURE_IOVECTOR set.
 
 you need to put this around every access to acb-buf
 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
acb-buf 
 #endif

or remove the #ifdef around the declaration of the buf field.  Does it
work with that change?

Paolo

 lieven@lieven-pc:~/git/qemu$ LANG=C sudo make -j8 install
   CCqapi-types.o
   CCqapi-visit.o
   CCqga/commands.o
   CCqga/guest-agent-command-state.o
   CCqga/main.o
   CCqga/commands-posix.o
   CCqga/channel-posix.o
   CCqga/qapi-generated/qga-qapi-types.o
   CCqga/qapi-generated/qga-qapi-visit.o
   CCqga/qapi-generated/qga-qmp-marshal.o
   CCtrace/generated-tracers.o
   ARlibqemustub.a
   CCthread-pool.o
   CCblock.o
   CCblockjob.o
   CCqemu-timer.o
   CCblock/iscsi.o
   CCfsdev/virtfs-proxy-helper.o
   CCfsdev/virtio-9p-marshal.o
   CCqemu-bridge-helper.o
 block/iscsi.c: In function 'iscsi_bh_cb':
 block/iscsi.c:82:15: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:83:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_write16_cb':
 block/iscsi.c:205:15: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:206:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_writev':
 block/iscsi.c:253:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:303:19: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_readv':
 block/iscsi.c:368:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_flush':
 block/iscsi.c:474:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_discard':
 block/iscsi.c:528:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_ioctl':
 block/iscsi.c:604:8: error: 'IscsiAIOCB' has no member named 'buf'
   CCqemu-log.o
 make: *** [block/iscsi.o] Error 1
 make: *** Waiting for unfinished jobs
 
 Peter
 
 On 22.01.2013 17:37, Paolo Bonzini wrote:
 Help testing these patches is welcome.

 Paolo Bonzini (1):
iscsi: do not leak acb-buf when commands are aborted

 Peter Lieven (1):
iscsi: add support for iovectors

   block/iscsi.c | 53
 +++--
   1 file changed, 43 insertions(+), 10 deletions(-)

 




Re: [Qemu-devel] [PATCH] aio-posix: Fix return value of aio_poll()

2013-01-24 Thread Dietmar Maurer
  If I detect a incomplete write, I register an aio handler like this:
 
  ret = write(fd, buf, count)
   if (ret  0  (errno == EAGAIN || errno == EWOULDBLOCK) ) {
...
qemu_aio_set_fd_handler(fd, NULL, vma_co_continue_write,
 NULL, mydata);
qemu_coroutine_yield();
 
  But seems that qemu_aio_wait() returns false after that.
 
  I thought that should return true instead?
 
 You need a flush handler (fourth argument to qemu_aio_set_fd_handler)
 that returns true.

Ok, that helps :-) Many thanks!


[Qemu-devel] [PATCH for-1.4 v4 04/12] macio: Split MacIO in two

2013-01-24 Thread Andreas Färber
Let the machines create two different types. This prepares to move
knowledge about sub-devices from the machines into the devices.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c|   97 +++--
 hw/ppc/mac.h  |   10 +++--
 hw/ppc/mac_newworld.c |4 +-
 hw/ppc/mac_oldworld.c |4 +-
 4 Dateien geändert, 82 Zeilen hinzugefügt(+), 33 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index 8b4b48d..0e6fc8d 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -36,7 +36,6 @@ typedef struct MacIOState
 PCIDevice parent;
 /* public */
 
-int is_oldworld;
 MemoryRegion bar;
 MemoryRegion *pic_mem;
 MemoryRegion *dbdma_mem;
@@ -52,15 +51,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 int i;
 MemoryRegion *bar = macio_state-bar;
 
-if (macio_state-pic_mem) {
-if (macio_state-is_oldworld) {
-/* Heathrow PIC */
-memory_region_add_subregion(bar, 0x0, macio_state-pic_mem);
-} else {
-/* OpenPIC */
-memory_region_add_subregion(bar, 0x4, macio_state-pic_mem);
-}
-}
 if (macio_state-dbdma_mem) {
 memory_region_add_subregion(bar, 0x08000, macio_state-dbdma_mem);
 }
@@ -80,7 +70,7 @@ static void macio_bar_setup(MacIOState *macio_state)
 macio_nvram_setup_bar(macio_state-nvram, bar, 0x6);
 }
 
-static int macio_initfn(PCIDevice *d)
+static int macio_common_initfn(PCIDevice *d)
 {
 MacIOState *s = MACIO(d);
 
@@ -92,6 +82,38 @@ static int macio_initfn(PCIDevice *d)
 return 0;
 }
 
+static int macio_oldworld_initfn(PCIDevice *d)
+{
+MacIOState *s = MACIO(d);
+int ret = macio_common_initfn(d);
+if (ret  0) {
+return ret;
+}
+
+if (s-pic_mem) {
+/* Heathrow PIC */
+memory_region_add_subregion(s-bar, 0x0, s-pic_mem);
+}
+
+return 0;
+}
+
+static int macio_newworld_initfn(PCIDevice *d)
+{
+MacIOState *s = MACIO(d);
+int ret = macio_common_initfn(d);
+if (ret  0) {
+return ret;
+}
+
+if (s-pic_mem) {
+/* OpenPIC */
+memory_region_add_subregion(s-bar, 0x4, s-pic_mem);
+}
+
+return 0;
+}
+
 static void macio_instance_init(Object *obj)
 {
 MacIOState *s = MACIO(obj);
@@ -99,44 +121,69 @@ static void macio_instance_init(Object *obj)
 memory_region_init(s-bar, macio, 0x8);
 }
 
+static void macio_oldworld_class_init(ObjectClass *oc, void *data)
+{
+PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+pdc-init = macio_oldworld_initfn;
+pdc-device_id = PCI_DEVICE_ID_APPLE_343S1201;
+}
+
+static void macio_newworld_class_init(ObjectClass *oc, void *data)
+{
+PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+pdc-init = macio_newworld_initfn;
+pdc-device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL;
+}
+
 static void macio_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k-init = macio_initfn;
 k-vendor_id = PCI_VENDOR_ID_APPLE;
 k-class_id = PCI_CLASS_OTHERS  8;
 }
 
+static const TypeInfo macio_oldworld_type_info = {
+.name  = TYPE_OLDWORLD_MACIO,
+.parent= TYPE_MACIO,
+.class_init= macio_oldworld_class_init,
+};
+
+static const TypeInfo macio_newworld_type_info = {
+.name  = TYPE_NEWWORLD_MACIO,
+.parent= TYPE_MACIO,
+.class_init= macio_newworld_class_init,
+};
+
 static const TypeInfo macio_type_info = {
 .name  = TYPE_MACIO,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(MacIOState),
 .instance_init = macio_instance_init,
+.abstract  = true,
 .class_init= macio_class_init,
 };
 
 static void macio_register_types(void)
 {
 type_register_static(macio_type_info);
+type_register_static(macio_oldworld_type_info);
+type_register_static(macio_newworld_type_info);
 }
 
 type_init(macio_register_types)
 
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
- MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
- MemoryRegion *cuda_mem, void *nvram,
- int nb_ide, MemoryRegion **ide_mem,
- MemoryRegion *escc_mem)
+void macio_init(PCIDevice *d,
+MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+MemoryRegion *cuda_mem, void *nvram,
+int nb_ide, MemoryRegion **ide_mem,
+MemoryRegion *escc_mem)
 {
-PCIDevice *d;
-MacIOState *macio_state;
+MacIOState *macio_state = MACIO(d);
 int i;
 
-d = pci_create(bus, -1, TYPE_MACIO);
-
-macio_state = MACIO(d);
-macio_state-is_oldworld = is_oldworld;
 macio_state-pic_mem = pic_mem;
 macio_state-dbdma_mem = dbdma_mem;
 macio_state-cuda_mem = cuda_mem;
@@ -147,12 +194,8 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 macio_state-nb_ide = nb_ide;
 for (i = 0; i  

Re: [Qemu-devel] [PATCH 1.4 0/2] iscsi: add support for iovectors

2013-01-24 Thread Peter Lieven

Am 24.01.2013 um 11:07 schrieb Paolo Bonzini pbonz...@redhat.com:

 Il 24/01/2013 11:03, Peter Lieven ha scritto:
 Hi Paolo,
 
 it doesn't compile for LIBISCSI_FEATURE_IOVECTOR set.
 
 you need to put this around every access to acb-buf
 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
   acb-buf 
 #endif
 
 or remove the #ifdef around the declaration of the buf field.  Does it
 work with that change?

I will let you know. I am currently manually reverting f6e35343 since qemu 
does`t compile at all at
the moment.

Peter




[Qemu-devel] [PATCH for-1.4 v4 03/12] macio: Delay qdev init until all fields are initialized

2013-01-24 Thread Andreas Färber
This turns macio_bar_setup() into an implementation detail of the qdev
initfn, to be removed step by step.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c |   11 ---
 1 Datei geändert, 8 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index 770e3bd..8b4b48d 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -82,7 +82,13 @@ static void macio_bar_setup(MacIOState *macio_state)
 
 static int macio_initfn(PCIDevice *d)
 {
+MacIOState *s = MACIO(d);
+
 d-config[0x3d] = 0x01; // interrupt on pin 1
+
+macio_bar_setup(s);
+pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, s-bar);
+
 return 0;
 }
 
@@ -127,7 +133,7 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 MacIOState *macio_state;
 int i;
 
-d = pci_create_simple(bus, -1, TYPE_MACIO);
+d = pci_create(bus, -1, TYPE_MACIO);
 
 macio_state = MACIO(d);
 macio_state-is_oldworld = is_oldworld;
@@ -148,6 +154,5 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 
 pci_config_set_device_id(d-config, device_id);
 
-macio_bar_setup(macio_state);
-pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, macio_state-bar);
+qdev_init_nofail(DEVICE(d));
 }
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4 v4 09/12] cuda: QOM'ify CUDA

2013-01-24 Thread Andreas Färber
It was not qdev'ified before. Turn it into a SysBusDevice and embed it
in MacIO.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/cuda.c |   95 +
 hw/macio.c|   43 ++
 hw/ppc/mac.h  |   68 +--
 hw/ppc/mac_newworld.c |   21 ++-
 hw/ppc/mac_oldworld.c |   18 +-
 5 Dateien geändert, 154 Zeilen hinzugefügt(+), 91 Zeilen entfernt(-)

diff --git a/hw/cuda.c b/hw/cuda.c
index bbd1fda..f863c38 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -108,48 +108,6 @@
 /* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
 #define RTC_OFFSET  2082844800
 
-typedef struct CUDATimer {
-int index;
-uint16_t latch;
-uint16_t counter_value; /* counter value at load time */
-int64_t load_time;
-int64_t next_irq_time;
-QEMUTimer *timer;
-} CUDATimer;
-
-typedef struct CUDAState {
-MemoryRegion mem;
-/* cuda registers */
-uint8_t b;  /* B-side data */
-uint8_t a;  /* A-side data */
-uint8_t dirb;   /* B-side direction (1=output) */
-uint8_t dira;   /* A-side direction (1=output) */
-uint8_t sr; /* Shift register */
-uint8_t acr;/* Auxiliary control register */
-uint8_t pcr;/* Peripheral control register */
-uint8_t ifr;/* Interrupt flag register */
-uint8_t ier;/* Interrupt enable register */
-uint8_t anh;/* A-side data, no handshake */
-
-CUDATimer timers[2];
-
-uint32_t tick_offset;
-
-uint8_t last_b; /* last value of B register */
-uint8_t last_acr; /* last value of B register */
-
-int data_in_size;
-int data_in_index;
-int data_out_index;
-
-qemu_irq irq;
-uint8_t autopoll;
-uint8_t data_in[128];
-uint8_t data_out[16];
-QEMUTimer *adb_poll_timer;
-} CUDAState;
-
-static CUDAState cuda_state;
 ADBBusState adb_bus;
 
 static void cuda_update(CUDAState *s);
@@ -701,9 +659,9 @@ static const VMStateDescription vmstate_cuda = {
 }
 };
 
-static void cuda_reset(void *opaque)
+static void cuda_reset(DeviceState *dev)
 {
-CUDAState *s = opaque;
+CUDAState *s = CUDA(dev);
 
 s-b = 0;
 s-a = 0;
@@ -728,25 +686,54 @@ static void cuda_reset(void *opaque)
 set_counter(s, s-timers[1], 0x);
 }
 
-void cuda_init (MemoryRegion **cuda_mem, qemu_irq irq)
+static void cuda_realizefn(DeviceState *dev, Error **errp)
 {
+CUDAState *s = CUDA(dev);
 struct tm tm;
-CUDAState *s = cuda_state;
-
-s-irq = irq;
 
-s-timers[0].index = 0;
 s-timers[0].timer = qemu_new_timer_ns(vm_clock, cuda_timer1, s);
 
-s-timers[1].index = 1;
-
 qemu_get_timedate(tm, 0);
 s-tick_offset = (uint32_t)mktimegm(tm) + RTC_OFFSET;
 
 s-adb_poll_timer = qemu_new_timer_ns(vm_clock, cuda_adb_poll, s);
+}
+
+static void cuda_initfn(Object *obj)
+{
+SysBusDevice *d = SYS_BUS_DEVICE(obj);
+CUDAState *s = CUDA(obj);
+int i;
+
 memory_region_init_io(s-mem, cuda_ops, s, cuda, 0x2000);
+sysbus_init_mmio(d, s-mem);
+sysbus_init_irq(d, s-irq);
+
+for (i = 0; i  ARRAY_SIZE(s-timers); i++) {
+s-timers[i].index = i;
+}
+}
+
+static void cuda_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
 
-*cuda_mem = s-mem;
-vmstate_register(NULL, -1, vmstate_cuda, s);
-qemu_register_reset(cuda_reset, s);
+dc-realize = cuda_realizefn;
+dc-reset = cuda_reset;
+dc-vmsd = vmstate_cuda;
 }
+
+static const TypeInfo cuda_type_info = {
+.name = TYPE_CUDA,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(CUDAState),
+.instance_init = cuda_initfn,
+.class_init = cuda_class_init,
+};
+
+static void cuda_register_types(void)
+{
+type_register_static(cuda_type_info);
+}
+
+type_init(cuda_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 36c00e3..74bdcd1 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -38,9 +38,9 @@ typedef struct MacIOState
 /* public */
 
 MemoryRegion bar;
+CUDAState cuda;
 void *dbdma;
 MemoryRegion *pic_mem;
-MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
 } MacIOState;
 
@@ -52,7 +52,7 @@ typedef struct OldWorldMacIOState {
 MacIOState parent_obj;
 /* public */
 
-qemu_irq irqs[2];
+qemu_irq irqs[3];
 
 MacIONVRAMState nvram;
 MACIOIDEState ide;
@@ -65,7 +65,7 @@ typedef struct NewWorldMacIOState {
 /* private */
 MacIOState parent_obj;
 /* public */
-qemu_irq irqs[4];
+qemu_irq irqs[5];
 MACIOIDEState ide[2];
 } NewWorldMacIOState;
 
@@ -76,17 +76,24 @@ static void macio_bar_setup(MacIOState *macio_state)
 if (macio_state-escc_mem) {
 memory_region_add_subregion(bar, 0x13000, macio_state-escc_mem);
 }
-if (macio_state-cuda_mem) {
-memory_region_add_subregion(bar, 0x16000, macio_state-cuda_mem);
-}
 }
 
 static int macio_common_initfn(PCIDevice *d)
 {
 

Re: [Qemu-devel] [PATCH] ui/vnc: VA API based H.264 encoding for VNC framebuffer updates

2013-01-24 Thread Jérôme Jutteau
Hello Qemu people,

2013/1/9 David Verbeiren david.verbei...@intel.com:
 This patch implements H.264 encoding of the VNC framebuffer updates
 using hardware acceleration through the VA API.

Sounds Great !

Sorry if my question has a obvious response but I can't find it:
David, on which version of Qemu can we apply your attached patch ?

Thanks !

-- 
Jérôme Jutteau



[Qemu-devel] [PATCH for-1.4 v4 06/12] mac_nvram: Mark as Big Endian

2013-01-24 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c |2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index bcde07d..0a22e66 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -96,7 +96,7 @@ static uint64_t macio_nvram_readb(void *opaque, hwaddr addr,
 static const MemoryRegionOps macio_nvram_ops = {
 .read = macio_nvram_readb,
 .write = macio_nvram_writeb,
-.endianness = DEVICE_NATIVE_ENDIAN,
+.endianness = DEVICE_BIG_ENDIAN,
 };
 
 static const VMStateDescription vmstate_macio_nvram = {
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4 v4 05/12] mac_nvram: Clean up public API

2013-01-24 Thread Andreas Färber
The state data field is accessed in uint8_t quantities, so switch from
uint32_t argument and return value to uint8_t.

Fix debug format specifiers while at it.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c |   21 ++---
 hw/ppc/mac.h   |4 ++--
 2 Dateien geändert, 12 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index eec7ca4..bcde07d 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -47,27 +47,26 @@ struct MacIONVRAMState {
 #define DEF_SYSTEM_SIZE 0xc10
 
 /* Direct access to NVRAM */
-uint32_t macio_nvram_read (void *opaque, uint32_t addr)
+uint8_t macio_nvram_read(MacIONVRAMState *s, uint32_t addr)
 {
-MacIONVRAMState *s = opaque;
 uint32_t ret;
 
-if (addr  s-size)
+if (addr  s-size) {
 ret = s-data[addr];
-else
+} else {
 ret = -1;
-NVR_DPRINTF(read addr %04x val %x\n, addr, ret);
+}
+NVR_DPRINTF(read addr %04 PRIx32  val % PRIx8 \n, addr, ret);
 
 return ret;
 }
 
-void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val)
+void macio_nvram_write(MacIONVRAMState *s, uint32_t addr, uint8_t val)
 {
-MacIONVRAMState *s = opaque;
-
-NVR_DPRINTF(write addr %04x val %x\n, addr, val);
-if (addr  s-size)
+NVR_DPRINTF(write addr %04 PRIx32  val % PRIx8 \n, addr, val);
+if (addr  s-size) {
 s-data[addr] = val;
+}
 }
 
 /* macio style NVRAM device */
@@ -78,7 +77,7 @@ static void macio_nvram_writeb(void *opaque, hwaddr addr,
 
 addr = (addr  s-it_shift)  (s-size - 1);
 s-data[addr] = value;
-NVR_DPRINTF(writeb addr %04x val %x\n, (int)addr, value);
+NVR_DPRINTF(writeb addr %04 PHYS_PRIx  val % PRIx64 \n, addr, value);
 }
 
 static uint64_t macio_nvram_readb(void *opaque, hwaddr addr,
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 864a610..6441794 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -78,6 +78,6 @@ MacIONVRAMState *macio_nvram_init (hwaddr size,
 void macio_nvram_setup_bar(MacIONVRAMState *s, MemoryRegion *bar,
hwaddr mem_base);
 void pmac_format_nvram_partition (MacIONVRAMState *nvr, int len);
-uint32_t macio_nvram_read (void *opaque, uint32_t addr);
-void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val);
+uint8_t macio_nvram_read(MacIONVRAMState *s, uint32_t addr);
+void macio_nvram_write(MacIONVRAMState *s, uint32_t addr, uint8_t val);
 #endif /* !defined(__PPC_MAC_H__) */
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 1.4 0/2] iscsi: add support for iovectors

2013-01-24 Thread Peter Lieven

Am 24.01.2013 um 11:07 schrieb Paolo Bonzini pbonz...@redhat.com:

 Il 24/01/2013 11:03, Peter Lieven ha scritto:
 Hi Paolo,
 
 it doesn't compile for LIBISCSI_FEATURE_IOVECTOR set.
 
 you need to put this around every access to acb-buf
 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
   acb-buf 
 #endif
 
 or remove the #ifdef around the declaration of the buf field.  Does it
 work with that change?

Compiles and works.

Could you please add a note to the commit message that libiscsi 1.8.0+ is 
required for the IO-Vector
support.

Thanks,
Peter

 
 Paolo
 
 lieven@lieven-pc:~/git/qemu$ LANG=C sudo make -j8 install
  CCqapi-types.o
  CCqapi-visit.o
  CCqga/commands.o
  CCqga/guest-agent-command-state.o
  CCqga/main.o
  CCqga/commands-posix.o
  CCqga/channel-posix.o
  CCqga/qapi-generated/qga-qapi-types.o
  CCqga/qapi-generated/qga-qapi-visit.o
  CCqga/qapi-generated/qga-qmp-marshal.o
  CCtrace/generated-tracers.o
  ARlibqemustub.a
  CCthread-pool.o
  CCblock.o
  CCblockjob.o
  CCqemu-timer.o
  CCblock/iscsi.o
  CCfsdev/virtfs-proxy-helper.o
  CCfsdev/virtio-9p-marshal.o
  CCqemu-bridge-helper.o
 block/iscsi.c: In function 'iscsi_bh_cb':
 block/iscsi.c:82:15: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:83:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_write16_cb':
 block/iscsi.c:205:15: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:206:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_writev':
 block/iscsi.c:253:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c:303:19: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_readv':
 block/iscsi.c:368:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_flush':
 block/iscsi.c:474:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_discard':
 block/iscsi.c:528:8: error: 'IscsiAIOCB' has no member named 'buf'
 block/iscsi.c: In function 'iscsi_aio_ioctl':
 block/iscsi.c:604:8: error: 'IscsiAIOCB' has no member named 'buf'
  CCqemu-log.o
 make: *** [block/iscsi.o] Error 1
 make: *** Waiting for unfinished jobs
 
 Peter
 
 On 22.01.2013 17:37, Paolo Bonzini wrote:
 Help testing these patches is welcome.
 
 Paolo Bonzini (1):
   iscsi: do not leak acb-buf when commands are aborted
 
 Peter Lieven (1):
   iscsi: add support for iovectors
 
  block/iscsi.c | 53
 +++--
  1 file changed, 43 insertions(+), 10 deletions(-)
 
 
 




[Qemu-devel] [PATCH V11 0/4] replace QEMUOptionParameter with QemuOpts parser

2013-01-24 Thread Dong Xu Wang
Patch 1 add def_value_str and use it in qemu_opts_print.

Patch 2 Create functions to pair with QEMUOptionParameter parser.

Patch 3 Use QemuOpts parser in Block.

Patch 4 Remove QEMUOptionParameter parser related code.

def_value_str is not real default value string now, we have to use it like
this:
cluster_size = qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZE, 
 DEFAULT_CLUSTER_SIZE);
qemu_opt_get_size has many consumers now, so I did not change it in this patch
series.

Checking whether opts is NULL is useless in block format drivers, but it is
needed in block protocols, I think formats and protocols should share the
same code style, so I checked opts in block format drivers. 
  

V10-V11:
1)  print all values that have actually been assigned while accept-any
cases.
2) qed.h move QED_DEFAULT_CLUSTER_SIZE from enum to macro, or
qemu_opts_print produce un-expanded cluster_size.
3) In qcow2.c and qcow.c, bdrv_create_file(filename, NULL), NULL - opts,
or while using protocol, there will be an error.

V9-V10:
1) Fix compile error on patch 3.

v8-v9:
1) add qemu_ prefix to gluster_create_opts.
2) fix bug: bdrv_gluster_unix and bdrv_gluster_rdma should also be
   converted.

v7-v8:
1) print elements = accept any params while opts_accepts_any() ==
true.
2) since def_print_str is the default value if an option isn't set,
so rename it to def_value_str.
3) rebase to upstream source tree.
4) add gluster.c, raw-win32.c, and rbd.c.

v6-v7:
1) Fix typo: enouth-enough.
2) use osdep.h:stringify(), not redefining new macro.
3) preserve TODO comment.
4) fix typo: BLOCK_OPT_ENCRYPT-BLOCK_OPT_STATIC.
5) initialize disk_type even when opts is NULL.

v5-v6:
1) allocate enough space in append_opts_list function.
2) judge if opts == NULL in block layer create functions.
3) use bdrv_create_file(filename, NULL) in qcow_create funtion.
4) made more readable while using qemu_opt_get_number funtion.

v4-v5:
1) Rewrite qemu_opts_create_nofail function based on Peter Maydell's comments.
2) Use g_strdup_printf in qemu_opt_set_number.
3) Rewrite qemu_opts_print.
4) .bdrv_create_options returns pointer directly. Fix a bug about encryption.
5) Check qemu_opt_get_number in raw-posix.c.

v3-v4:
1) Rebased to the newest source tree.
2) Remove redundant #include block-cache.h
3) Other small changes.

v2-v3:
1) rewrite qemu_opt_set_bool and qemu_opt_set_number according Paolo's coments.
2) split patches to make review easier.

v1-v2:
1) add Luiz's patches.
2) create qemu_opt_set_number() and qemu_opts_create_nofail() functions.
3) add QemuOptsList map to drivers.
4) use original opts parser, not creating new ones.
5) fix other bugs.


Dong Xu Wang (4):
  add def_value_str and use it in qemu_opts_print
  Create four opts list related functions
  Use QemuOpts support in block layer
  remove QEMUOptionParameter related functions and struct

 block.c   |  91 +--
 block/cow.c   |  46 +++---
 block/gluster.c   |  37 ++---
 block/qcow.c  |  60 +++
 block/qcow2.c | 171 ++--
 block/qed.c   |  86 +-
 block/qed.h   |   2 +-
 block/raw-posix.c |  59 ---
 block/raw-win32.c |  30 ++--
 block/raw.c   |  30 ++--
 block/rbd.c   |  62 +++
 block/sheepdog.c  |  75 +
 block/vdi.c   |  69 
 block/vmdk.c  |  74 -
 block/vpc.c   |  67 
 block/vvfat.c |  11 +-
 include/block/block.h |   4 +-
 include/block/block_int.h |   6 +-
 include/qemu/option.h |  37 +
 qemu-img.c|  61 ---
 util/qemu-option.c| 405 +-
 21 files changed, 639 insertions(+), 844 deletions(-)

-- 
1.7.11.7




[Qemu-devel] [PATCH V11 2/4] Create four opts list related functions

2013-01-24 Thread Dong Xu Wang
This patch will create 4 functions, count_opts_list, append_opts_list,
free_opts_list and print_opts_list, they will used in following commits.

Signed-off-by: Dong Xu Wang wdon...@vnet.linux.ibm.com
---
v6-v7):
1) Fix typo.

v5-v6):
1) allocate enough space in append_opts_list function.

 include/qemu/option.h |  4 +++
 util/qemu-option.c| 90 +++
 2 files changed, 94 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 394170a..f784c2e 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -156,4 +156,8 @@ int qemu_opts_print(QemuOpts *opts, void *dummy);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
+QemuOptsList *append_opts_list(QemuOptsList *dest,
+   QemuOptsList *list);
+void free_opts_list(QemuOptsList *list);
+void print_opts_list(QemuOptsList *list);
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 1aed418..f4bbbf8 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1152,3 +1152,93 @@ int qemu_opts_foreach(QemuOptsList *list, 
qemu_opts_loopfunc func, void *opaque,
 loc_pop(loc);
 return rc;
 }
+
+static size_t count_opts_list(QemuOptsList *list)
+{
+size_t i = 0;
+
+while (list  list-desc[i].name) {
+i++;
+}
+
+return i;
+}
+
+/* Create a new QemuOptsList and make its desc to the merge of first and 
second.
+ * It will allocate space for one new QemuOptsList plus enough space for
+ * QemuOptDesc in first and second QemuOptsList. First argument's QemuOptDesc
+ * members take precedence over second's.
+ */
+QemuOptsList *append_opts_list(QemuOptsList *first,
+   QemuOptsList *second)
+{
+size_t num_first_options, num_second_options;
+QemuOptsList *dest = NULL;
+int i = 0;
+int index = 0;
+
+num_first_options = count_opts_list(first);
+num_second_options = count_opts_list(second);
+if (num_first_options + num_second_options == 0) {
+return NULL;
+}
+
+dest = g_malloc0(sizeof(QemuOptsList)
++ (num_first_options + num_second_options + 1) * sizeof(QemuOptDesc));
+
+dest-name = append_opts_list;
+dest-implied_opt_name = NULL;
+dest-merge_lists = false;
+QTAILQ_INIT(dest-head);
+while (first  (first-desc[i].name)) {
+if (!find_desc_by_name(dest-desc, first-desc[i].name)) {
+dest-desc[index].name = g_strdup(first-desc[i].name);
+dest-desc[index].help = g_strdup(first-desc[i].help);
+dest-desc[index].type = first-desc[i].type;
+dest-desc[index].def_value_str =
+g_strdup(first-desc[i].def_value_str);
+++index;
+   }
+i++;
+}
+i = 0;
+while (second  (second-desc[i].name)) {
+if (!find_desc_by_name(dest-desc, second-desc[i].name)) {
+dest-desc[index].name = g_strdup(first-desc[i].name);
+dest-desc[index].help = g_strdup(first-desc[i].help);
+dest-desc[index].type = second-desc[i].type;
+dest-desc[index].def_value_str =
+g_strdup(second-desc[i].def_value_str);
+++index;
+}
+i++;
+}
+dest-desc[index].name = NULL;
+return dest;
+}
+
+void free_opts_list(QemuOptsList *list)
+{
+int i = 0;
+
+while (list  list-desc[i].name) {
+g_free((char *)list-desc[i].name);
+g_free((char *)list-desc[i].help);
+g_free((char *)list-desc[i].def_value_str);
+i++;
+}
+
+g_free(list);
+}
+
+void print_opts_list(QemuOptsList *list)
+{
+int i = 0;
+printf(Supported options:\n);
+while (list  list-desc[i].name) {
+printf(%-16s %s\n, list-desc[i].name,
+list-desc[i].help ?
+list-desc[i].help : No description available);
+i++;
+}
+}
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH 3/3] QAPI: Introduce memchar-read QMP command

2013-01-24 Thread Lei Li

On 01/23/2013 11:42 PM, Luiz Capitulino wrote:

On Wed, 23 Jan 2013 17:06:12 +0800
Lei Li li...@linux.vnet.ibm.com wrote:


Signed-off-by: Lei Li li...@linux.vnet.ibm.com
---
  hmp-commands.hx  |   21 +
  hmp.c|   17 +
  hmp.h|1 +
  qapi-schema.json |   36 
  qemu-char.c  |   48 
  qmp-commands.hx  |   33 +
  6 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index bcfea11..bdd48f3 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -858,6 +858,27 @@ to char device 'memory'.
  ETEXI
  
  {

+.name   = memchar_read,
+.args_type  = device:s,size:i,
+.params = device size,
+.help   = Provide read interface for CirMemCharDriver. Read from
+  it and return the data with size.,
+.mhandler.cmd = hmp_memchar_read,
+},
+
+STEXI
+@item memchar_read @var{device}
+@findex memchar_read
+Provide read interface for CirMemCharDriver. Read from char device
+'memory' and return the data.
+
+@var{size} is the size of data want to read from. Refer to unencoded
+size of the raw data, would adjust to the init size of the memchar
+if the requested size is larger than it.
+
+ETEXI
+
+{
  .name   = migrate,
  .args_type  = detach:-d,blk:-b,inc:-i,uri:s,
  .params = [-d] [-b] [-i] uri,
diff --git a/hmp.c b/hmp.c
index 647316a..1f1df5d 100644
--- a/hmp.c
+++ b/hmp.c
@@ -697,6 +697,23 @@ void hmp_memchar_write(Monitor *mon, const QDict *qdict)
  hmp_handle_error(mon, errp);
  }
  
+void hmp_memchar_read(Monitor *mon, const QDict *qdict)

+{
+uint32_t size = qdict_get_int(qdict, size);
+const char *chardev = qdict_get_str(qdict, device);
+MemCharRead *meminfo;
+Error *errp = NULL;
+
+meminfo = qmp_memchar_read(chardev, size, false, 0, errp);
+if (errp) {
+monitor_printf(mon, %s\n, error_get_pretty(errp));
+error_free(errp);
+return;
+}
+
+monitor_printf(mon, %s, \n, meminfo-data);
+}
+
  static void hmp_cont_cb(void *opaque, int err)
  {
  if (!err) {
diff --git a/hmp.h b/hmp.h
index 06d6ea2..076d8cf 100644
--- a/hmp.h
+++ b/hmp.h
@@ -44,6 +44,7 @@ void hmp_cpu(Monitor *mon, const QDict *qdict);
  void hmp_memsave(Monitor *mon, const QDict *qdict);
  void hmp_pmemsave(Monitor *mon, const QDict *qdict);
  void hmp_memchar_write(Monitor *mon, const QDict *qdict);
+void hmp_memchar_read(Monitor *mon, const QDict *qdict);
  void hmp_cont(Monitor *mon, const QDict *qdict);
  void hmp_system_wakeup(Monitor *mon, const QDict *qdict);
  void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 8202311..ad4e276 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -363,6 +363,42 @@
 '*format': 'DataFormat'} }
  
  ##

+# @MemCharRead
+#
+# Result of QMP command memchar-read.
+#
+# @data: The data read from memchar as string.
+#
+# @count: The numbers of bytes read from.
+#
+# Since: 1.4
+##
+{ 'type': 'MemCharRead',
+  'data': { 'data': 'str', 'count': 'int' } }
+
+##
+# @memchar-read:
+#
+# Provide read interface for memchardev. Read from the char
+# device 'memory' and return the data.
+#
+# @device: the name of the memory char device.
+#
+# @size: the size to read in bytes.
+#
+# @format: #optional the format of the data want to read from
+#  memchardev, by default is 'utf8'.
+#
+# Returns: @MemCharRead
+#  If @device is not a valid memchr device, DeviceNotFound
+#
+# Since: 1.4
+##
+{ 'command': 'memchar-read',
+  'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'},
+  'returns': 'MemCharRead' }
+
+##
  # @CommandInfo:
  #
  # Information about a QMP command
diff --git a/qemu-char.c b/qemu-char.c
index dbd1a7c..c45397a 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2790,6 +2790,54 @@ void qmp_memchar_write(const char *device, int64_t size,
  }
  }
  
+MemCharRead *qmp_memchar_read(const char *device, int64_t size,

+  bool has_format, enum DataFormat format,
+  Error **errp)
+{
+CharDriverState *chr;
+guchar *read_data;
+MemCharRead *meminfo;
+size_t count;
+
+chr = qemu_chr_find(device);
+if (!chr) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+return NULL;
+}
+
+if (qemu_is_chr(chr, memory)) {
+error_setg(errp,%s is not memory char device, device);
+return NULL;
+}
+
+if (size = 0) {
+error_setg(errp, size must be greater than zero);
+return NULL;
+}
+
+/* Return empty strings when the buffer is empty. */
+if (cirmem_chr_is_empty(chr)) {
+return NULL;
+}

You can't just return NULL here, if you have to return MemCharRead. It's
not a problem to have an empty data 

Re: [Qemu-devel] [PATCH for-1.4] target-cris: Fix typo in D_LOG() macro

2013-01-24 Thread Andreas Färber
Am 24.01.2013 10:51, schrieb Andreas Färber:
 It's __VAR_ARGS__. Fixes the build with CRIS_[OP_]HELPER_DEBUG defined.

__VA_ARGS__ obviously. :) Please fix when committing.

Andreas

 
 Broken since r6338 / 93fcfe39a0383377e647b821c9f165fd927cd4e0 (Convert
 references to logfile/loglevel to use qemu_log*() macros).
 
 Cc: Eduardo Habkost ehabk...@redhat.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
  target-cris/helper.c|2 +-
  target-cris/op_helper.c |2 +-
  2 Dateien geändert, 2 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
 
 diff --git a/target-cris/helper.c b/target-cris/helper.c
 index 8407a6d..6e75e98 100644
 --- a/target-cris/helper.c
 +++ b/target-cris/helper.c
 @@ -28,7 +28,7 @@
  
  #ifdef CRIS_HELPER_DEBUG
  #define D(x) x
 -#define D_LOG(...) qemu_log(__VA__ARGS__)
 +#define D_LOG(...) qemu_log(__VA_ARGS__)
  #else
  #define D(x)
  #define D_LOG(...) do { } while (0)
 diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
 index 79bff38..0f6a1ee 100644
 --- a/target-cris/op_helper.c
 +++ b/target-cris/op_helper.c
 @@ -28,7 +28,7 @@
  
  #ifdef CRIS_OP_HELPER_DEBUG
  #define D(x) x
 -#define D_LOG(...) qemu_log(__VA__ARGS__)
 +#define D_LOG(...) qemu_log(__VA_ARGS__)
  #else
  #define D(x)
  #define D_LOG(...) do { } while (0)
 


-- 
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] target-i386: kvm: prevent buffer overflow if -cpu foo, [x]level is too big

2013-01-24 Thread Laszlo Ersek
comments in-line

On 01/24/13 00:05, Igor Mammedov wrote:
 Stack corruption may occur if too big 'level' or 'xlevel' values passed
 on command line with KVM enabled, due to limited size of cpuid_data
 in kvm_arch_init_vcpu().
 
 reproduces with:
  qemu -enable-kvm -cpu qemu64,level=4294967295
 or
  qemu -enable-kvm -cpu qemu64,xlevel=4294967295
 
 Check if there is space in cpuid_data before passing it to cpu_x86_cpuid()
 or abort() if there is not space.
 
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 ---
  target-i386/kvm.c | 27 ++-
  1 file changed, 26 insertions(+), 1 deletion(-)
 
 diff --git a/target-i386/kvm.c b/target-i386/kvm.c
 index 3acff40..8885b22 100644
 --- a/target-i386/kvm.c
 +++ b/target-i386/kvm.c
 @@ -413,10 +413,13 @@ static void cpu_update_state(void *opaque, int running, 
 RunState state)
  
  int kvm_arch_init_vcpu(CPUState *cs)
  {
 +const int max_cpuid_entries = 100;
  struct {
  struct kvm_cpuid2 cpuid;
 -struct kvm_cpuid_entry2 entries[100];
 +struct kvm_cpuid_entry2 entries[max_cpuid_entries];
  } QEMU_PACKED cpuid_data;

This does not conform to C99 (it would probably conform to ISO C++); it
violates 6.7.5.2 Array declarators:

2 Only an ordinary identifier (as defined in 6.2.3) with both block
  scope or function prototype scope and no linkage shall have a
  variably modified type.

entries here is not an ordinary identifier; it is in the members of
structures or unions namespace (6.2.3 Name spaces of identifiers).

If you compile such code with gcc -std=c99 -pedantic -Wall -Wextra,
gcc emits

  warning: a member of a structure or union cannot have a variably
   modified type

Anyway a #define easily fixes this.

 +const struct kvm_cpuid_entry2 *cpuid_last_entry =
 +cpuid_data.entries[max_cpuid_entries - 1];

Consider const-qualifying not only the target of the pointer, but the
pointer itself:

const struct kvm_cpuid_entry2 * const cpuid_last_entry = ...

  X86CPU *cpu = X86_CPU(cs);
  CPUX86State *env = cpu-env;
  uint32_t limit, i, j, cpuid_i;
 @@ -503,6 +506,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
  
  for (i = 0; i = limit; i++) {
  c = cpuid_data.entries[cpuid_i++];
 +if (c  cpuid_last_entry) {
 +fprintf(stderr, unsupported level value: 0x%x\n, limit);
 +abort();
 +}

These comparisons are fine. If c points just one past the last element
in the array, then c is still valid for evaluation (but not
dereferencing), and it can be compared against another pointer into the
same array.

Also, the patch seems to catch all

  c = cpuid_data.entries[cpuid_i++];

statements that are inside loops, and the rest (a low fixed number) is
covered by an array size like 100. If you introduce the #define (or
someone tells me we're not pedantic) you'll have my (not really relevant
:)) nod.

Thanks
Laszlo



Re: [Qemu-devel] [PATCH for-1.4] target-cris: Fix typo in D_LOG() macro

2013-01-24 Thread Edgar E. Iglesias
On Thu, Jan 24, 2013 at 10:51:47AM +0100, Andreas Färber wrote:
 It's __VAR_ARGS__. Fixes the build with CRIS_[OP_]HELPER_DEBUG defined.
 
 Broken since r6338 / 93fcfe39a0383377e647b821c9f165fd927cd4e0 (Convert
 references to logfile/loglevel to use qemu_log*() macros).

Applied, thanks!


 
 Cc: Eduardo Habkost ehabk...@redhat.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
  target-cris/helper.c|2 +-
  target-cris/op_helper.c |2 +-
  2 Dateien geändert, 2 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
 
 diff --git a/target-cris/helper.c b/target-cris/helper.c
 index 8407a6d..6e75e98 100644
 --- a/target-cris/helper.c
 +++ b/target-cris/helper.c
 @@ -28,7 +28,7 @@
  
  #ifdef CRIS_HELPER_DEBUG
  #define D(x) x
 -#define D_LOG(...) qemu_log(__VA__ARGS__)
 +#define D_LOG(...) qemu_log(__VA_ARGS__)
  #else
  #define D(x)
  #define D_LOG(...) do { } while (0)
 diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
 index 79bff38..0f6a1ee 100644
 --- a/target-cris/op_helper.c
 +++ b/target-cris/op_helper.c
 @@ -28,7 +28,7 @@
  
  #ifdef CRIS_OP_HELPER_DEBUG
  #define D(x) x
 -#define D_LOG(...) qemu_log(__VA__ARGS__)
 +#define D_LOG(...) qemu_log(__VA_ARGS__)
  #else
  #define D(x)
  #define D_LOG(...) do { } while (0)
 -- 
 1.7.10.4
 



Re: [Qemu-devel] [PATCH 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Markus Armbruster
Peter Lieven p...@dlhnet.de writes:

 Latest git doesn't compile with this patch:

 hw/fw_cfg.c: In function 'fw_cfg_write':
 hw/fw_cfg.c:207:5: error: implicit declaration of function
 trace_fw_cfg_write' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:207:5: error: nested extern declaration of
 trace_fw_cfg_write' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_select':
 hw/fw_cfg.c:232:5: error: implicit declaration of function
 trace_fw_cfg_select' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:232:5: error: nested extern declaration of
 trace_fw_cfg_select' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_read':
 hw/fw_cfg.c:247:5: error: implicit declaration of function
 trace_fw_cfg_read' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:247:5: error: nested extern declaration of
 trace_fw_cfg_read' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_add_file':
 hw/fw_cfg.c:460:13: error: implicit declaration of function
 trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:460:13: error: nested extern declaration of
 trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
 hw/fw_cfg.c:467:5: error: implicit declaration of function
 trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:467:5: error: nested extern declaration of
 trace_fw_cfg_add_file' [-Werror=nested-externs]
 cc1: all warnings being treated as errors
 make: *** [hw/fw_cfg.o] Error 1

Compiles fine for me.

What happens if you blow away your build tree and start over?

In my experience, rebuilding of trace-related stuff is rather fragile...



Re: [Qemu-devel] [PATCH V2 2/6] hw/mdio: Generalize etraxfs MDIO bitbanging emulation

2013-01-24 Thread Grant Likely
On Wed, 23 Jan 2013 23:45:13 +, Paul Brook p...@codesourcery.com wrote:
  +#ifdef USE_THIS_DEAD_CODE
  +void mdio_detach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int
  addr) +{
  +bus-devs[addr  0x1f] = NULL;
  +}
  +#endif
 
 This is clearly wrong.

It's in both versions of the original code. I didn't add this. I
included it when moving a code block because it appears to be there as a
point of completeness if it ever should be needed.

Edgar, do you want to keep this block around?

 It also worries me that there isn't a clean separation between the MDIO bus 
 and the bitbang interface.  IMO the bitbang interface should be a separate 
 device, and if we're wiring up bitbang interfaces then it really should be 
 via 
 standard GPIO pins (aka qemu_irq). 

Only the bitbang state machine is in the mdio layer. It says nothing
about where those signals come from, gpio or otherwise. Not all cases
will actually be GPIOs. For instance, the smc91c111 has dedicated pins
for MDIO operations which are not GPIOs, even though the driver has to
manage the bigbanging.

That said, I'm not opposed to changing the model if that is the design
direction. However, I hope that the series won't be blocked on this
point. This series moves and enhances existing code. A move to qemu_irq
should be done as a follow-on patch.

g.



Re: [Qemu-devel] [PATCH V2 1/6] trivial: etraxfs_eth: Eliminate checkpatch errors

2013-01-24 Thread Grant Likely
On Thu, 24 Jan 2013 10:09:26 +0100, Andreas Färber afaer...@suse.de wrote:
 Am 23.01.2013 17:15, schrieb Grant Likely:
  This is a trivial patch to harmonize the coding style on
  hw/etraxfs_eth.c. This is in preparation to split off the bitbang mdio
  code into a separate file.
  
  Cc: Peter Maydell peter.mayd...@linaro.org
  Cc: Paul Brook p...@codesourcery.com
  Cc: Edgar E. Iglesias edgar.igles...@gmail.com
  Cc: Anthony Liguori aligu...@us.ibm.com
  Cc: Andreas Färber afaer...@suse.de
  Signed-off-by: Grant Likely grant.lik...@secretlab.ca
 
 In the future please don't prefix patches with trivial:  - if they're
 truely trivial and the code is unmaintained (i.e., not in this case) you
 should cc qemu-triv...@nongnu.org instead. extraxfs_eth: ... as
 subject would've been sufficient.

okay.

g.




[Qemu-devel] [PATCH V11 4/4] remove QEMUOptionParameter related functions and struct

2013-01-24 Thread Dong Xu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
---
 include/qemu/option.h |  32 --
 util/qemu-option.c| 285 --
 2 files changed, 317 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index f784c2e..094663b 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -38,17 +38,6 @@ enum QEMUOptionParType {
 OPT_STRING,
 };
 
-typedef struct QEMUOptionParameter {
-const char *name;
-enum QEMUOptionParType type;
-union {
-uint64_t n;
-char* s;
-} value;
-const char *help;
-} QEMUOptionParameter;
-
-
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
 int get_next_param_value(char *buf, int buf_size,
@@ -58,27 +47,6 @@ int get_param_value(char *buf, int buf_size,
 int check_params(char *buf, int buf_size,
  const char * const *params, const char *str);
 
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry-name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
-QEMUOptionParameter *list, QEMUOptionParameter *dest);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
-
 /* -- */
 
 typedef struct QemuOpt QemuOpt;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index f4bbbf8..c56a8e1 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -153,22 +153,6 @@ int check_params(char *buf, int buf_size,
 return 0;
 }
 
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name)
-{
-while (list  list-name) {
-if (!strcmp(list-name, name)) {
-return list;
-}
-list++;
-}
-
-return NULL;
-}
-
 static void parse_option_bool(const char *name, const char *value, bool *ret,
   Error **errp)
 {
@@ -240,275 +224,6 @@ static void parse_option_size(const char *name, const 
char *value,
 }
 }
 
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- *  If no value is given, the flag is set to 1.
- *  Otherwise the value must be on (set to 1) or off (set to 0)
- *
- * OPT_STRING (uses value.s):
- *  value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- *  The value is converted to an integer. Suffixes for kilobytes etc. are
- *  allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value)
-{
-bool flag;
-Error *local_err = NULL;
-
-// Find a matching parameter
-list = get_option_parameter(list, name);
-if (list == NULL) {
-fprintf(stderr, Unknown option '%s'\n, name);
-return -1;
-}
-
-// Process parameter
-switch (list-type) {
-case OPT_FLAG:
-parse_option_bool(name, value, flag, local_err);
-if (!error_is_set(local_err)) {
-list-value.n = flag;
-}
-break;
-
-case OPT_STRING:
-if (value != NULL) {
-list-value.s = g_strdup(value);
-} else {
-fprintf(stderr, Option '%s' needs a parameter\n, name);
-return -1;
-}
-break;
-
-case OPT_SIZE:
-parse_option_size(name, value, list-value.n, local_err);
-break;
-
-default:
-fprintf(stderr, Bug: Option '%s' has an unknown type\n, name);
-return -1;
-}
-
-if (error_is_set(local_err)) {
-qerror_report_err(local_err);
-error_free(local_err);
-return -1;
-}
-
-return 0;
-}
-
-/*
- * Sets the given parameter to an integer instead of a string.
- * This function cannot be used to set string options.
- *
- * Returns 0 on success, -1 in error cases
- */
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value)
-{
-// Find a matching parameter
-list = get_option_parameter(list, name);
-if (list == NULL) {
-fprintf(stderr, Unknown option 

Re: [Qemu-devel] [PATCH 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Andreas Färber
Am 24.01.2013 11:32, schrieb Markus Armbruster:
 Peter Lieven p...@dlhnet.de writes:
 
 Latest git doesn't compile with this patch:

 hw/fw_cfg.c: In function 'fw_cfg_write':
 hw/fw_cfg.c:207:5: error: implicit declaration of function
 trace_fw_cfg_write' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:207:5: error: nested extern declaration of
 trace_fw_cfg_write' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_select':
 hw/fw_cfg.c:232:5: error: implicit declaration of function
 trace_fw_cfg_select' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:232:5: error: nested extern declaration of
 trace_fw_cfg_select' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_read':
 hw/fw_cfg.c:247:5: error: implicit declaration of function
 trace_fw_cfg_read' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:247:5: error: nested extern declaration of
 trace_fw_cfg_read' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_add_file':
 hw/fw_cfg.c:460:13: error: implicit declaration of function
 trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:460:13: error: nested extern declaration of
 trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
 hw/fw_cfg.c:467:5: error: implicit declaration of function
 trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:467:5: error: nested extern declaration of
 trace_fw_cfg_add_file' [-Werror=nested-externs]
 cc1: all warnings being treated as errors
 make: *** [hw/fw_cfg.o] Error 1
 
 Compiles fine for me.
 
 What happens if you blow away your build tree and start over?
 
 In my experience, rebuilding of trace-related stuff is rather fragile...

There were some recent changes ... there's probably a stale trace.h and
trace.c in the build directory.

Would be nice if we could get the build system to automatically remove
such known stale files...

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 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Peter Lieven

Am 24.01.2013 um 11:32 schrieb Markus Armbruster arm...@redhat.com:

 Peter Lieven p...@dlhnet.de writes:
 
 Latest git doesn't compile with this patch:
 
 hw/fw_cfg.c: In function 'fw_cfg_write':
 hw/fw_cfg.c:207:5: error: implicit declaration of function
 trace_fw_cfg_write' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:207:5: error: nested extern declaration of
 trace_fw_cfg_write' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_select':
 hw/fw_cfg.c:232:5: error: implicit declaration of function
 trace_fw_cfg_select' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:232:5: error: nested extern declaration of
 trace_fw_cfg_select' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_read':
 hw/fw_cfg.c:247:5: error: implicit declaration of function
 trace_fw_cfg_read' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:247:5: error: nested extern declaration of
 trace_fw_cfg_read' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_add_file':
 hw/fw_cfg.c:460:13: error: implicit declaration of function
 trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:460:13: error: nested extern declaration of
 trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
 hw/fw_cfg.c:467:5: error: implicit declaration of function
 trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:467:5: error: nested extern declaration of
 trace_fw_cfg_add_file' [-Werror=nested-externs]
 cc1: all warnings being treated as errors
 make: *** [hw/fw_cfg.o] Error 1
 
 Compiles fine for me.
 
 What happens if you blow away your build tree and start over?
 
 In my experience, rebuilding of trace-related stuff is rather fragile...

If I make a fresh clone of the qmu git repository it works.

Peter




[Qemu-devel] [A cry for sanity]: make_device_config.sh: Fix target path in generated dependency file

2013-01-24 Thread Michael Tokarev

Guys, it isn't sane anymore.  It if FAR from being funny.

Ping^7.. if i counted correctly...

03.12.2012 23:31, mdroth wrote:

On Sat, Oct 27, 2012 at 12:32:28PM +0400, Michael Tokarev wrote:

Ping?


Ping.

Fix still applicable for 1.3, also looking to pull it in for 1.2.2.



/mjt

On 18.09.2012 18:32, Andreas Färber wrote:

Am 18.09.2012 14:29, schrieb Michael Tokarev:

Has it been applied to anything?  I don't think so.
Is it still needed?


Not in qemu.git yet, still applicable AFAICT. CC'ing Paolo.

/-F



Thanks,

/mjt

On 07.06.2012 20:23, Andreas Färber wrote:

config-devices.mak.d is included from Makefile.target, i.e. from inside
the *-softmmu/ directory. It included the directory path, so never
applied to the actual config-devices.mak. Symptoms were spurious
dependency issues with default-configs/pci.mak.

Fix by using `basename` to strip the directory path.

Reported-by: Gerhard Wiesinger li...@wiesinger.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
  Seems I forgot to send this out before 1.1...

  scripts/make_device_config.sh |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/make_device_config.sh b/scripts/make_device_config.sh
index 5d14885..0778fe2 100644
--- a/scripts/make_device_config.sh
+++ b/scripts/make_device_config.sh
@@ -25,4 +25,4 @@ done
  process_includes $src  $dest

  cat $src $all_includes | grep -v '^include'  $dest
-echo $1: $all_includes  $dep
+echo `basename $1`: $all_includes  $dep















Re: [Qemu-devel] [PATCH 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Peter Lieven

Am 24.01.2013 um 11:41 schrieb Andreas Färber afaer...@suse.de:

 Am 24.01.2013 11:32, schrieb Markus Armbruster:
 Peter Lieven p...@dlhnet.de writes:
 
 Latest git doesn't compile with this patch:
 
 hw/fw_cfg.c: In function 'fw_cfg_write':
 hw/fw_cfg.c:207:5: error: implicit declaration of function
 trace_fw_cfg_write' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:207:5: error: nested extern declaration of
 trace_fw_cfg_write' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_select':
 hw/fw_cfg.c:232:5: error: implicit declaration of function
 trace_fw_cfg_select' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:232:5: error: nested extern declaration of
 trace_fw_cfg_select' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_read':
 hw/fw_cfg.c:247:5: error: implicit declaration of function
 trace_fw_cfg_read' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:247:5: error: nested extern declaration of
 trace_fw_cfg_read' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_add_file':
 hw/fw_cfg.c:460:13: error: implicit declaration of function
 trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:460:13: error: nested extern declaration of
 trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
 hw/fw_cfg.c:467:5: error: implicit declaration of function
 trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:467:5: error: nested extern declaration of
 trace_fw_cfg_add_file' [-Werror=nested-externs]
 cc1: all warnings being treated as errors
 make: *** [hw/fw_cfg.o] Error 1
 
 Compiles fine for me.
 
 What happens if you blow away your build tree and start over?
 
 In my experience, rebuilding of trace-related stuff is rather fragile...
 
 There were some recent changes ... there's probably a stale trace.h and
 trace.c in the build directory.

removing trace.c and trace.h is not enough, but a fresh clone of the
repository works. are there any more such files?

Peter


 
 Would be nice if we could get the build system to automatically remove
 such known stale files...
 
 Andreas
 
 -- 
 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
 GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg




[Qemu-devel] [PATCH V11 1/4] add def_value_str and use it in qemu_opts_print

2013-01-24 Thread Dong Xu Wang
qemu_opts_print has no user now, so can re-write the function safely.

qemu_opts_print will be used while using qemu-img create, it will
produce the same output as previous code.

The behavior of this function has changed:

1. Print every possible option, whether a value has been set or not.
2. Option descriptors may provide a default value.
3. Print to stdout instead of stderr.

Previously the behavior was to print every option that has been set.
Options that have not been set would be skipped.

Signed-off-by: Dong Xu Wang wdon...@vnet.linux.ibm.com
---
v10-v11:
1)  print all values that have actually been assigned while accept-any
cases.

v7-v8:
1) print elements = accept any params while opts_accepts_any() ==
true.
2) since def_print_str is the default value if an option isn't set,
so rename it to def_value_str.

 include/qemu/option.h |  1 +
 util/qemu-option.c| 30 +-
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index ba197cd..394170a 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -96,6 +96,7 @@ typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
+const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
diff --git a/util/qemu-option.c b/util/qemu-option.c
index f532b76..1aed418 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -863,13 +863,33 @@ void qemu_opts_del(QemuOpts *opts)
 int qemu_opts_print(QemuOpts *opts, void *dummy)
 {
 QemuOpt *opt;
+QemuOptDesc *desc = opts-list-desc;
 
-fprintf(stderr, %s: %s:, opts-list-name,
-opts-id ? opts-id : noid);
-QTAILQ_FOREACH(opt, opts-head, next) {
-fprintf(stderr,  %s=\%s\, opt-name, opt-str);
+if (desc[0].name == NULL) {
+QTAILQ_FOREACH(opt, opts-head, next) {
+printf(%s=\%s\ , opt-name, opt-str);
+}
+return 0;
+}
+for (; desc  desc-name; desc++) {
+const char *value = desc-def_value_str;
+QemuOpt *opt;
+
+opt = qemu_opt_find(opts, desc-name);
+if (opt) {
+value = opt-str;
+}
+
+if (!value) {
+continue;
+}
+
+if (desc-type == QEMU_OPT_STRING) {
+printf(%s='%s' , desc-name, value);
+} else {
+printf(%s=%s , desc-name, value);
+}
 }
-fprintf(stderr, \n);
 return 0;
 }
 
-- 
1.7.11.7




Re: [Qemu-devel] [A cry for sanity]: make_device_config.sh: Fix target path in generated dependency file

2013-01-24 Thread Andreas Färber
Am 24.01.2013 11:18, schrieb Michael Tokarev:
 Guys, it isn't sane anymore.  It if FAR from being funny.
 
 Ping^7.. if i counted correctly...

Anthony asked me to resend this one but I haven't found it among all my
branches and repositories yet o:-) and had higher priorities. Further, I
have not encountered it recently - it was about additions to pci.mak
*sometimes* breaking the build due to bad ordering (back then: megasas).

However, I'm not aware of recent build system changes that would
obsolete this patch - Paolo is still CC.

Andreas

 
 03.12.2012 23:31, mdroth wrote:
 On Sat, Oct 27, 2012 at 12:32:28PM +0400, Michael Tokarev wrote:
 Ping?

 Ping.

 Fix still applicable for 1.3, also looking to pull it in for 1.2.2.


 /mjt

 On 18.09.2012 18:32, Andreas Färber wrote:
 Am 18.09.2012 14:29, schrieb Michael Tokarev:
 Has it been applied to anything?  I don't think so.
 Is it still needed?

 Not in qemu.git yet, still applicable AFAICT. CC'ing Paolo.

 /-F


 Thanks,

 /mjt

 On 07.06.2012 20:23, Andreas Färber wrote:
 config-devices.mak.d is included from Makefile.target, i.e. from
 inside
 the *-softmmu/ directory. It included the directory path, so never
 applied to the actual config-devices.mak. Symptoms were spurious
 dependency issues with default-configs/pci.mak.

 Fix by using `basename` to strip the directory path.

 Reported-by: Gerhard Wiesinger li...@wiesinger.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
   Seems I forgot to send this out before 1.1...

   scripts/make_device_config.sh |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/scripts/make_device_config.sh
 b/scripts/make_device_config.sh
 index 5d14885..0778fe2 100644
 --- a/scripts/make_device_config.sh
 +++ b/scripts/make_device_config.sh
 @@ -25,4 +25,4 @@ done
   process_includes $src  $dest

   cat $src $all_includes | grep -v '^include'  $dest
 -echo $1: $all_includes  $dep
 +echo `basename $1`: $all_includes  $dep






 


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



[Qemu-devel] [PATCH 0/6] bdrv_open() error return fixes

2013-01-24 Thread Kevin Wolf
Kevin Wolf (6):
  bochs: Fix bdrv_open() error handling
  cloop: Fix bdrv_open() error handling
  vpc: Fix bdrv_open() error handling
  dmg: Fix bdrv_open() error handling
  dmg: Use g_free instead of free
  parallels: Fix bdrv_open() error handling

 block/bochs.c |   22 +--
 block/cloop.c |   27 ++---
 block/dmg.c   |  158 ++--
 block/parallels.c |   23 +---
 block/vpc.c   |   36 
 5 files changed, 187 insertions(+), 79 deletions(-)

-- 
1.7.6.5




[Qemu-devel] [PATCH 1/6] bochs: Fix bdrv_open() error handling

2013-01-24 Thread Kevin Wolf
Return -errno instead of -1 on errors. While touching the
code, fix a memory leak.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/bochs.c |   22 +++---
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/block/bochs.c b/block/bochs.c
index 3737583..a6eb33d 100644
--- a/block/bochs.c
+++ b/block/bochs.c
@@ -114,11 +114,13 @@ static int bochs_open(BlockDriverState *bs, int flags)
 int i;
 struct bochs_header bochs;
 struct bochs_header_v1 header_v1;
+int ret;
 
 bs-read_only = 1; // no write support yet
 
-if (bdrv_pread(bs-file, 0, bochs, sizeof(bochs)) != sizeof(bochs)) {
-goto fail;
+ret = bdrv_pread(bs-file, 0, bochs, sizeof(bochs));
+if (ret  0) {
+return ret;
 }
 
 if (strcmp(bochs.magic, HEADER_MAGIC) ||
@@ -138,9 +140,13 @@ static int bochs_open(BlockDriverState *bs, int flags)
 
 s-catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
 s-catalog_bitmap = g_malloc(s-catalog_size * 4);
-if (bdrv_pread(bs-file, le32_to_cpu(bochs.header), s-catalog_bitmap,
-   s-catalog_size * 4) != s-catalog_size * 4)
-   goto fail;
+
+ret = bdrv_pread(bs-file, le32_to_cpu(bochs.header), s-catalog_bitmap,
+ s-catalog_size * 4);
+if (ret  0) {
+goto fail;
+}
+
 for (i = 0; i  s-catalog_size; i++)
le32_to_cpus(s-catalog_bitmap[i]);
 
@@ -153,8 +159,10 @@ static int bochs_open(BlockDriverState *bs, int flags)
 
 qemu_co_mutex_init(s-lock);
 return 0;
- fail:
-return -1;
+
+fail:
+g_free(s-catalog_bitmap);
+return ret;
 }
 
 static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
-- 
1.7.6.5




[Qemu-devel] [PATCH 3/6] vpc: Fix bdrv_open() error handling

2013-01-24 Thread Kevin Wolf
Return -errno instead of -1 on errors. While touching the
code, fix a memory leak.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/vpc.c |   36 +---
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 7948609..9d2b177 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -163,24 +163,29 @@ static int vpc_open(BlockDriverState *bs, int flags)
 struct vhd_dyndisk_header* dyndisk_header;
 uint8_t buf[HEADER_SIZE];
 uint32_t checksum;
-int err = -1;
 int disk_type = VHD_DYNAMIC;
+int ret;
 
-if (bdrv_pread(bs-file, 0, s-footer_buf, HEADER_SIZE) != HEADER_SIZE)
+ret = bdrv_pread(bs-file, 0, s-footer_buf, HEADER_SIZE);
+if (ret  0 ) {
 goto fail;
+}
 
 footer = (struct vhd_footer*) s-footer_buf;
 if (strncmp(footer-creator, conectix, 8)) {
 int64_t offset = bdrv_getlength(bs-file);
 if (offset  HEADER_SIZE) {
+ret = offset;
 goto fail;
 }
 /* If a fixed disk, the footer is found only at the end of the file */
-if (bdrv_pread(bs-file, offset-HEADER_SIZE, s-footer_buf, 
HEADER_SIZE)
-!= HEADER_SIZE) {
+ret = bdrv_pread(bs-file, offset-HEADER_SIZE, s-footer_buf,
+ HEADER_SIZE);
+if (ret  0) {
 goto fail;
 }
 if (strncmp(footer-creator, conectix, 8)) {
+ret = -EMEDIUMTYPE;
 goto fail;
 }
 disk_type = VHD_FIXED;
@@ -203,19 +208,21 @@ static int vpc_open(BlockDriverState *bs, int flags)
 
 /* Allow a maximum disk size of approximately 2 TB */
 if (bs-total_sectors = 65535LL * 255 * 255) {
-err = -EFBIG;
+ret = -EFBIG;
 goto fail;
 }
 
 if (disk_type == VHD_DYNAMIC) {
-if (bdrv_pread(bs-file, be64_to_cpu(footer-data_offset), buf,
-HEADER_SIZE) != HEADER_SIZE) {
+ret = bdrv_pread(bs-file, be64_to_cpu(footer-data_offset), buf,
+ HEADER_SIZE);
+if (ret  0) {
 goto fail;
 }
 
 dyndisk_header = (struct vhd_dyndisk_header *) buf;
 
 if (strncmp(dyndisk_header-magic, cxsparse, 8)) {
+ret = -EINVAL;
 goto fail;
 }
 
@@ -226,8 +233,10 @@ static int vpc_open(BlockDriverState *bs, int flags)
 s-pagetable = g_malloc(s-max_table_entries * 4);
 
 s-bat_offset = be64_to_cpu(dyndisk_header-table_offset);
-if (bdrv_pread(bs-file, s-bat_offset, s-pagetable,
-s-max_table_entries * 4) != s-max_table_entries * 4) {
+
+ret = bdrv_pread(bs-file, s-bat_offset, s-pagetable,
+ s-max_table_entries * 4);
+if (ret  0) {
 goto fail;
 }
 
@@ -265,8 +274,13 @@ static int vpc_open(BlockDriverState *bs, int flags)
 migrate_add_blocker(s-migration_blocker);
 
 return 0;
- fail:
-return err;
+
+fail:
+g_free(s-pagetable);
+#ifdef CACHE
+g_free(s-pageentry_u8);
+#endif
+return ret;
 }
 
 static int vpc_reopen_prepare(BDRVReopenState *state,
-- 
1.7.6.5




[Qemu-devel] [PATCH 2/6] cloop: Fix bdrv_open() error handling

2013-01-24 Thread Kevin Wolf
Return -errno instead of -1 on errors. While touching the
code, fix a memory leak.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/cloop.c |   27 +--
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/block/cloop.c b/block/cloop.c
index 5a0d0d8..9b36063 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -57,27 +57,32 @@ static int cloop_open(BlockDriverState *bs, int flags)
 {
 BDRVCloopState *s = bs-opaque;
 uint32_t offsets_size, max_compressed_block_size = 1, i;
+int ret;
 
 bs-read_only = 1;
 
 /* read header */
-if (bdrv_pread(bs-file, 128, s-block_size, 4)  4) {
-goto cloop_close;
+ret = bdrv_pread(bs-file, 128, s-block_size, 4);
+if (ret  0) {
+return ret;
 }
 s-block_size = be32_to_cpu(s-block_size);
 
-if (bdrv_pread(bs-file, 128 + 4, s-n_blocks, 4)  4) {
-goto cloop_close;
+ret = bdrv_pread(bs-file, 128 + 4, s-n_blocks, 4);
+if (ret  0) {
+return ret;
 }
 s-n_blocks = be32_to_cpu(s-n_blocks);
 
 /* read offsets */
 offsets_size = s-n_blocks * sizeof(uint64_t);
 s-offsets = g_malloc(offsets_size);
-if (bdrv_pread(bs-file, 128 + 4 + 4, s-offsets, offsets_size) 
-offsets_size) {
-goto cloop_close;
+
+ret = bdrv_pread(bs-file, 128 + 4 + 4, s-offsets, offsets_size);
+if (ret  0) {
+goto fail;
 }
+
 for(i=0;is-n_blocks;i++) {
 s-offsets[i] = be64_to_cpu(s-offsets[i]);
 if (i  0) {
@@ -92,7 +97,8 @@ static int cloop_open(BlockDriverState *bs, int flags)
 s-compressed_block = g_malloc(max_compressed_block_size + 1);
 s-uncompressed_block = g_malloc(s-block_size);
 if (inflateInit(s-zstream) != Z_OK) {
-goto cloop_close;
+ret = -EINVAL;
+goto fail;
 }
 s-current_block = s-n_blocks;
 
@@ -101,8 +107,9 @@ static int cloop_open(BlockDriverState *bs, int flags)
 qemu_co_mutex_init(s-lock);
 return 0;
 
-cloop_close:
-return -1;
+fail:
+g_free(s-offsets);
+return ret;
 }
 
 static inline int cloop_read_block(BlockDriverState *bs, int block_num)
-- 
1.7.6.5




[Qemu-devel] [PATCH 5/6] dmg: Use g_free instead of free

2013-01-24 Thread Kevin Wolf
The buffers are allocated with g_(re)alloc, so use g_free to free them.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/dmg.c |   16 +---
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/block/dmg.c b/block/dmg.c
index d47d2d8..316d3c0 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -366,15 +366,17 @@ static coroutine_fn int dmg_co_read(BlockDriverState *bs, 
int64_t sector_num,
 static void dmg_close(BlockDriverState *bs)
 {
 BDRVDMGState *s = bs-opaque;
+
 if(s-n_chunks0) {
-   free(s-types);
-   free(s-offsets);
-   free(s-lengths);
-   free(s-sectors);
-   free(s-sectorcounts);
+g_free(s-types);
+g_free(s-offsets);
+g_free(s-lengths);
+g_free(s-sectors);
+g_free(s-sectorcounts);
 }
-free(s-compressed_chunk);
-free(s-uncompressed_chunk);
+g_free(s-compressed_chunk);
+g_free(s-uncompressed_chunk);
+
 inflateEnd(s-zstream);
 }
 
-- 
1.7.6.5




Re: [Qemu-devel] [PATCH 1/2] fw_cfg: Splash image loader can overrun a stack variable, fix

2013-01-24 Thread Laszlo Ersek
On 01/23/13 18:25, Markus Armbruster wrote:
 read_splashfile() passes the address of an int variable as size_t *
 parameter to g_file_get_contents(), with a cast to gag the compiler.
 
 No problem on machines where sizeof(size_t) == sizeof(int).
 
 Happens to work on my x86_64 box (64 bit little endian): the least
 significant 32 bits of the file size end up in the right place
 (caller's variable file_size), and the most significant 32 bits
 clobber a place that gets assigned to before its next use (caller's
 variable file_type).
 
 I'd expect it to break on a 64 bit big-endian box.
 
 Fix up the variable types and drop the problematic cast.
 

Ultimately fw_cfg_add_file() and fw_cfg_add_bytes() (reasonably) convert
(truncate) the size to uint32_t, but that's completely orthogonal.

Reviewed-by: Laszlo Ersek ler...@redhat.com



[Qemu-devel] [PATCH] vmware_vga: fix out of bounds and invalid rects updating

2013-01-24 Thread Michael Tokarev
This is a follow up for several attempts to fix this issue.

Previous incarnations:

1. http://thread.gmane.org/gmane.linux.ubuntu.bugs.general/3156089
https://bugs.launchpad.net/bugs/918791
qemu-kvm dies when using vmvga driver and unity in the guest bug.
Fix by Serge Hallyn:
 https://launchpadlibrarian.net/94916786/qemu-vmware.debdiff
This fix is incomplete, since it does not check width and height
for being negative.  Serge weren't sure if that's the right place
to fix it, maybe the fix should be up the stack somewhere.

2. http://thread.gmane.org/gmane.comp.emulators.qemu/166064
by Marek Vasut: vmware_vga: Redraw only visible area

This one adds the (incomplete) check to vmsvga_update_rect_delayed(),
the routine just queues the rect updating but does no interesting
stuff.  It is also incomplete in the same way as patch by Serge,
but also does not touch widthheight at all after adjusting xy,
which is wrong.

As far as I can see, when processing guest requests, the device
places them into a queue (vmsvga_update_rect_delayed()) and
processes this queue in different place/time, namely, in
vmsvga_update_rect().  Sometimes, vmsvga_update_rect() is
called directly, without placing the request to the gueue.
This is the place this patch changes, which is the last
(deepest) in the stack.  I'm not sure if this is the right
place still, since it is possible we have some queue optimization
(or may have in the future) which will be upset by negative/wrong
values here, so maybe we should check for validity of input
right when receiving request from the guest (and maybe even
use unsigned types there).  But I don't know the protocol
and implementation enough to have a definitive answer.

But since vmsvga_update_rect() has other sanity checks already,
I'm adding the missing ones there as well.

Cc'ing BALATON Zoltan and Andrzej Zaborowski who shows in `git blame'
output and may know something in this area.

If this patch is accepted, it should be applied to all active
stable branches (at least since 1.1, maybe even before), with
minor context change (ds_get_*(s-vga.ds) = s-*).  I'm not
Cc'ing -stable yet, will do it explicitly once the patch is
accepted.

BTW, these checks use fprintf(stderr) -- it should be converted
to something more appropriate, since stderr will most likely
disappear somewhere.

Cc: Marek Vasut ma...@denx.de
Cc: Serge Hallyn serge.hal...@ubuntu.com
Cc: BALATON Zoltan bala...@eik.bme.hu
Cc: Andrzej Zaborowski balr...@gmail.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 hw/vmware_vga.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 62771bb..c8a95c2 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -296,6 +296,15 @@ static inline void vmsvga_update_rect(struct 
vmsvga_state_s *s,
 uint8_t *src;
 uint8_t *dst;
 
+if (x  0) {
+fprintf(stderr, %s: update x was  0 (%d)\n, __FUNCTION__, x);
+w += x;
+x = 0;
+}
+if (w  0) {
+fprintf(stderr, %s: update w was  0 (%d)\n, __FUNCTION__, w);
+w = 0;
+}
 if (x + w  ds_get_width(s-vga.ds)) {
 fprintf(stderr, %s: update width too large x: %d, w: %d\n,
 __func__, x, w);
@@ -303,6 +312,15 @@ static inline void vmsvga_update_rect(struct 
vmsvga_state_s *s,
 w = ds_get_width(s-vga.ds) - x;
 }
 
+if (y  0) {
+fprintf(stderr, %s: update y was  0 (%d)\n,  __FUNCTION__, y);
+h += y;
+y = 0;
+}
+if (h  0) {
+fprintf(stderr, %s: update h was  0 (%d)\n,  __FUNCTION__, h);
+h = 0;
+}
 if (y + h  ds_get_height(s-vga.ds)) {
 fprintf(stderr, %s: update height too large y: %d, h: %d\n,
 __func__, y, h);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 2/2] fw_cfg: Drop a few superfluous initializers

2013-01-24 Thread Laszlo Ersek
On 01/23/13 18:25, Markus Armbruster wrote:
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/fw_cfg.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
 index b7da5c7..bdcd836 100644
 --- a/hw/fw_cfg.c
 +++ b/hw/fw_cfg.c
 @@ -60,8 +60,8 @@ static char *read_splashfile(char *filename, size_t 
 *file_sizep,
  GError *err = NULL;
  gboolean res;
  gchar *content;
 -int file_type = -1;
 -unsigned int filehead = 0;
 +int file_type;
 +unsigned int filehead;
  int bmp_bpp;
  
  res = g_file_get_contents(filename, content, file_sizep, err);
 @@ -113,7 +113,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
  char *p;
  char *filename, *file_data;
  size_t file_size;
 -int file_type = -1;
 +int file_type;
  const char *temp;
  
  /* get user configuration */

Reviewed-by: Laszlo Ersek ler...@redhat.com



Re: [Qemu-devel] [PATCH] gdbstub: Do not kill target in system emulation mode

2013-01-24 Thread Fabien Chouteau
On 01/23/2013 07:44 PM, Jan Kiszka wrote:
 
 PS: If you are looking for kill in the meantime: monitor quit
 

I didn't know we can use monitor from Gdb, thanks for the info.

-- 
Fabien Chouteau



Re: [Qemu-devel] [PATCH] arm: vexpress: Clear sysctl cfgctrl start bit

2013-01-24 Thread Peter Maydell
On 23 December 2012 16:34, Christoffer Dall
c.d...@virtualopensystems.com wrote:
 On Sun, Dec 23, 2012 at 6:01 AM, Peter Maydell peter.mayd...@linaro.org 
 wrote:
 On 22 December 2012 19:03, Christoffer Dall
 c.d...@virtualopensystems.com wrote:
 The start bit should only be set to indicate that a function call is
 underway, right now.  When done with function, clear it.

 Looks plausible but I'd like a crosscheck that this is how the hardware
 really behaves.

 sure, on my vexpress box that's certainly the case by experimentation though.

OK, if you've compared with hardware I'm happy.

Reviewed-by: Peter Maydell peter.mayd...@linaro.org

-- PMM



Re: [Qemu-devel] [PATCH] gdbstub: Do not kill target in system emulation mode

2013-01-24 Thread Fabien Chouteau
On 01/24/2013 03:02 AM, Joel Brobecker wrote:
 qAttached is not supported in Qemu yet, this explains why Gdb sends
 kill at the end of debug session. I will implement it and revert your
 patch. Gdb will automatically detach instead of kill at the end of
 debugging session.
 
 I would make it configurable by the command-line, to allow for both
 behaviors. In my situations, the behavior I would prefer is a kill.
 

OK, well noted.

Thanks Joel,

-- 
Fabien Chouteau



[Qemu-devel] [PATCH] s390: Add default support for SCLP console

2013-01-24 Thread Alexander Graf
The current s390 machine uses the virtio console as default console,
but this doesn't mean that we always want to keep it that way for new
machines.

This patch introduces a way for a machine type to specify that it wants
the default console to be an SCLP console, which is a lot closer to what
real hardware does.

Signed-off-by: Alexander Graf ag...@suse.de
---
 hw/boards.h |1 +
 vl.c|   48 
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/hw/boards.h b/hw/boards.h
index 3ff9665..3813d4e 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -33,6 +33,7 @@ typedef struct QEMUMachine {
 unsigned int no_serial:1,
 no_parallel:1,
 use_virtcon:1,
+use_sclp:1,
 no_floppy:1,
 no_cdrom:1,
 no_sdcard:1;
diff --git a/vl.c b/vl.c
index 4ee1302..6a19a8f 100644
--- a/vl.c
+++ b/vl.c
@@ -176,6 +176,7 @@ int main(int argc, char **argv)
 #define DEFAULT_RAM_SIZE 128
 
 #define MAX_VIRTIO_CONSOLES 1
+#define MAX_SCLP_CONSOLES 1
 
 static const char *data_dir;
 const char *bios_name = NULL;
@@ -203,6 +204,7 @@ int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
+CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
@@ -271,6 +273,7 @@ static int tcg_tb_size;
 static int default_serial = 1;
 static int default_parallel = 1;
 static int default_virtcon = 1;
+static int default_sclp = 1;
 static int default_monitor = 1;
 static int default_floppy = 1;
 static int default_cdrom = 1;
@@ -2340,6 +2343,7 @@ struct device_config {
 DEV_VIRTCON,   /* -virtioconsole */
 DEV_DEBUGCON,  /* -debugcon */
 DEV_GDB,   /* -gdb, -s */
+DEV_SCLP,  /* s390 sclp */
 } type;
 const char *cmdline;
 Location loc;
@@ -2458,6 +2462,39 @@ static int virtcon_parse(const char *devname)
 return 0;
 }
 
+static int sclp_parse(const char *devname)
+{
+QemuOptsList *device = qemu_find_opts(device);
+static int index = 0;
+char label[32];
+QemuOpts *dev_opts;
+
+if (strcmp(devname, none) == 0) {
+return 0;
+}
+if (index == MAX_SCLP_CONSOLES) {
+fprintf(stderr, qemu: too many sclp consoles\n);
+exit(1);
+}
+
+assert(arch_type == QEMU_ARCH_S390X);
+
+dev_opts = qemu_opts_create(device, NULL, 0, NULL);
+qemu_opt_set(dev_opts, driver, sclpconsole);
+
+snprintf(label, sizeof(label), sclpcon%d, index);
+sclp_hds[index] = qemu_chr_new(label, devname, NULL);
+if (!sclp_hds[index]) {
+fprintf(stderr, qemu: could not connect sclp console
+ to character backend '%s'\n, devname);
+return -1;
+}
+qemu_opt_set(dev_opts, chardev, label);
+
+index++;
+return 0;
+}
+
 static int debugcon_parse(const char *devname)
 {   
 QemuOpts *opts;
@@ -3832,6 +3869,9 @@ int main(int argc, char **argv, char **envp)
 if (!machine-use_virtcon) {
 default_virtcon = 0;
 }
+if (!machine-use_sclp) {
+default_sclp = 0;
+}
 if (machine-no_floppy) {
 default_floppy = 0;
 }
@@ -3873,11 +3913,15 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_SERIAL, mon:stdio);
 } else if (default_virtcon  default_monitor) {
 add_device_config(DEV_VIRTCON, mon:stdio);
+} else if (default_sclp  default_monitor) {
+add_device_config(DEV_SCLP, mon:stdio);
 } else {
 if (default_serial)
 add_device_config(DEV_SERIAL, stdio);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, stdio);
+if (default_sclp)
+add_device_config(DEV_SCLP, stdio);
 if (default_monitor)
 monitor_parse(stdio, readline);
 }
@@ -3890,6 +3934,8 @@ int main(int argc, char **argv, char **envp)
 monitor_parse(vc:80Cx24C, readline);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, vc:80Cx24C);
+if (default_sclp)
+add_device_config(DEV_SCLP, vc:80Cx24C);
 }
 
 socket_init();
@@ -4060,6 +4106,8 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 if (foreach_device_config(DEV_VIRTCON, virtcon_parse)  0)
 exit(1);
+if (foreach_device_config(DEV_SCLP, sclp_parse)  0)
+exit(1);
 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse)  0)
 exit(1);
 
-- 
1.6.0.2




Re: [Qemu-devel] [PATCH] gdbstub: Do not kill target in system emulation mode

2013-01-24 Thread Jan Kiszka
On 2013-01-24 12:19, Fabien Chouteau wrote:
 On 01/24/2013 03:02 AM, Joel Brobecker wrote:
 qAttached is not supported in Qemu yet, this explains why Gdb sends
 kill at the end of debug session. I will implement it and revert your
 patch. Gdb will automatically detach instead of kill at the end of
 debugging session.

 I would make it configurable by the command-line, to allow for both
 behaviors. In my situations, the behavior I would prefer is a kill.

 
 OK, well noted.

Not sure if that is really useful, but the default shall remain on
non-lethal.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux



[Qemu-devel] [PATCH 6/6] parallels: Fix bdrv_open() error handling

2013-01-24 Thread Kevin Wolf
Return -errno instead of -1 on errors. Hey, no memory leak to fix here
while we're touching it!

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/parallels.c |   23 +++
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index 3773750..8688f6c 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -73,14 +73,18 @@ static int parallels_open(BlockDriverState *bs, int flags)
 BDRVParallelsState *s = bs-opaque;
 int i;
 struct parallels_header ph;
+int ret;
 
 bs-read_only = 1; // no write support yet
 
-if (bdrv_pread(bs-file, 0, ph, sizeof(ph)) != sizeof(ph))
+ret = bdrv_pread(bs-file, 0, ph, sizeof(ph));
+if (ret  0) {
 goto fail;
+}
 
 if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
-   (le32_to_cpu(ph.version) != HEADER_VERSION)) {
+(le32_to_cpu(ph.version) != HEADER_VERSION)) {
+ret = -EMEDIUMTYPE;
 goto fail;
 }
 
@@ -90,18 +94,21 @@ static int parallels_open(BlockDriverState *bs, int flags)
 
 s-catalog_size = le32_to_cpu(ph.catalog_entries);
 s-catalog_bitmap = g_malloc(s-catalog_size * 4);
-if (bdrv_pread(bs-file, 64, s-catalog_bitmap, s-catalog_size * 4) !=
-   s-catalog_size * 4)
-   goto fail;
+
+ret = bdrv_pread(bs-file, 64, s-catalog_bitmap, s-catalog_size * 4);
+if (ret  0) {
+goto fail;
+}
+
 for (i = 0; i  s-catalog_size; i++)
le32_to_cpus(s-catalog_bitmap[i]);
 
 qemu_co_mutex_init(s-lock);
 return 0;
+
 fail:
-if (s-catalog_bitmap)
-   g_free(s-catalog_bitmap);
-return -1;
+g_free(s-catalog_bitmap);
+return ret;
 }
 
 static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
-- 
1.7.6.5




[Qemu-devel] [PATCH] ide: Add fall through annotations

2013-01-24 Thread Kevin Wolf
Add comments to help static analysers detect that these cases are
intentional, and clean up some whitespace in the environment of these
comments.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/ide/core.c |   33 +
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 14ad079..3743dc3 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1149,8 +1149,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 }
 ide_set_irq(s-bus);
 break;
+
 case WIN_VERIFY_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_VERIFY:
 case WIN_VERIFY_ONCE:
 /* do sector number check ? */
@@ -1158,8 +1160,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 s-status = READY_STAT | SEEK_STAT;
 ide_set_irq(s-bus);
 break;
+
 case WIN_READ_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_READ:
 case WIN_READ_ONCE:
 if (s-drive_kind == IDE_CD) {
@@ -1173,8 +1177,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 s-req_nb_sectors = 1;
 ide_sector_read(s);
 break;
+
 case WIN_WRITE_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_WRITE:
 case WIN_WRITE_ONCE:
 case CFA_WRITE_SECT_WO_ERASE:
@@ -1189,8 +1195,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 ide_transfer_start(s, s-io_buffer, 512, ide_sector_write);
 s-media_changed = 1;
 break;
+
 case WIN_MULTREAD_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_MULTREAD:
 if (!s-bs) {
 goto abort_cmd;
@@ -1202,8 +1210,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 s-req_nb_sectors = s-mult_sectors;
 ide_sector_read(s);
 break;
+
 case WIN_MULTWRITE_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_MULTWRITE:
 case CFA_WRITE_MULTI_WO_ERASE:
 if (!s-bs) {
@@ -1222,8 +1232,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 ide_transfer_start(s, s-io_buffer, 512 * n, ide_sector_write);
 s-media_changed = 1;
 break;
+
 case WIN_READDMA_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_READDMA:
 case WIN_READDMA_ONCE:
 if (!s-bs) {
@@ -1232,8 +1244,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
ide_cmd_lba48_transform(s, lba48);
 ide_sector_start_dma(s, IDE_DMA_READ);
 break;
+
 case WIN_WRITEDMA_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_WRITEDMA:
 case WIN_WRITEDMA_ONCE:
 if (!s-bs) {
@@ -1243,14 +1257,17 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 ide_sector_start_dma(s, IDE_DMA_WRITE);
 s-media_changed = 1;
 break;
+
 case WIN_READ_NATIVE_MAX_EXT:
-   lba48 = 1;
+lba48 = 1;
+/* fall through */
 case WIN_READ_NATIVE_MAX:
ide_cmd_lba48_transform(s, lba48);
 ide_set_sector(s, s-nb_sectors - 1);
 s-status = READY_STAT | SEEK_STAT;
 ide_set_irq(s-bus);
 break;
+
 case WIN_CHECKPOWERMODE1:
 case WIN_CHECKPOWERMODE2:
 s-error = 0;
-- 
1.7.6.5




[Qemu-devel] [PATCH 4/6] dmg: Fix bdrv_open() error handling

2013-01-24 Thread Kevin Wolf
Return -errno instead of -1 on errors. While touching the
code, fix even some more memory leaks than in the other drivers...

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/dmg.c |  136 --
 1 files changed, 103 insertions(+), 33 deletions(-)

diff --git a/block/dmg.c b/block/dmg.c
index ac397dc..d47d2d8 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -57,29 +57,53 @@ static int dmg_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 return 0;
 }
 
-static off_t read_off(BlockDriverState *bs, int64_t offset)
+static int read_uint64(BlockDriverState *bs, int64_t offset, uint64_t *result)
 {
-   uint64_t buffer;
-   if (bdrv_pread(bs-file, offset, buffer, 8)  8)
-   return 0;
-   return be64_to_cpu(buffer);
+uint64_t buffer;
+int ret;
+
+ret = bdrv_pread(bs-file, offset, buffer, 8);
+if (ret  0) {
+return ret;
+}
+
+*result = be64_to_cpu(buffer);
+return 0;
 }
 
-static off_t read_uint32(BlockDriverState *bs, int64_t offset)
+static int read_off(BlockDriverState *bs, int64_t offset, off_t *result)
+{
+uint64_t buffer;
+int ret;
+
+ret = read_uint64(bs, offset, buffer);
+*result = buffer;
+
+return ret;
+}
+
+static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result)
 {
uint32_t buffer;
-   if (bdrv_pread(bs-file, offset, buffer, 4)  4)
-   return 0;
-   return be32_to_cpu(buffer);
+int ret;
+
+ret = bdrv_pread(bs-file, offset, buffer, 4);
+if (ret  0) {
+return ret;
+}
+
+*result = be32_to_cpu(buffer);
+return 0;
 }
 
 static int dmg_open(BlockDriverState *bs, int flags)
 {
 BDRVDMGState *s = bs-opaque;
 off_t info_begin,info_end,last_in_offset,last_out_offset;
-uint32_t count;
+uint32_t count, tmp;
 uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
 int64_t offset;
+int ret;
 
 bs-read_only = 1;
 s-n_chunks = 0;
@@ -88,21 +112,32 @@ static int dmg_open(BlockDriverState *bs, int flags)
 /* read offset of info blocks */
 offset = bdrv_getlength(bs-file);
 if (offset  0) {
+ret = offset;
 goto fail;
 }
 offset -= 0x1d8;
 
-info_begin = read_off(bs, offset);
-if (info_begin == 0) {
-   goto fail;
+ret = read_off(bs, offset, info_begin);
+if (ret  0) {
+goto fail;
+} else if (info_begin == 0) {
+ret = -EINVAL;
+goto fail;
 }
 
-if (read_uint32(bs, info_begin) != 0x100) {
+ret = read_uint32(bs, info_begin, tmp);
+if (ret  0) {
+goto fail;
+} else if (tmp != 0x100) {
+ret = -EINVAL;
 goto fail;
 }
 
-count = read_uint32(bs, info_begin + 4);
-if (count == 0) {
+ret = read_uint32(bs, info_begin + 4, count);
+if (ret  0) {
+goto fail;
+} else if (count == 0) {
+ret = -EINVAL;
 goto fail;
 }
 info_end = info_begin + count;
@@ -114,12 +149,20 @@ static int dmg_open(BlockDriverState *bs, int flags)
 while (offset  info_end) {
 uint32_t type;
 
-   count = read_uint32(bs, offset);
-   if(count==0)
-   goto fail;
+ret = read_uint32(bs, offset, count);
+if (ret  0) {
+goto fail;
+} else if (count == 0) {
+ret = -EINVAL;
+goto fail;
+}
 offset += 4;
 
-   type = read_uint32(bs, offset);
+ret = read_uint32(bs, offset, type);
+if (ret  0) {
+goto fail;
+}
+
if (type == 0x6d697368  count = 244) {
int new_size, chunk_count;
 
@@ -134,8 +177,11 @@ static int dmg_open(BlockDriverState *bs, int flags)
s-sectors = g_realloc(s-sectors, new_size);
s-sectorcounts = g_realloc(s-sectorcounts, new_size);
 
-   for(i=s-n_chunks;is-n_chunks+chunk_count;i++) {
-   s-types[i] = read_uint32(bs, offset);
+for(i=s-n_chunks;is-n_chunks+chunk_count;i++) {
+ret = read_uint32(bs, offset, s-types[i]);
+if (ret  0) {
+goto fail;
+}
offset += 4;
if(s-types[i]!=0x8005  s-types[i]!=1  s-types[i]!=2) 
{
if(s-types[i]==0x) {
@@ -149,17 +195,31 @@ static int dmg_open(BlockDriverState *bs, int flags)
}
offset += 4;
 
-   s-sectors[i] = last_out_offset+read_off(bs, offset);
-   offset += 8;
-
-   s-sectorcounts[i] = read_off(bs, offset);
-   offset += 8;
-
-   s-offsets[i] = last_in_offset+read_off(bs, offset);
-   offset += 8;
-
-   s-lengths[i] = read_off(bs, offset);
-   offset += 8;
+ret = read_uint64(bs, offset, s-sectors[i]);
+if (ret  0) {
+goto fail;
+}
+   

Re: [Qemu-devel] [PATCH 0/7 v2] KVM regsync

2013-01-24 Thread Alexander Graf

On 10.01.2013, at 16:28, Jason J. Herne wrote:

 Rework the method used to synchronize CPU registers between Qemu 
 KVM.  This patch set extends kvm_arch_put_registers() and
 kvm_arch_get_registers() to take a register bitmap parameter.  All
 existing code paths are updated to specify this new parameter.
 
 IMPORTANT NOTE:  The PPC and i386 implementations are incomplete.
 I am submitting this code at this time only to get a review on the
 implementation of the existing code and to perhaps seek assistance
 with the mentioned architectures.
 
 I am not sure who will finish the implementation of PPC/i386 yet.  Due
 to the fact that I am unfamiliar with these architectures at the
 register level and I do not have test environments I would like to
 humbly request that a maintainer of these architectures take a look at
 it.  Or perhaps Bharat could handle the PPC code?  This would only leave i386 
 to worry about.  If I cannot find someone to handle i386 I
 will look into the feasibility of completing it myself.
 
 In order to complete the missing implementations,
 kvm_arch_get_registers and kvm_arch_put_registers (and associated
 helper functions) will need to be updated to only sync the registers
 contained in the new bitmap argument.  

I disagree. The read functions would stay the way they are, because they always 
read everything today. The write functions would read bitmap bits instead of 
level  x. The bitmap would contain bits for

  LEVEL_1
  LEVEL_2
  LEVEL_3

with the externally used LEVEL_3 define that you would use for syncing being 
(LEVEL_1 | LEVEL_2 | LEVEL_3).

That way you keep the level based semantic and nobody really needs non-obvious 
code changes.

 Also, each set of registers
 represented  by one of the bits must be mutually exclusive with respect
 to every other bit.  if this is not the case then local register data
 can be lost when kvm_arch_get_registers is called causing an old
 register value to overwrite a newer local value.

Any get_registers call with a changing bitmap would flush out everything and 
start from scratch. Don't overoptimize from the beginning :).


Alex




Re: [Qemu-devel] [PATCH 2/7 v2] KVM regsync: Add register bitmap parameter to kvm_arch_[get|put]_registers

2013-01-24 Thread Alexander Graf

On 10.01.2013, at 16:28, Jason J. Herne wrote:

 From: Jason J. Herne jjhe...@us.ibm.com
 
 Modify kvm_arch_get_registers anf kvm_arch_put_registers interfaces such
 that they accept a register bitmap parameter.  Also modify the only caller of
 kvm_arch_get_registers such that it passes an appropriate bitmap.  The idea 
 here
 is that, for all currently existing calls we want to do nothing different.
 
 Signed-off-by: Jason J. Herne jjhe...@us.ibm.com
 Reviewed-by: Christian Borntraeger borntrae...@de.ibm.com
 ---
 include/sysemu/kvm.h |   11 ++-
 kvm-all.c|2 +-
 target-i386/cpu.h|   15 +++
 target-ppc/cpu.h |   15 +++
 target-s390x/cpu.h   |   15 +++
 target-s390x/kvm.c   |2 +-
 6 files changed, 49 insertions(+), 11 deletions(-)
 
 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index 6756e16..e0738ba 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -165,16 +165,9 @@ int kvm_arch_handle_exit(CPUState *cpu, struct kvm_run 
 *run);
 
 int kvm_arch_process_async_events(CPUState *cpu);
 
 -int kvm_arch_get_registers(CPUState *cpu);
 +int kvm_arch_get_registers(CPUState *cpu, int regmap);
 
 -/* state subset only touched by the VCPU itself during runtime */
 -#define KVM_REGSYNC_RUNTIME_STATE   1
 -/* state subset modified during VCPU reset */
 -#define KVM_REGSYNC_RESET_STATE 2
 -/* full state set, modified during initialization or on vmload */
 -#define KVM_REGSYNC_FULL_STATE  3
 -
 -int kvm_arch_put_registers(CPUState *cpu, int level);
 +int kvm_arch_put_registers(CPUState *cpu, int regmap);
 
 int kvm_arch_init(KVMState *s);
 
 diff --git a/kvm-all.c b/kvm-all.c
 index aa58b74..1aa61bb 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -1494,7 +1494,7 @@ static void do_kvm_cpu_synchronize_state(void *arg)
 CPUState *cpu = arg;
 
 if (!cpu-kvm_vcpu_dirty) {
 -kvm_arch_get_registers(cpu);
 +kvm_arch_get_registers(cpu, KVM_REGSYNC_FULL_STATE);
 cpu-kvm_vcpu_dirty = true;
 }
 }
 diff --git a/target-i386/cpu.h b/target-i386/cpu.h
 index e56921b..64d9f05 100644
 --- a/target-i386/cpu.h
 +++ b/target-i386/cpu.h
 @@ -1223,4 +1223,19 @@ void enable_kvm_pv_eoi(void);
 /* Return name of 32-bit register, from a R_* constant */
 const char *get_register_name_32(unsigned int reg);
 
 +/* Architecture specific register synchronization constants */
 +#define KVM_REGSYNC_I386_RUNTIME_REGS 0x01
 +#define KVM_REGSYNC_I386_RESET_REGS 0x02
 +#define KVM_REGSYNC_I386_FULL_REGS 0x04

These should be defined as (1  x). How about s/REGS/BIT/ here too, to 
indicate what the defines are really about?

 +
 +/* General register sets made up of architeture specific registers*/
 +/* state subset only touched by the VCPU itself during runtime */
 +#define KVM_REGSYNC_RUNTIME_STATE   KVM_REGSYNC_I386_RUNTIME_REGS
 +/* state subset modified during VCPU reset */
 +#define KVM_REGSYNC_RESET_STATE (KVM_REGSYNC_RUNTIME_STATE| \
 +KVM_REGSYNC_I386_RESET_REGS)
 +/* full state set, modified during initialization or on vmload */
 +#define KVM_REGSYNC_FULL_STATE  (KVM_REGSYNC_RESET_STATE| \
 +KVM_REGSYNC_I386_FULL_REGS)

Good :)

Since higher state is still a higher number than lower state, all checks in 
arch-specific code keep working too. Nice :)


Alex




Re: [Qemu-devel] [PATCH for-1.4 qom-cpu 8/9 v6] target-i386: Topology APIC ID utility functions

2013-01-24 Thread Eduardo Habkost
On Wed, Jan 23, 2013 at 08:49:58PM +0100, Andreas Färber wrote:
 Am 23.01.2013 18:58, schrieb Eduardo Habkost:
  This introduces utility functions for the APIC ID calculation, based on:
Intel® 64 Architecture Processor Topology Enumeration

  http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/
  
  The code should be also compatible with AMD's Extended Method described 
  at:
AMD CPUID Specification (Publication #25481)
Section 3: Multiple Core Calcuation
  as long as:
   - nr_threads is set to 1;
   - OFFSET_IDX is assumed to be 0;
   - CPUID Fn8000_0008_ECX[ApicIdCoreIdSize[3:0]] is set to 
  apicid_core_width().
  
  Unit tests included. The code is still not being used anywhere. It will be 
  used
  by the the next patch.
 
 (I would drop this reference to next patch when applying.)
  
  Signed-off-by: Eduardo Habkost ehabk...@redhat.com
 [...]
  diff --git a/tests/Makefile b/tests/Makefile
  index d86e95a..4b98d4f 100644
  --- a/tests/Makefile
  +++ b/tests/Makefile
  @@ -45,6 +45,10 @@ gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c
   gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c
   check-unit-y += tests/test-thread-pool$(EXESUF)
   gcov-files-test-thread-pool-y = thread-pool.c
  +check-unit-y += tests/test-x86-cpuid$(EXESUF)
  +# all code tested by test-x86-cpuid is inside topology.h,
  +# so add the test file itself to the gcov list
  +gcov-files-test-x86-cpuid-y = tests/test-x86-cpuid.c
   
   check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
   
 
 With patch 7/9 dropped I am more comfortable with the test integration.
 
 I wonder however whether the gcov line is correct - won't this screw up
 the statistics so that it's better to drop that line and to add
 hw/pc_piix.c or target-i386/cpu.c in 9/9 instead? Blue?

I want to make gcov check for coverage only of topology.h (that's where the
tested code lives). Including test-x86-cpuid.c is the closest I could get to
that[1]. Including pc_piix.c or cpu.c would surely screw up the numbers, as the
tests don't cover any of the pc_piix.c or target-i386/cpu.c code.

[1] If I set gcov-files-test-x86-cpuid-y = target-i386/topology.h, I get:

  GTESTER tests/test-x86-cpuid
  Gcov report for target-i386/topology.h:
  target-i386/topology.gcno:cannot open graph file

It looks like the .gcno file generation is per-object-file, not per-source-file
(gcov-files-*-y being a list of .c files confused me). If that's the case, then
the only valid value for gcov-files-test-x86-cpuid-y is really
tests/test-x86-cpuid.c, because all the tested code is being compiled inside
tests/test-x86-cpuid.o.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 3/7 v2] KVM regsync: S390: Implement kvm_arch_[get/put]_registers regmap paramter

2013-01-24 Thread Alexander Graf

On 10.01.2013, at 16:28, Jason J. Herne wrote:

 From: Jason J. Herne jjhe...@us.ibm.com
 
 S390 re-implementation of kvm_arch_get_registers and kvm_arch_put_registers
 functions to take advantage of the register map parameter.
 
 Signed-off-by: Jason J. Herne jjhe...@us.ibm.com
 Reviewed-by: Christian Borntraeger borntrae...@de.ibm.com
 ---
 target-s390x/kvm.c |  165 ++--
 1 file changed, 84 insertions(+), 81 deletions(-)
 
 diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
 index 4b87f1c..ab6b27b 100644
 --- a/target-s390x/kvm.c
 +++ b/target-s390x/kvm.c
 @@ -88,7 +88,7 @@ void kvm_arch_reset_vcpu(CPUState *cpu)
 /* FIXME: add code to reset vcpu. */
 }
 
 -int kvm_arch_put_registers(CPUState *cs, int level)
 +int kvm_arch_put_registers(CPUState *cs, int regmap)
 {
 S390CPU *cpu = S390_CPU(cs);
 CPUS390XState *env = cpu-env;
 @@ -97,57 +97,56 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 int ret;
 int i;
 
 -/* always save the PSW  and the GPRS*/
 -cs-kvm_run-psw_addr = env-psw.addr;
 -cs-kvm_run-psw_mask = env-psw.mask;
 +if (regmap  KVM_REGSYNC_S390_RUNTIME_REGS) {
 +cs-kvm_run-psw_addr = env-psw.addr;
 +cs-kvm_run-psw_mask = env-psw.mask;
 
 -if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_GPRS) {
 -for (i = 0; i  16; i++) {
 -cs-kvm_run-s.regs.gprs[i] = env-regs[i];
 -cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_GPRS;
 -}
 -} else {
 -for (i = 0; i  16; i++) {
 -regs.gprs[i] = env-regs[i];
 -}
 -ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, regs);
 -if (ret  0) {
 -return ret;
 +if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_GPRS) {
 +for (i = 0; i  16; i++) {
 +cs-kvm_run-s.regs.gprs[i] = env-regs[i];
 +cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_GPRS;
 +}
 +} else {
 +for (i = 0; i  16; i++) {
 +regs.gprs[i] = env-regs[i];
 +}
 +ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, regs);
 +if (ret  0) {
 +return ret;
 +}
 }
 }
 
 -/* Do we need to save more than that? */
 -if (level == KVM_REGSYNC_RUNTIME_STATE) {
 -return 0;
 -}
 -
 -if (cap_sync_regs 
 -cs-kvm_run-kvm_valid_regs  KVM_SYNC_ACRS 
 -cs-kvm_run-kvm_valid_regs  KVM_SYNC_CRS) {
 -for (i = 0; i  16; i++) {
 -cs-kvm_run-s.regs.acrs[i] = env-aregs[i];
 -cs-kvm_run-s.regs.crs[i] = env-cregs[i];
 -}
 -cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_ACRS;
 -cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_CRS;
 -} else {
 -for (i = 0; i  16; i++) {
 -sregs.acrs[i] = env-aregs[i];
 -sregs.crs[i] = env-cregs[i];
 +if (regmap  KVM_REGSYNC_S390_RESET_REGS) {
 +if (cap_sync_regs 
 +cs-kvm_run-kvm_valid_regs  KVM_SYNC_ACRS 
 +cs-kvm_run-kvm_valid_regs  KVM_SYNC_CRS) {
 +for (i = 0; i  16; i++) {
 +cs-kvm_run-s.regs.acrs[i] = env-aregs[i];
 +cs-kvm_run-s.regs.crs[i] = env-cregs[i];
 +}
 +cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_ACRS;
 +cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_CRS;
 +} else {
 +for (i = 0; i  16; i++) {
 +sregs.acrs[i] = env-aregs[i];
 +sregs.crs[i] = env-cregs[i];
 +}
 +ret = kvm_vcpu_ioctl(cs, KVM_SET_SREGS, sregs);
 +if (ret  0) {
 +return ret;
 +}
 }
 -ret = kvm_vcpu_ioctl(cs, KVM_SET_SREGS, sregs);
 -if (ret  0) {
 -return ret;
 +
 +/* Finally the prefix */
 +if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_PREFIX) {
 +cs-kvm_run-s.regs.prefix = env-psa;
 +cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_PREFIX;
 +} else {
 +/* prefix is only supported via sync regs */
 }
 }
 
 -/* Finally the prefix */
 -if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_PREFIX) {
 -cs-kvm_run-s.regs.prefix = env-psa;
 -cs-kvm_run-kvm_dirty_regs |= KVM_SYNC_PREFIX;
 -} else {
 -/* prefix is only supported via sync regs */
 -}
 return 0;
 }
 
 @@ -160,49 +159,53 @@ int kvm_arch_get_registers(CPUState *cs, int regmap)
 int ret;
 int i;
 
 -/* get the PSW */
 -env-psw.addr = cs-kvm_run-psw_addr;
 -env-psw.mask = cs-kvm_run-psw_mask;
 +if (regmap  KVM_REGSYNC_S390_RUNTIME_REGS) {
 +/* get the PSW */
 +env-psw.addr = cs-kvm_run-psw_addr;
 +env-psw.mask = cs-kvm_run-psw_mask;
 
 -/* the GPRS */
 -if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_GPRS) {
 -for (i = 0; i  16; i++) {
 -env-regs[i] = cs-kvm_run-s.regs.gprs[i];
 

Re: [Qemu-devel] buildbot failure in qemu on monitor_x86_64_debian_6_0

2013-01-24 Thread Luiz Capitulino
On Thu, 24 Jan 2013 04:44:42 +0100
q...@buildbot.b1-systems.de wrote:

 The Buildbot has detected a new failure on builder monitor_x86_64_debian_6_0 
 while building qemu.

I actually dropped that queue, as I'm not using it.

Can you guys remove it from buildslaves?



Re: [Qemu-devel] [PATCH] qapi/x86: add control registers to query-cpus

2013-01-24 Thread Luiz Capitulino
On Wed, 23 Jan 2013 16:45:50 -0500
pe...@gridcentric.ca wrote:

 From: Peter Feiner pe...@gridcentric.ca
 
 Adds control registers that govern virtual address translation to query-cpus.
 
 Given these registers and the guest's physical memory, which can be obtained
 with dump-guest-memory, a client can perform virtual-to-physical translations.
 This is useful for debugging and introspection.

What about converting 'info registers' to QMP (ie. having query-cpu-registers)?



[Qemu-devel] [PATCH 02/11] s390: Add mapping helper functions.

2013-01-24 Thread Cornelia Huck
Add s390_cpu_physical_memory_{map,unmap} with special handling
for the lowcore.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com

---

v5 - v6:

 - Make lowcore/0 page handling easier to read
 - Make len a pointer
---
 target-s390x/cpu.h|  4 
 target-s390x/helper.c | 25 +
 2 files changed, 29 insertions(+)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 1f2d942..7951aab 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -302,6 +302,10 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, 
target_ulong address, int rw
 
 
 #ifndef CONFIG_USER_ONLY
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr 
*len,
+   int is_write);
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+int is_write);
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 023c074..3109c77 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -490,6 +490,31 @@ static void cpu_unmap_lowcore(LowCore *lowcore)
 cpu_physical_memory_unmap(lowcore, sizeof(LowCore), 1, sizeof(LowCore));
 }
 
+void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr 
*len,
+   int is_write)
+{
+hwaddr start = addr;
+
+/* Mind the prefix area. */
+if (addr  8192) {
+/* Map the lowcore. */
+start += env-psa;
+*len = MIN(*len, 8192 - addr);
+} else if ((addr = env-psa)  (addr  env-psa + 8192)) {
+/* Map the 0 page. */
+start -= env-psa;
+*len = MIN(*len, 8192 - start);
+}
+
+return cpu_physical_memory_map(start, len, is_write);
+}
+
+void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
+int is_write)
+{
+cpu_physical_memory_unmap(addr, len, is_write, len);
+}
+
 static void do_svc_interrupt(CPUS390XState *env)
 {
 uint64_t mask, addr;
-- 
1.7.12.4




[Qemu-devel] [PATCH v6 00/11] s390: channel I/O support in qemu.

2013-01-24 Thread Cornelia Huck
Hi,

another round for virtual channel I/O in qemu.

The patches have been respun against current master; changelogs
are in the patches themselves.

Changes are mostly some cleanups; of note are the preparations
for VirtioBus and some changes for making the code endianness
aware.

Making s390-ccw-virtio the default machine has been deferred until
after tcg support is available.

Alexander Graf (1):
  s390: Add default support for SCLP console

Cornelia Huck (10):
  s390: Lowcore mapping helper.
  s390: Add mapping helper functions.
  s390: Channel I/O basic definitions.
  s390: I/O interrupt and machine check injection.
  s390: Add channel I/O instructions.
  s390: Virtual channel subsystem support.
  s390: Wire up channel I/O in kvm.
  s390: Add new channel I/O based virtio transport.
  s390-virtio: Factor out some initialization code.
  s390: Add s390-ccw-virtio machine.

 hw/boards.h|1 +
 hw/s390-virtio.c   |  118 ++--
 hw/s390-virtio.h   |6 +
 hw/s390x/Makefile.objs |3 +
 hw/s390x/css.c | 1277 
 hw/s390x/css.h |   99 
 hw/s390x/s390-virtio-ccw.c |  134 +
 hw/s390x/virtio-ccw.c  |  947 
 hw/s390x/virtio-ccw.h  |   94 
 target-s390x/Makefile.objs |2 +-
 target-s390x/cpu.h |  247 -
 target-s390x/helper.c  |  200 ++-
 target-s390x/ioinst.c  |  752 ++
 target-s390x/ioinst.h  |  223 
 target-s390x/kvm.c |  239 -
 trace-events   |   18 +
 vl.c   |   48 ++
 17 files changed, 4333 insertions(+), 75 deletions(-)
 create mode 100644 hw/s390x/css.c
 create mode 100644 hw/s390x/css.h
 create mode 100644 hw/s390x/s390-virtio-ccw.c
 create mode 100644 hw/s390x/virtio-ccw.c
 create mode 100644 hw/s390x/virtio-ccw.h
 create mode 100644 target-s390x/ioinst.c
 create mode 100644 target-s390x/ioinst.h

-- 
1.7.12.4




[Qemu-devel] [PATCH 10/11] s390: Add default support for SCLP console

2013-01-24 Thread Cornelia Huck
From: Alexander Graf ag...@suse.de

The current s390 machine uses the virtio console as default console,
but this doesn't mean that we always want to keep it that way for new
machines.

This patch introduces a way for a machine type to specify that it wants
the default console to be an SCLP console, which is a lot closer to what
real hardware does.

Signed-off-by: Alexander Graf ag...@suse.de
Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
---
 hw/boards.h |  1 +
 vl.c| 48 
 2 files changed, 49 insertions(+)

diff --git a/hw/boards.h b/hw/boards.h
index 3ff9665..3813d4e 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -33,6 +33,7 @@ typedef struct QEMUMachine {
 unsigned int no_serial:1,
 no_parallel:1,
 use_virtcon:1,
+use_sclp:1,
 no_floppy:1,
 no_cdrom:1,
 no_sdcard:1;
diff --git a/vl.c b/vl.c
index 4ee1302..6a19a8f 100644
--- a/vl.c
+++ b/vl.c
@@ -176,6 +176,7 @@ int main(int argc, char **argv)
 #define DEFAULT_RAM_SIZE 128
 
 #define MAX_VIRTIO_CONSOLES 1
+#define MAX_SCLP_CONSOLES 1
 
 static const char *data_dir;
 const char *bios_name = NULL;
@@ -203,6 +204,7 @@ int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
+CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
@@ -271,6 +273,7 @@ static int tcg_tb_size;
 static int default_serial = 1;
 static int default_parallel = 1;
 static int default_virtcon = 1;
+static int default_sclp = 1;
 static int default_monitor = 1;
 static int default_floppy = 1;
 static int default_cdrom = 1;
@@ -2340,6 +2343,7 @@ struct device_config {
 DEV_VIRTCON,   /* -virtioconsole */
 DEV_DEBUGCON,  /* -debugcon */
 DEV_GDB,   /* -gdb, -s */
+DEV_SCLP,  /* s390 sclp */
 } type;
 const char *cmdline;
 Location loc;
@@ -2458,6 +2462,39 @@ static int virtcon_parse(const char *devname)
 return 0;
 }
 
+static int sclp_parse(const char *devname)
+{
+QemuOptsList *device = qemu_find_opts(device);
+static int index = 0;
+char label[32];
+QemuOpts *dev_opts;
+
+if (strcmp(devname, none) == 0) {
+return 0;
+}
+if (index == MAX_SCLP_CONSOLES) {
+fprintf(stderr, qemu: too many sclp consoles\n);
+exit(1);
+}
+
+assert(arch_type == QEMU_ARCH_S390X);
+
+dev_opts = qemu_opts_create(device, NULL, 0, NULL);
+qemu_opt_set(dev_opts, driver, sclpconsole);
+
+snprintf(label, sizeof(label), sclpcon%d, index);
+sclp_hds[index] = qemu_chr_new(label, devname, NULL);
+if (!sclp_hds[index]) {
+fprintf(stderr, qemu: could not connect sclp console
+ to character backend '%s'\n, devname);
+return -1;
+}
+qemu_opt_set(dev_opts, chardev, label);
+
+index++;
+return 0;
+}
+
 static int debugcon_parse(const char *devname)
 {   
 QemuOpts *opts;
@@ -3832,6 +3869,9 @@ int main(int argc, char **argv, char **envp)
 if (!machine-use_virtcon) {
 default_virtcon = 0;
 }
+if (!machine-use_sclp) {
+default_sclp = 0;
+}
 if (machine-no_floppy) {
 default_floppy = 0;
 }
@@ -3873,11 +3913,15 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_SERIAL, mon:stdio);
 } else if (default_virtcon  default_monitor) {
 add_device_config(DEV_VIRTCON, mon:stdio);
+} else if (default_sclp  default_monitor) {
+add_device_config(DEV_SCLP, mon:stdio);
 } else {
 if (default_serial)
 add_device_config(DEV_SERIAL, stdio);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, stdio);
+if (default_sclp)
+add_device_config(DEV_SCLP, stdio);
 if (default_monitor)
 monitor_parse(stdio, readline);
 }
@@ -3890,6 +3934,8 @@ int main(int argc, char **argv, char **envp)
 monitor_parse(vc:80Cx24C, readline);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, vc:80Cx24C);
+if (default_sclp)
+add_device_config(DEV_SCLP, vc:80Cx24C);
 }
 
 socket_init();
@@ -4060,6 +4106,8 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 if (foreach_device_config(DEV_VIRTCON, virtcon_parse)  0)
 exit(1);
+if (foreach_device_config(DEV_SCLP, sclp_parse)  0)
+exit(1);
 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse)  0)
 exit(1);
 
-- 
1.7.12.4




[Qemu-devel] [PATCH 11/11] s390: Add s390-ccw-virtio machine.

2013-01-24 Thread Cornelia Huck
Add a new machine type, s390-ccw-virtio, making use of the
virtio-ccw transport to present virtio devices as channel
devices.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com

---

v5 - v6:
- Don't make virtio-ccw the default yet
- Adapt to ipl device changes
- Adapt to VirtioBus changes
- Default to sclp console
---
 hw/s390-virtio.h   |   1 +
 hw/s390x/Makefile.objs |   1 +
 hw/s390x/s390-virtio-ccw.c | 134 +
 3 files changed, 136 insertions(+)
 create mode 100644 hw/s390x/s390-virtio-ccw.c

diff --git a/hw/s390-virtio.h b/hw/s390-virtio.h
index 67bfd20..a6c4c19 100644
--- a/hw/s390-virtio.h
+++ b/hw/s390-virtio.h
@@ -15,6 +15,7 @@
 #define KVM_S390_VIRTIO_NOTIFY  0
 #define KVM_S390_VIRTIO_RESET   1
 #define KVM_S390_VIRTIO_SET_STATUS  2
+#define KVM_S390_VIRTIO_CCW_NOTIFY  3
 
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index f6b461b..9eed6d9 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -7,4 +7,5 @@ obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
 obj-y += ipl.o
 obj-y += css.o
+obj-y += s390-virtio-ccw.o
 obj-y += virtio-ccw.o
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
new file mode 100644
index 000..9575d00
--- /dev/null
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -0,0 +1,134 @@
+/*
+ * virtio ccw machine
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck cornelia.h...@de.ibm.com
+ *
+ * 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 hw/boards.h
+#include exec/address-spaces.h
+#include hw/s390-virtio.h
+#include hw/s390x/sclp.h
+#include ioinst.h
+#include css.h
+#include virtio-ccw.h
+
+static int virtio_ccw_hcall_notify(const uint64_t *args)
+{
+uint64_t subch_id = args[0];
+uint64_t queue = args[1];
+SubchDev *sch;
+int cssid, ssid, schid, m;
+
+if (ioinst_disassemble_sch_ident(subch_id, m, cssid, ssid, schid)) {
+return -EINVAL;
+}
+sch = css_find_subch(m, cssid, ssid, schid);
+if (!sch || !css_subch_visible(sch)) {
+return -EINVAL;
+}
+virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
+return 0;
+
+}
+
+static int virtio_ccw_hcall_early_printk(const uint64_t *args)
+{
+uint64_t mem = args[0];
+
+if (mem  ram_size) {
+/* Early printk */
+return 0;
+}
+return -EINVAL;
+}
+
+static void virtio_ccw_register_hcalls(void)
+{
+s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
+   virtio_ccw_hcall_notify);
+/* Tolerate early printk. */
+s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
+   virtio_ccw_hcall_early_printk);
+}
+
+static void ccw_init(QEMUMachineInitArgs *args)
+{
+ram_addr_t my_ram_size = args-ram_size;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
+int shift = 0;
+uint8_t *storage_keys;
+int ret;
+VirtualCssBus *css_bus;
+
+/* s390x ram size detection needs a 16bit multiplier + an increment. So
+   guests  64GB can be specified in 2MB steps etc. */
+while ((my_ram_size  (20 + shift))  65535) {
+shift++;
+}
+my_ram_size = my_ram_size  (20 + shift)  (20 + shift);
+
+/* lets propagate the changed ram size into the global variable. */
+ram_size = my_ram_size;
+
+/* get a BUS */
+css_bus = virtual_css_bus_init();
+s390_sclp_init();
+s390_init_ipl_dev(args-kernel_filename, args-kernel_cmdline,
+  args-initrd_filename);
+
+/* register hypercalls */
+virtio_ccw_register_hcalls();
+
+/* allocate RAM */
+memory_region_init_ram(ram, s390.ram, my_ram_size);
+vmstate_register_ram_global(ram);
+memory_region_add_subregion(sysmem, 0, ram);
+
+/* allocate storage keys */
+storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
+
+/* init CPUs */
+s390_init_cpus(args-cpu_model, storage_keys);
+
+if (kvm_enabled()) {
+kvm_s390_enable_css_support(s390_cpu_addr2state(0));
+}
+/*
+ * Create virtual css and set it as default so that non mcss-e
+ * enabled guests only see virtio devices.
+ */
+ret = css_create_css_image(VIRTUAL_CSSID, true);
+assert(ret == 0);
+
+/* Create VirtIO network adapters */
+s390_create_virtio_net(BUS(css_bus), virtio-net-ccw);
+}
+
+static QEMUMachine ccw_machine = {
+.name = s390-ccw-virtio,
+.alias = s390-ccw,
+.desc = VirtIO-ccw based S390 machine,
+.init = ccw_init,
+.block_default_type = IF_VIRTIO,
+.no_cdrom = 1,
+.no_floppy = 1,
+.no_serial = 1,
+.no_parallel = 1,
+.no_sdcard = 1,
+.use_sclp = 1,
+ 

[Qemu-devel] [PATCH 05/11] s390: Add channel I/O instructions.

2013-01-24 Thread Cornelia Huck
Provide handlers for (most) channel I/O instructions.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com

---

v5 - v6:
- Adapt to s390_cpu_physical_memory_map changes
- Simplify chsc handling
- Handle endianness
---
 target-s390x/cpu.h| 100 +++
 target-s390x/ioinst.c | 716 ++
 target-s390x/ioinst.h |  16 ++
 trace-events  |   6 +
 4 files changed, 838 insertions(+)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 3e00d38..76a822c 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -147,6 +147,9 @@ static inline void cpu_clone_regs(CPUS390XState *env, 
target_ulong newsp)
 }
 #endif
 
+/* distinguish between 24 bit and 31 bit addressing */
+#define HIGH_ORDER_BIT 0x8000
+
 /* Interrupt Codes */
 /* Program Interrupts */
 #define PGM_OPERATION   0x0001
@@ -331,6 +334,20 @@ void *s390_cpu_physical_memory_map(CPUS390XState *env, 
hwaddr addr, hwaddr *len,
int is_write);
 void s390_cpu_physical_memory_unmap(CPUS390XState *env, void *addr, hwaddr len,
 int is_write);
+static inline hwaddr decode_basedisp_s(CPUS390XState *env, uint32_t ipb)
+{
+hwaddr addr = 0;
+uint8_t reg;
+
+reg = ipb  28;
+if (reg  0) {
+addr = env-regs[reg];
+}
+addr += (ipb  16)  0xfff;
+
+return addr;
+}
+
 void s390x_tod_timer(void *opaque);
 void s390x_cpu_timer(void *opaque);
 
@@ -380,6 +397,89 @@ static inline unsigned s390_del_running_cpu(CPUS390XState 
*env)
 void cpu_lock(void);
 void cpu_unlock(void);
 
+typedef struct SubchDev SubchDev;
+
+static inline SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
+   uint16_t schid)
+{
+return NULL;
+}
+static inline bool css_subch_visible(SubchDev *sch)
+{
+return false;
+}
+static inline void css_conditional_io_interrupt(SubchDev *sch)
+{
+}
+static inline int css_do_stsch(SubchDev *sch, SCHIB *schib)
+{
+return -ENODEV;
+}
+static inline bool css_schid_final(uint8_t cssid, uint8_t ssid, uint16_t schid)
+{
+return true;
+}
+static inline int css_do_msch(SubchDev *sch, SCHIB *schib)
+{
+return -ENODEV;
+}
+static inline int css_do_xsch(SubchDev *sch)
+{
+return -ENODEV;
+}
+static inline int css_do_csch(SubchDev *sch)
+{
+return -ENODEV;
+}
+static inline int css_do_hsch(SubchDev *sch)
+{
+return -ENODEV;
+}
+static inline int css_do_ssch(SubchDev *sch, ORB *orb)
+{
+return -ENODEV;
+}
+static inline int css_do_tsch(SubchDev *sch, IRB *irb)
+{
+return -ENODEV;
+}
+static inline int css_do_stcrw(CRW *crw)
+{
+return 1;
+}
+static inline int css_do_tpi(uint64_t addr, int lowcore)
+{
+return 0;
+}
+static inline int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid,
+   int rfmt, uint8_t l_chpid, void *buf)
+{
+return 0;
+}
+static inline void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo)
+{
+}
+static inline int css_enable_mss(void)
+{
+return -EINVAL;
+}
+static inline int css_enable_mcsse(void)
+{
+return -EINVAL;
+}
+static inline int css_do_rsch(SubchDev *sch)
+{
+return -ENODEV;
+}
+static inline int css_do_rchp(uint8_t cssid, uint8_t chpid)
+{
+return -ENODEV;
+}
+static inline bool css_present(uint8_t cssid)
+{
+return false;
+}
+
 static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
 {
 env-aregs[0] = newtls  32;
diff --git a/target-s390x/ioinst.c b/target-s390x/ioinst.c
index 06a16ee..4ef2d73 100644
--- a/target-s390x/ioinst.c
+++ b/target-s390x/ioinst.c
@@ -13,6 +13,7 @@
 
 #include cpu.h
 #include ioinst.h
+#include trace.h
 
 int ioinst_disassemble_sch_ident(uint32_t value, int *m, int *cssid, int *ssid,
  int *schid)
@@ -34,3 +35,718 @@ int ioinst_disassemble_sch_ident(uint32_t value, int *m, 
int *cssid, int *ssid,
 *schid = IOINST_SCHID_NR(value);
 return 0;
 }
+
+int ioinst_handle_xsch(CPUS390XState *env, uint64_t reg1)
+{
+int cssid, ssid, schid, m;
+SubchDev *sch;
+int ret = -ENODEV;
+int cc;
+
+if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid)) {
+program_interrupt(env, PGM_OPERAND, 2);
+return -EIO;
+}
+trace_ioinst_sch_id(xsch, cssid, ssid, schid);
+sch = css_find_subch(m, cssid, ssid, schid);
+if (sch  css_subch_visible(sch)) {
+ret = css_do_xsch(sch);
+}
+switch (ret) {
+case -ENODEV:
+cc = 3;
+break;
+case -EBUSY:
+cc = 2;
+break;
+case 0:
+cc = 0;
+break;
+default:
+cc = 1;
+break;
+}
+
+return cc;
+}
+
+int ioinst_handle_csch(CPUS390XState *env, uint64_t reg1)
+{
+int cssid, ssid, schid, m;
+SubchDev *sch;
+int ret = -ENODEV;
+int cc;
+
+if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid)) {
+

[Qemu-devel] [PATCH 08/11] s390: Add new channel I/O based virtio transport.

2013-01-24 Thread Cornelia Huck
Add a new virtio transport that uses channel commands to perform
virtio operations.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com

---

v5 - v6:
- Get rid of qemu_get_ram_ptr usage
- Adapt to virtual css changes
- Constify TypeInfos
- Prepare for VirtioBus
---
 hw/s390x/Makefile.objs |   1 +
 hw/s390x/virtio-ccw.c  | 947 +
 hw/s390x/virtio-ccw.h  |  94 +
 trace-events   |   4 +
 4 files changed, 1046 insertions(+)
 create mode 100644 hw/s390x/virtio-ccw.c
 create mode 100644 hw/s390x/virtio-ccw.h

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index ab99da6..f6b461b 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -7,3 +7,4 @@ obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
 obj-y += ipl.o
 obj-y += css.o
+obj-y += virtio-ccw.o
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
new file mode 100644
index 000..58f9982
--- /dev/null
+++ b/hw/s390x/virtio-ccw.c
@@ -0,0 +1,947 @@
+/*
+ * virtio ccw target implementation
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Cornelia Huck cornelia.h...@de.ibm.com
+ *
+ * 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 hw/hw.h
+#include block/block.h
+#include sysemu/blockdev.h
+#include sysemu/sysemu.h
+#include net/net.h
+#include monitor/monitor.h
+#include hw/virtio.h
+#include hw/virtio-serial.h
+#include hw/virtio-net.h
+#include hw/sysbus.h
+#include qemu/bitops.h
+#include hw/virtio-bus.h
+
+#include ioinst.h
+#include css.h
+#include virtio-ccw.h
+#include trace.h
+
+static const TypeInfo virtual_css_bus_info = {
+.name = TYPE_VIRTUAL_CSS_BUS,
+.parent = TYPE_BUS,
+.instance_size = sizeof(VirtualCssBus),
+};
+
+static const VirtIOBindings virtio_ccw_bindings;
+
+VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
+{
+VirtIODevice *vdev = NULL;
+
+if (sch-driver_data) {
+vdev = ((VirtioCcwData *)sch-driver_data)-vdev;
+}
+return vdev;
+}
+
+static void virtio_ccw_reset_subchannels(void *opaque)
+{
+VirtualCssBus *bus = opaque;
+BusChild *kid;
+VirtioCcwData *data;
+BusState *parent = BUS(bus);
+
+QTAILQ_FOREACH(kid, parent-children, sibling) {
+data = (VirtioCcwData *)kid-child;
+virtio_reset(data-vdev);
+css_reset_sch(data-sch);
+}
+css_reset();
+}
+
+VirtualCssBus *virtual_css_bus_init(void)
+{
+VirtualCssBus *cbus;
+BusState *bus;
+DeviceState *dev;
+
+/* Create bridge device */
+dev = qdev_create(NULL, virtual-css-bridge);
+qdev_init_nofail(dev);
+
+/* Create bus on bridge device */
+bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, virtual-css);
+cbus = VIRTUAL_CSS_BUS(bus);
+
+/* Enable hotplugging */
+bus-allow_hotplug = 1;
+
+qemu_register_reset(virtio_ccw_reset_subchannels, cbus);
+return cbus;
+}
+
+/* Communication blocks used by several channel commands. */
+typedef struct VqInfoBlock {
+uint64_t queue;
+uint32_t align;
+uint16_t index;
+uint16_t num;
+} QEMU_PACKED VqInfoBlock;
+
+typedef struct VqConfigBlock {
+uint16_t index;
+uint16_t num_max;
+} QEMU_PACKED VqConfigBlock;
+
+typedef struct VirtioFeatDesc {
+uint32_t features;
+uint8_t index;
+} QEMU_PACKED VirtioFeatDesc;
+
+/* Specify where the virtqueues for the subchannel are in guest memory. */
+static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
+  uint16_t index, uint16_t num)
+{
+VirtioCcwData *data = sch-driver_data;
+
+if (index  VIRTIO_PCI_QUEUE_MAX) {
+return -EINVAL;
+}
+
+/* Current code in virtio.c relies on 4K alignment. */
+if (addr  (align != 4096)) {
+return -EINVAL;
+}
+
+if (!data) {
+return -EINVAL;
+}
+
+virtio_queue_set_addr(data-vdev, index, addr);
+if (!addr) {
+virtio_queue_set_vector(data-vdev, index, 0);
+} else {
+/* Fail if we don't have a big enough queue. */
+/* TODO: Add interface to handle vring.num changing */
+if (virtio_queue_get_num(data-vdev, index)  num) {
+return -EINVAL;
+}
+virtio_queue_set_vector(data-vdev, index, index);
+}
+/* tell notify handler in case of config change */
+data-vdev-config_vector = VIRTIO_PCI_QUEUE_MAX;
+return 0;
+}
+
+static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
+{
+int ret;
+VqInfoBlock info;
+uint8_t status;
+VirtioFeatDesc features;
+void *config;
+hwaddr indicators;
+VqConfigBlock vq_config;
+VirtioCcwData *data = sch-driver_data;
+bool check_len;
+int len;
+hwaddr hw_len;
+
+if (!data) {
+return -EINVAL;
+}
+
+trace_virtio_ccw_interpret_ccw(sch-cssid, sch-ssid, sch-schid,
+   ccw.cmd_code);
+check_len = 

Re: [Qemu-devel] [PATCH] ui/vnc: VA API based H.264 encoding for VNC framebuffer updates

2013-01-24 Thread Verbeiren, David
Hi Jérôme,

The patch applied cleanly on qemu master branch when I sent it. I see the 
addition of ui/vnc_ws probably broke it.
The specific commit I tested it against was 8e4a424b305e29...:
http://git.qemu.org/?p=qemu.git;a=snapshot;h=8e4a424b305e29dc0e454f52df3b35577f342975;sf=tgz

I'll also take care of that when I send a next revision addressing the comments 
I got from the list (hopefully some time next week).

Regards,
-David

-Original Message-
From: Jérôme Jutteau [mailto:jerome.jutt...@outscale.com] 
Sent: Thursday, January 24, 2013 11:16 AM
To: Verbeiren, David
Cc: qemu-devel@nongnu.org; aligu...@us.ibm.com
Subject: Re: [Qemu-devel] [PATCH] ui/vnc: VA API based H.264 encoding for VNC 
framebuffer updates

Hello Qemu people,

2013/1/9 David Verbeiren david.verbei...@intel.com:
 This patch implements H.264 encoding of the VNC framebuffer updates 
 using hardware acceleration through the VA API.

Sounds Great !

Sorry if my question has a obvious response but I can't find it:
David, on which version of Qemu can we apply your attached patch ?

Thanks !

--
Jérôme Jutteau
Intel Corporation NV/SA
Kings Square, Veldkant 31
2550 Kontich
RPM (Bruxelles) 0415.497.718. 
Citibank, Brussels, account 570/1031255/09

This e-mail and any attachments may contain confidential material for the sole 
use of the intended recipient(s). Any review or distribution by others is 
strictly prohibited. If you are not the intended recipient, please contact the 
sender and delete all copies.


Re: [Qemu-devel] [PATCH] vmware_vga: fix out of bounds and invalid rects updating

2013-01-24 Thread Marek Vasut
Dear Michael Tokarev,

 This is a follow up for several attempts to fix this issue.
 
 Previous incarnations:
 
 1. http://thread.gmane.org/gmane.linux.ubuntu.bugs.general/3156089
 https://bugs.launchpad.net/bugs/918791
 qemu-kvm dies when using vmvga driver and unity in the guest bug.
 Fix by Serge Hallyn:
  https://launchpadlibrarian.net/94916786/qemu-vmware.debdiff
 This fix is incomplete, since it does not check width and height
 for being negative.  Serge weren't sure if that's the right place
 to fix it, maybe the fix should be up the stack somewhere.
 
 2. http://thread.gmane.org/gmane.comp.emulators.qemu/166064
 by Marek Vasut: vmware_vga: Redraw only visible area

Looks like this should do the trick as well.

Reviewed-by: Marek Vasut ma...@denx.de

Best regards,
Marek Vasut



Re: [Qemu-devel] [PATCH] s390: Add default support for SCLP console

2013-01-24 Thread Andreas Färber
Am 24.01.2013 12:23, schrieb Alexander Graf:
 The current s390 machine uses the virtio console as default console,
 but this doesn't mean that we always want to keep it that way for new
 machines.
 
 This patch introduces a way for a machine type to specify that it wants
 the default console to be an SCLP console, which is a lot closer to what
 real hardware does.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  hw/boards.h |1 +
  vl.c|   48 
  2 files changed, 49 insertions(+), 0 deletions(-)
 
 diff --git a/hw/boards.h b/hw/boards.h
 index 3ff9665..3813d4e 100644
 --- a/hw/boards.h
 +++ b/hw/boards.h
 @@ -33,6 +33,7 @@ typedef struct QEMUMachine {
  unsigned int no_serial:1,
  no_parallel:1,
  use_virtcon:1,
 +use_sclp:1,
  no_floppy:1,
  no_cdrom:1,
  no_sdcard:1;
 diff --git a/vl.c b/vl.c
 index 4ee1302..6a19a8f 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -176,6 +176,7 @@ int main(int argc, char **argv)
  #define DEFAULT_RAM_SIZE 128
  
  #define MAX_VIRTIO_CONSOLES 1
 +#define MAX_SCLP_CONSOLES 1
  
  static const char *data_dir;
  const char *bios_name = NULL;
 @@ -203,6 +204,7 @@ int no_quit = 0;
  CharDriverState *serial_hds[MAX_SERIAL_PORTS];
  CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
  CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
 +CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
  int win2k_install_hack = 0;
  int singlestep = 0;
  int smp_cpus = 1;
 @@ -271,6 +273,7 @@ static int tcg_tb_size;
  static int default_serial = 1;
  static int default_parallel = 1;
  static int default_virtcon = 1;
 +static int default_sclp = 1;
  static int default_monitor = 1;
  static int default_floppy = 1;
  static int default_cdrom = 1;
 @@ -2340,6 +2343,7 @@ struct device_config {
  DEV_VIRTCON,   /* -virtioconsole */
  DEV_DEBUGCON,  /* -debugcon */
  DEV_GDB,   /* -gdb, -s */
 +DEV_SCLP,  /* s390 sclp */
  } type;
  const char *cmdline;
  Location loc;
 @@ -2458,6 +2462,39 @@ static int virtcon_parse(const char *devname)
  return 0;
  }
  
 +static int sclp_parse(const char *devname)
 +{
 +QemuOptsList *device = qemu_find_opts(device);
 +static int index = 0;
 +char label[32];
 +QemuOpts *dev_opts;
 +
 +if (strcmp(devname, none) == 0) {
 +return 0;
 +}
 +if (index == MAX_SCLP_CONSOLES) {
 +fprintf(stderr, qemu: too many sclp consoles\n);
 +exit(1);
 +}
 +
 +assert(arch_type == QEMU_ARCH_S390X);
 +
 +dev_opts = qemu_opts_create(device, NULL, 0, NULL);
 +qemu_opt_set(dev_opts, driver, sclpconsole);
 +
 +snprintf(label, sizeof(label), sclpcon%d, index);
 +sclp_hds[index] = qemu_chr_new(label, devname, NULL);
 +if (!sclp_hds[index]) {
 +fprintf(stderr, qemu: could not connect sclp console
 + to character backend '%s'\n, devname);
 +return -1;
 +}
 +qemu_opt_set(dev_opts, chardev, label);
 +
 +index++;
 +return 0;
 +}
 +
  static int debugcon_parse(const char *devname)
  {   
  QemuOpts *opts;
 @@ -3832,6 +3869,9 @@ int main(int argc, char **argv, char **envp)
  if (!machine-use_virtcon) {
  default_virtcon = 0;
  }
 +if (!machine-use_sclp) {
 +default_sclp = 0;
 +}
  if (machine-no_floppy) {
  default_floppy = 0;
  }
 @@ -3873,11 +3913,15 @@ int main(int argc, char **argv, char **envp)
  add_device_config(DEV_SERIAL, mon:stdio);
  } else if (default_virtcon  default_monitor) {
  add_device_config(DEV_VIRTCON, mon:stdio);
 +} else if (default_sclp  default_monitor) {
 +add_device_config(DEV_SCLP, mon:stdio);
  } else {
  if (default_serial)
  add_device_config(DEV_SERIAL, stdio);
  if (default_virtcon)
  add_device_config(DEV_VIRTCON, stdio);
 +if (default_sclp)
 +add_device_config(DEV_SCLP, stdio);

Braces.

  if (default_monitor)
  monitor_parse(stdio, readline);
  }
 @@ -3890,6 +3934,8 @@ int main(int argc, char **argv, char **envp)
  monitor_parse(vc:80Cx24C, readline);
  if (default_virtcon)
  add_device_config(DEV_VIRTCON, vc:80Cx24C);
 +if (default_sclp)
 +add_device_config(DEV_SCLP, vc:80Cx24C);

Braces

  }
  
  socket_init();
 @@ -4060,6 +4106,8 @@ int main(int argc, char **argv, char **envp)
  exit(1);
  if (foreach_device_config(DEV_VIRTCON, virtcon_parse)  0)
  exit(1);
 +if (foreach_device_config(DEV_SCLP, sclp_parse)  0)
 +exit(1);

Braces (seems you're not using a checkpatch.pl commit hook?)

  if (foreach_device_config(DEV_DEBUGCON, debugcon_parse)  0)
  exit(1);
  

Otherwise doesn't look wrong.

Out of curiosity, where is hds historically coming from?
For 

Re: [Qemu-devel] [PATCH] ide: Add fall through annotations

2013-01-24 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Add comments to help static analysers detect that these cases are
 intentional, and clean up some whitespace in the environment of these
 comments.

 Signed-off-by: Kevin Wolf kw...@redhat.com

Reviewed-by: Markus Armbruster arm...@redhat.com



Re: [Qemu-devel] [PATCH 4/7 v2] KVM regsync: Add register bitmap parameter to do_kvm_cpu_synchronize_state

2013-01-24 Thread Alexander Graf

On 17.01.2013, at 00:01, Marcelo Tosatti wrote:

 On Wed, Jan 16, 2013 at 09:41:54PM +0100, Christian Borntraeger wrote:
 On 16/01/13 21:21, Marcelo Tosatti wrote:
 On Wed, Jan 16, 2013 at 09:03:20PM +0100, Christian Borntraeger wrote:
 On 16/01/13 17:05, Marcelo Tosatti wrote:
 
 The S/390 problem, from
 http://lists.nongnu.org/archive/html/qemu-devel/2012-11/msg02213.html:
 
  The kvm register sync needs to happen in the kvm register sync
 function :)
 That would eliminate the whole purpose of sync regs and forces us to
 have an
 expensive ioctl on lots of exits (again). I would prefer to sync the 
 registers
 that we never need in qemu just here.
 
 That's why the register sync has different stages.
 
 Not the get_register. Which is called on every synchronize_state. Which
 happen 
 quite often
 on s390.
 
 But wait: on these S/390 codepaths, you do GET_REGS already, via
 cpu_synchronize_state.
 
 So on S/390
 
 - cpu_synchronize_state(env)
 - read any register from env
 
 Is not valid? This is what generic code assumes.
 
 TO recap the motiviation:
 
 cpu_synchronize_state on s390 currently updates any register in env that is
 used by qemu (general purpose, prefix, psw, control and access) in the 
 normal
 runtime. it turns out we have all of these regs in kvm_run, so we can do 
 synchronize states without doing an additional ioctl call.
 Now, for life migration and dump we need some additional registers (which 
 are
 only accessable via onereg interface). So synchronize_state would need to
 do 3 or 4 additional system calls on the hot path, only to take care of 
 something that is not on the hot path at all.
 For historic reasons, we have one exit code for almost all exits. 
 Therefore,
 we need to call synchronize_states almost always.
 We could now start to have a poor mans synchronize_state in arch code, but
 that would collide with common code synchronize_state if done at the wrong
 time. Thus we want to make common code capable of having only a subset of
 the register synched - by making it possible to sync the other regs later
 on if needed without wiping the former sync.
 
 Makes sense?
 
 Christian
 
 Yes. As noted in the last email on the thread, runtime/reset/full are to
 serapate sets of registers when writing _to_ kernel. When reading _from_
 kernel, reset and full distinctions are not appropriate (any register
 can change, as far as knowledge goes).
 
 Hmm, I probably did not understood your point, so I will try to explain mine
 and see what you respond :-)
 
 The point of the patch set, is to allow this distinction when reading. 
 In other words it allows code to state: I am only interested in regxy and 
 dont
 care if the other regs in env are out of sync.
 
 Fine.
 
 If a full sync is necessary later on the other regs are synched as well.
 If a full sync was already done before a partial get becomes a no-op.
 
 - FULL is the set of registers written when loadvm/initialization is
 performed.
 - RESET, a subset of full, is a set of registers written on SYSTEM
 RESET.
 - RUNTIME, a subset of RESET, is a set of registers written during
 RUNTIME.
 
 To write both the RESET and FULL set of registers during runtime,
 contradicts the description above for both RESET and FULL.
 
 Two examples from i386:
 
if (level == KVM_PUT_FULL_STATE) {
/*
 * KVM is yet unable to synchronize TSC values of multiple VCPUs
 * on
 * writeback. Until this is fixed, we only write the offset to
 * SMP
 * guests after migration, desynchronizing the VCPUs, but
 * avoiding
 * huge jump-backs that would occur without any writeback at
 * all.
 */
   ...
}
 
 And:
 
/*
 * The following paravirtual MSRs have side effects on the guest or
 * are
 * too heavy for normal writeback. Limit them to reset or full state
 * updates.
 */
 
 Why should that be not possible.
 
 It should, but separately from FULL/RESET/RUNTIME distinction.
 This sequence
 
   get_regs(FULLSTATE)
   put_regs(FULLSTATE)
 
 During runtime is not allowed. And only syncing the RUNTIME set of
 registers during and leaving the FULL set of registers marked as
 dirty is confusing also. 
 
 So perhaps what you'd want is selective read/write of RUNTIME registers
 as suggested.
 
 
 Date: Fri, 4 Jan 2013 23:49:42 -0200
 From: Marcelo Tosatti mtosa...@redhat.com
 To: Jason J. Herne jjhe...@linux.vnet.ibm.com
 Cc: Alexander Graf ag...@suse.de,
   Bhushan Bharat-R65777 r65...@freescale.com,
   Christian Borntraeger borntrae...@de.ibm.com,
   Anthony Liguori aligu...@us.ibm.com,
   qemu-devel@nongnu.org qemu-devel qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 7/7] KVM regsync: Fix
 do_kvm_cpu_synchronize_state data integrity issue
 
 On Fri, Jan 04, 2013 at 10:25:45AM -0500, Jason J. Herne wrote:
 If I've followed the conversation correctly this is what needs to be done:
 
 1. Remove the level parameters from 

Re: [Qemu-devel] [PATCH 4/7 v2] KVM regsync: Add register bitmap parameter to do_kvm_cpu_synchronize_state

2013-01-24 Thread Alexander Graf

On 16.01.2013, at 18:23, Marcelo Tosatti wrote:

 On Wed, Jan 16, 2013 at 05:00:52PM +, Bhushan Bharat-R65777 wrote:
 I think above code should be:
kvm_arch_put_registers(cpu, cpu-kvm_vcpu_dirty);
cpu-kvm_vcpu_dirty = false;
 
 so vcpu will not enter guest state with dirty registers in qemu.
 
 Not so clear - currently PUT_FULL/PUT_RESET are performed on
 pre-defined points.
 
 Unrelated:
 
 2) Also, what is the reason for specifying sets of registers in 
 arch-specific
 code? Is that because it allows PPC to fix their sync-timer register 
 problem?
 
 When you are writing generic code, what does it mean to use
 'KVM_REGSYNC_{RUNTIME,RESET,FULL}_STATE' ?
 Answer: it depends on the architecture.
 
 3) On x86, kvm_arch_get_registers(GET_FULL) must not imply
 kvm_arch_put_registers(PUT_FULL).
 
 The S/390 problem, from
 http://lists.nongnu.org/archive/html/qemu-devel/2012-11/msg02213.html:
 
  The kvm register sync needs to happen in the kvm register sync
 function :)
 That would eliminate the whole purpose of sync regs and forces us to
 have an expensive ioctl on lots of exits (again). I would prefer to
 sync the registers that we never need in qemu just here.
 
 That's why the register sync has different stages.
 
 Not the get_register. Which is called on every synchronize_state. Which 
 happen
 quite often on s390.
 
 But wait: on these S/390 codepaths, you do GET_REGS already, via
 cpu_synchronize_state.
 
 So on S/390
 
 - cpu_synchronize_state(env)
 - read any register from env
 
 Is not valid? This is what generic code assumes.
 
 
 Bhushan Bharat, the PPC problem, can you describe it clearly: from what i
 understood, an in-kernel register cannot be read/written back because that
 register value can change in the meantime. When is it necessary to write it
 back? (there is a similar problem with TSC on x86, which is fixed by only
 writing TSC on FULL_STATE arch_put_registers).
 
 There are two things:
 
 First-)
 For timer related changes on PowerPC, some registers needed to be changed 
 from QEMU, so we have to get the registers via KVM_GET_SREGS and then set 
 those registers back to KVM via KVM_SET_SREGS. cpu_synchronize_state() will 
 get registers but kvm_arch_put_registers() works on level based mechanism 
 and does not provide a good way of setting a register-set. So we wrote a 
 separate function that will push these registers back to KVM and this also 
 uses KVM_SET_SREGS ioctl. This solves what is needed for PPC.
 
 Can you describe the problem in detail? You must sync a particular
 timer register only on special conditions, not during normal
 cpu_synchronize_state() runs?

We basically have a core interrupt pending register. This register can be

  * written from kernel space when a timer expires
  * written from user space on reset
  * written from user space on watchdog expiry

 What register is that and why it cannot be synced normally? When is it
 necessary to sync it?

We need to sync it on the above 2 occasions.

Thinking about this a bit more, we're trying to keep the synchronization window 
short to not get into conflicts with the kernel timer kicking in in between. 
Imagine this race:

  * user space reads TSR
  * kernel timer expires, sets bit in TSR
  * user space writes TSR

That's why we don't want this to be synced every time. We would only set TSR 
when we reset the counter. At that point in time it doesn't hurt to lose the 
kernel timer set, because we cleared the bit anyways.

But maybe the better solution would be a special write to clear ONE_REG 
register to clear specific bits and a big hammer set ONE_REG (which we have 
already) for reset only.

That would make things easier, right? Scott, any ideas on this?


Alex




Re: [Qemu-devel] [PATCH 1/6] bochs: Fix bdrv_open() error handling

2013-01-24 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Return -errno instead of -1 on errors. While touching the
 code, fix a memory leak.

 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
  block/bochs.c |   22 +++---
  1 files changed, 15 insertions(+), 7 deletions(-)

 diff --git a/block/bochs.c b/block/bochs.c
 index 3737583..a6eb33d 100644
 --- a/block/bochs.c
 +++ b/block/bochs.c
 @@ -114,11 +114,13 @@ static int bochs_open(BlockDriverState *bs, int flags)
  int i;
  struct bochs_header bochs;
  struct bochs_header_v1 header_v1;
 +int ret;
  
  bs-read_only = 1; // no write support yet
  
 -if (bdrv_pread(bs-file, 0, bochs, sizeof(bochs)) != sizeof(bochs)) {
 -goto fail;
 +ret = bdrv_pread(bs-file, 0, bochs, sizeof(bochs));
 +if (ret  0) {
 +return ret;
  }
  
  if (strcmp(bochs.magic, HEADER_MAGIC) ||
   strcmp(bochs.type, REDOLOG_TYPE) ||
   strcmp(bochs.subtype, GROWING_TYPE) ||
   ((le32_to_cpu(bochs.version) != HEADER_VERSION) 
   (le32_to_cpu(bochs.version) != HEADER_V1))) {

I'm afraid you need to set ret here.  I wonder why the compiler didn't
flag it.

   goto fail;
   }
 @@ -138,9 +140,13 @@ static int bochs_open(BlockDriverState *bs, int flags)
  
  s-catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
  s-catalog_bitmap = g_malloc(s-catalog_size * 4);
 -if (bdrv_pread(bs-file, le32_to_cpu(bochs.header), s-catalog_bitmap,
 -   s-catalog_size * 4) != s-catalog_size * 4)
 - goto fail;
 +
 +ret = bdrv_pread(bs-file, le32_to_cpu(bochs.header), s-catalog_bitmap,
 + s-catalog_size * 4);
 +if (ret  0) {
 +goto fail;
 +}
 +
  for (i = 0; i  s-catalog_size; i++)
   le32_to_cpus(s-catalog_bitmap[i]);
  
 @@ -153,8 +159,10 @@ static int bochs_open(BlockDriverState *bs, int flags)
  
  qemu_co_mutex_init(s-lock);
  return 0;
 - fail:
 -return -1;
 +
 +fail:
 +g_free(s-catalog_bitmap);
 +return ret;
  }
  
  static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)



Re: [Qemu-devel] [PATCH 1/8] fw_cfg: Replace debug prints by tracepoints

2013-01-24 Thread Markus Armbruster
Peter Lieven p...@dlhnet.de writes:

 Am 24.01.2013 um 11:32 schrieb Markus Armbruster arm...@redhat.com:

 Peter Lieven p...@dlhnet.de writes:
 
 Latest git doesn't compile with this patch:
 
 hw/fw_cfg.c: In function 'fw_cfg_write':
 hw/fw_cfg.c:207:5: error: implicit declaration of function
 trace_fw_cfg_write' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:207:5: error: nested extern declaration of
 trace_fw_cfg_write' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_select':
 hw/fw_cfg.c:232:5: error: implicit declaration of function
 trace_fw_cfg_select' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:232:5: error: nested extern declaration of
 trace_fw_cfg_select' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_read':
 hw/fw_cfg.c:247:5: error: implicit declaration of function
 trace_fw_cfg_read' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:247:5: error: nested extern declaration of
 trace_fw_cfg_read' [-Werror=nested-externs]
 hw/fw_cfg.c: In function 'fw_cfg_add_file':
 hw/fw_cfg.c:460:13: error: implicit declaration of function
 trace_fw_cfg_add_file_dupe' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:460:13: error: nested extern declaration of
 trace_fw_cfg_add_file_dupe' [-Werror=nested-externs]
 hw/fw_cfg.c:467:5: error: implicit declaration of function
 trace_fw_cfg_add_file' [-Werror=implicit-function-declaration]
 hw/fw_cfg.c:467:5: error: nested extern declaration of
 trace_fw_cfg_add_file' [-Werror=nested-externs]
 cc1: all warnings being treated as errors
 make: *** [hw/fw_cfg.o] Error 1
 
 Compiles fine for me.
 
 What happens if you blow away your build tree and start over?
 
 In my experience, rebuilding of trace-related stuff is rather fragile...

 If I make a fresh clone of the qmu git repository it works.

I always build in a separate build directory, which I can blow away
freely.



Re: [Qemu-devel] [PATCH] s390: Add default support for SCLP console

2013-01-24 Thread Alexander Graf

On 24.01.2013, at 13:37, Andreas Färber wrote:

 Am 24.01.2013 12:23, schrieb Alexander Graf:
 The current s390 machine uses the virtio console as default console,
 but this doesn't mean that we always want to keep it that way for new
 machines.
 
 This patch introduces a way for a machine type to specify that it wants
 the default console to be an SCLP console, which is a lot closer to what
 real hardware does.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 hw/boards.h |1 +
 vl.c|   48 
 2 files changed, 49 insertions(+), 0 deletions(-)
 
 diff --git a/hw/boards.h b/hw/boards.h
 index 3ff9665..3813d4e 100644
 --- a/hw/boards.h
 +++ b/hw/boards.h
 @@ -33,6 +33,7 @@ typedef struct QEMUMachine {
 unsigned int no_serial:1,
 no_parallel:1,
 use_virtcon:1,
 +use_sclp:1,
 no_floppy:1,
 no_cdrom:1,
 no_sdcard:1;
 diff --git a/vl.c b/vl.c
 index 4ee1302..6a19a8f 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -176,6 +176,7 @@ int main(int argc, char **argv)
 #define DEFAULT_RAM_SIZE 128
 
 #define MAX_VIRTIO_CONSOLES 1
 +#define MAX_SCLP_CONSOLES 1
 
 static const char *data_dir;
 const char *bios_name = NULL;
 @@ -203,6 +204,7 @@ int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
 +CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
 @@ -271,6 +273,7 @@ static int tcg_tb_size;
 static int default_serial = 1;
 static int default_parallel = 1;
 static int default_virtcon = 1;
 +static int default_sclp = 1;
 static int default_monitor = 1;
 static int default_floppy = 1;
 static int default_cdrom = 1;
 @@ -2340,6 +2343,7 @@ struct device_config {
 DEV_VIRTCON,   /* -virtioconsole */
 DEV_DEBUGCON,  /* -debugcon */
 DEV_GDB,   /* -gdb, -s */
 +DEV_SCLP,  /* s390 sclp */
 } type;
 const char *cmdline;
 Location loc;
 @@ -2458,6 +2462,39 @@ static int virtcon_parse(const char *devname)
 return 0;
 }
 
 +static int sclp_parse(const char *devname)
 +{
 +QemuOptsList *device = qemu_find_opts(device);
 +static int index = 0;
 +char label[32];
 +QemuOpts *dev_opts;
 +
 +if (strcmp(devname, none) == 0) {
 +return 0;
 +}
 +if (index == MAX_SCLP_CONSOLES) {
 +fprintf(stderr, qemu: too many sclp consoles\n);
 +exit(1);
 +}
 +
 +assert(arch_type == QEMU_ARCH_S390X);
 +
 +dev_opts = qemu_opts_create(device, NULL, 0, NULL);
 +qemu_opt_set(dev_opts, driver, sclpconsole);
 +
 +snprintf(label, sizeof(label), sclpcon%d, index);
 +sclp_hds[index] = qemu_chr_new(label, devname, NULL);
 +if (!sclp_hds[index]) {
 +fprintf(stderr, qemu: could not connect sclp console
 + to character backend '%s'\n, devname);
 +return -1;
 +}
 +qemu_opt_set(dev_opts, chardev, label);
 +
 +index++;
 +return 0;
 +}
 +
 static int debugcon_parse(const char *devname)
 {   
 QemuOpts *opts;
 @@ -3832,6 +3869,9 @@ int main(int argc, char **argv, char **envp)
 if (!machine-use_virtcon) {
 default_virtcon = 0;
 }
 +if (!machine-use_sclp) {
 +default_sclp = 0;
 +}
 if (machine-no_floppy) {
 default_floppy = 0;
 }
 @@ -3873,11 +3913,15 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_SERIAL, mon:stdio);
 } else if (default_virtcon  default_monitor) {
 add_device_config(DEV_VIRTCON, mon:stdio);
 +} else if (default_sclp  default_monitor) {
 +add_device_config(DEV_SCLP, mon:stdio);
 } else {
 if (default_serial)
 add_device_config(DEV_SERIAL, stdio);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, stdio);
 +if (default_sclp)
 +add_device_config(DEV_SCLP, stdio);
 
 Braces.
 
 if (default_monitor)
 monitor_parse(stdio, readline);
 }
 @@ -3890,6 +3934,8 @@ int main(int argc, char **argv, char **envp)
 monitor_parse(vc:80Cx24C, readline);
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, vc:80Cx24C);
 +if (default_sclp)
 +add_device_config(DEV_SCLP, vc:80Cx24C);
 
 Braces
 
 }
 
 socket_init();
 @@ -4060,6 +4106,8 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 if (foreach_device_config(DEV_VIRTCON, virtcon_parse)  0)
 exit(1);
 +if (foreach_device_config(DEV_SCLP, sclp_parse)  0)
 +exit(1);
 
 Braces (seems you're not using a checkpatch.pl commit hook?)

I know, but I decided against braces here and above as it would make the code 
completely unreadable to have braces in some cases, but not in others.


Alex




Re: [Qemu-devel] [RESEND PATCH for 1.4 v10 0/3] char: Add CirMemCharDriver and provide QMP interface

2013-01-24 Thread Luiz Capitulino
On Thu, 24 Jan 2013 15:18:04 +0800
Lei Li li...@linux.vnet.ibm.com wrote:

 On 01/23/2013 11:47 PM, Luiz Capitulino wrote:
  On Wed, 23 Jan 2013 17:06:09 +0800
  Lei Li li...@linux.vnet.ibm.com wrote:
 
  Hi Anthony,
 
  Resubmit this series with your comments squashed in and Luiz's new
  comments fixed up. I will push console command part in another thread.
  There are two bugs in this series. QEMU started with:
 
# qemu [...] -chardev memory,id=foo,maxcapacity=4
 
  This explodes:
 
(qemu) memchar_read foo 10
 
  I'd expect to read '3uiz' in the steps below:
 
(qemu) memchar_write foo luiz3
(qemu) memchar_read foo 10
uiz3,
(qemu)
 
 Hi Luiz,
 
 Thanks very much for your time to test this series!
 I think the result shows how this algorithm works...

[...]

   -
   |  3  |  u  |  i  |  z  |
   -
 ^
 |
   prod
   cons
 
 I hope that I make it clear. :)

Yes, you're right. You're returning old data first, and that's correct
and I was wrong. Sorry for that.

Now, you do have two bugs to fix: the segfaul and the ',' which was
returned by memchar_read in my example. Apart from that, there's my
last comment about returning a full MemCharRead type when the
buffer is empty.

Then, if no new issues are introduced, this will be good to be merged.



Re: [Qemu-devel] [PATCH 2/6] cloop: Fix bdrv_open() error handling

2013-01-24 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Return -errno instead of -1 on errors. While touching the
 code, fix a memory leak.

 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
  block/cloop.c |   27 +--
  1 files changed, 17 insertions(+), 10 deletions(-)

 diff --git a/block/cloop.c b/block/cloop.c
 index 5a0d0d8..9b36063 100644
 --- a/block/cloop.c
 +++ b/block/cloop.c
 @@ -57,27 +57,32 @@ static int cloop_open(BlockDriverState *bs, int flags)
  {
  BDRVCloopState *s = bs-opaque;
  uint32_t offsets_size, max_compressed_block_size = 1, i;
 +int ret;
  
  bs-read_only = 1;
  
  /* read header */
 -if (bdrv_pread(bs-file, 128, s-block_size, 4)  4) {
 -goto cloop_close;
 +ret = bdrv_pread(bs-file, 128, s-block_size, 4);
 +if (ret  0) {
 +return ret;
  }
  s-block_size = be32_to_cpu(s-block_size);
  
 -if (bdrv_pread(bs-file, 128 + 4, s-n_blocks, 4)  4) {
 -goto cloop_close;
 +ret = bdrv_pread(bs-file, 128 + 4, s-n_blocks, 4);
 +if (ret  0) {
 +return ret;
  }
  s-n_blocks = be32_to_cpu(s-n_blocks);
  
  /* read offsets */
  offsets_size = s-n_blocks * sizeof(uint64_t);
  s-offsets = g_malloc(offsets_size);
 -if (bdrv_pread(bs-file, 128 + 4 + 4, s-offsets, offsets_size) 
 -offsets_size) {
 -goto cloop_close;
 +

Empty line visually detaches the /* read offsets */ comment from the
actual read.  Sure you want it?

 +ret = bdrv_pread(bs-file, 128 + 4 + 4, s-offsets, offsets_size);
 +if (ret  0) {
 +goto fail;
  }
 +
  for(i=0;is-n_blocks;i++) {
  s-offsets[i] = be64_to_cpu(s-offsets[i]);
  if (i  0) {
 @@ -92,7 +97,8 @@ static int cloop_open(BlockDriverState *bs, int flags)
  s-compressed_block = g_malloc(max_compressed_block_size + 1);
  s-uncompressed_block = g_malloc(s-block_size);
  if (inflateInit(s-zstream) != Z_OK) {
 -goto cloop_close;
 +ret = -EINVAL;

inflateInit() can return a number of different errors.  But your change
doesn't make things worse, and that's good enough.

 +goto fail;
  }
  s-current_block = s-n_blocks;
  
 @@ -101,8 +107,9 @@ static int cloop_open(BlockDriverState *bs, int flags)
  qemu_co_mutex_init(s-lock);
  return 0;
  
 -cloop_close:
 -return -1;
 +fail:
 +g_free(s-offsets);

What about s-compressed_block and s-uncompressed_block?

 +return ret;
  }
  
  static inline int cloop_read_block(BlockDriverState *bs, int block_num)



[Qemu-devel] [PATCH 07/11] s390: Wire up channel I/O in kvm.

2013-01-24 Thread Cornelia Huck
Trigger the code for our virtual css in case of instruction
intercepts for I/O instructions.

Handle the tsch exit for the subchannel-related part of tsch.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
---
 target-s390x/cpu.h |  11 +++
 target-s390x/kvm.c | 239 ++---
 2 files changed, 237 insertions(+), 13 deletions(-)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 778065c..ce12fa4 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -1058,6 +1058,13 @@ void QEMU_NORETURN runtime_exception(CPUS390XState *env, 
int excp,
 
 #include sysemu/kvm.h
 
+#ifdef CONFIG_KVM
+void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
+   uint16_t subchannel_nr, uint32_t io_int_parm,
+   uint32_t io_int_word);
+void kvm_s390_crw_mchk(S390CPU *cpu);
+void kvm_s390_enable_css_support(S390CPU *cpu);
+#else
 static inline void kvm_s390_io_interrupt(S390CPU *cpu,
 uint16_t subchannel_id,
 uint16_t subchannel_nr,
@@ -1068,6 +1075,10 @@ static inline void kvm_s390_io_interrupt(S390CPU *cpu,
 static inline void kvm_s390_crw_mchk(S390CPU *cpu)
 {
 }
+static inline void kvm_s390_enable_css_support(S390CPU *cpu)
+{
+}
+#endif
 
 static inline void s390_io_interrupt(S390CPU *cpu,
  uint16_t subchannel_id,
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index add6a58..e876406 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -47,9 +47,29 @@
 
 #define IPA0_DIAG   0x8300
 #define IPA0_SIGP   0xae00
-#define IPA0_PRIV   0xb200
+#define IPA0_B2 0xb200
+#define IPA0_B9 0xb900
+#define IPA0_EB 0xeb00
 
 #define PRIV_SCLP_CALL  0x20
+#define PRIV_CSCH   0x30
+#define PRIV_HSCH   0x31
+#define PRIV_MSCH   0x32
+#define PRIV_SSCH   0x33
+#define PRIV_STSCH  0x34
+#define PRIV_TSCH   0x35
+#define PRIV_TPI0x36
+#define PRIV_SAL0x37
+#define PRIV_RSCH   0x38
+#define PRIV_STCRW  0x39
+#define PRIV_STCPS  0x3a
+#define PRIV_RCHP   0x3b
+#define PRIV_SCHM   0x3c
+#define PRIV_CHSC   0x5f
+#define PRIV_SIGA   0x74
+#define PRIV_XSCH   0x76
+#define PRIV_SQBS   0x8a
+#define PRIV_EQBS   0x9c
 #define DIAG_KVM_HYPERCALL  0x500
 #define DIAG_KVM_BREAKPOINT 0x501
 
@@ -375,10 +395,123 @@ static int kvm_sclp_service_call(S390CPU *cpu, struct 
kvm_run *run,
 return 0;
 }
 
-static int handle_priv(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)
+static int kvm_handle_css_inst(S390CPU *cpu, struct kvm_run *run,
+   uint8_t ipa0, uint8_t ipa1, uint8_t ipb)
+{
+int r = 0;
+int no_cc = 0;
+CPUS390XState *env = cpu-env;
+
+if (ipa0 != 0xb2) {
+/* Not handled for now. */
+return -1;
+}
+cpu_synchronize_state(env);
+switch (ipa1) {
+case PRIV_XSCH:
+r = ioinst_handle_xsch(env, env-regs[1]);
+break;
+case PRIV_CSCH:
+r = ioinst_handle_csch(env, env-regs[1]);
+break;
+case PRIV_HSCH:
+r = ioinst_handle_hsch(env, env-regs[1]);
+break;
+case PRIV_MSCH:
+r = ioinst_handle_msch(env, env-regs[1], run-s390_sieic.ipb);
+break;
+case PRIV_SSCH:
+r = ioinst_handle_ssch(env, env-regs[1], run-s390_sieic.ipb);
+break;
+case PRIV_STCRW:
+r = ioinst_handle_stcrw(env, run-s390_sieic.ipb);
+break;
+case PRIV_STSCH:
+r = ioinst_handle_stsch(env, env-regs[1], run-s390_sieic.ipb);
+break;
+case PRIV_TSCH:
+/* We should only get tsch via KVM_EXIT_S390_TSCH. */
+fprintf(stderr, Spurious tsch intercept\n);
+break;
+case PRIV_CHSC:
+r = ioinst_handle_chsc(env, run-s390_sieic.ipb);
+break;
+case PRIV_TPI:
+/* This should have been handled by kvm already. */
+fprintf(stderr, Spurious tpi intercept\n);
+break;
+case PRIV_SCHM:
+no_cc = 1;
+r = ioinst_handle_schm(env, env-regs[1], env-regs[2],
+   run-s390_sieic.ipb);
+break;
+case PRIV_RSCH:
+r = ioinst_handle_rsch(env, env-regs[1]);
+break;
+case PRIV_RCHP:
+r = ioinst_handle_rchp(env, env-regs[1]);
+break;
+case PRIV_STCPS:
+/* We do not provide this instruction, it is suppressed. */
+no_cc = 1;
+r = 0;
+break;
+case 

Re: [Qemu-devel] [RFC] Virtio-desktop: Virtio-based virtual desktop

2013-01-24 Thread Anup Patel
On 24 January 2013 14:55, Stefan Hajnoczi stefa...@gmail.com wrote:

 On Thu, Jan 24, 2013 at 11:40:24AM +0530, Anup Patel wrote:
  IMHO, If we have something like Virtio-desktop specification then all
  possible guest OSes can have support for it and different hypervisor can
  emulate it without worrying about guest support.

 At this point x86 virtualization is mature and working with a mix of
 emulated x86 architecture pieces and virtio devices for
 performance-critical or open-ended functionality that we want to be able
 to extend.

 ARM is getting KVM and virtio-mmio support.  It will be in a similar
 position soon.

 Virtio guest drivers have not been implemented widely.  The Linux and
 Windows efforts are driven by the folks who were behind virtio from the
 start, but Solaris, FreeBSD, and others didn't really jump on the virtio
 bandwagon.

[Anup] I think other OSes will be motivated to added Virtio drivers if there
exists some think like Virtio-desktop specification that is being emulated
by
many hypervisors.


 Given this landscape, what is the advantage of doing a virtio-desktop?
 It will still need to fall back on ARM or x86 which is already being
 virtualized and emulated.

[Anup] Virtio-desktop stresses on having minimum architecture dependent
devices. Any improvements or additions in Virtio-desktop will be available
to other architectures.



 Depending on how you see it we either have virtio-desktop already or,
 if not, I think the experience with virtio adoption suggests other
 hypervisors and guest OSes will not trip over themselves to implement
 virtio-desktop.

[Anup] I believe Virtio adoption will increase by having a concrete
Virtio-desktop specification and without it Virtio devices are just another
way of para-virtualization. In fact, having Virtio-desktop support for an
OS
will enable it to run under different hypervisors.


 What's the advantage over virtualizating an existing ARM or x86 platform
 and using virtio devices where appropriate?

[Anup] With Virtio-desktop, many platforms can share lot of common
code mostly in-form of Virtio devices. We already drivers for most
Virtio devices in the mainline Linux kernel. The only missing devices are
Virtio-fb, Virtio-input, and Virtio-power from Virtio-desktop perspective.
[Anup] Further, Virtio is interface independent which means a Virtio device
can be a MMIO-based device or PCI-based device or some other form.
[Anup] Most proprietary hypervisors and Xen already have para-virtualized
devices which are similar to Virtio devices. In fact, we have wide variety
of
approaches in para-virtualization. We can think of Virtio and
Virtio-desktop as
an attempt to standardize para-virtualization in an architecture
independent and
hypervisor independent way. Of-course, implementation and performance of
Virtio devices will vary under different hypervisors.



 Stefan


--Anup


  1   2   3   >