Re: [Qemu-devel] [Resend][Seabios PATCH] don't boot from un-selected devices

2012-12-19 Thread Amos Kong
On Wed, Dec 19, 2012 at 08:38:13AM +0100, Gerd Hoffmann wrote:
 On 12/19/12 08:24, Amos Kong wrote:
  Current seabios will try to boot from selected devices first,
  if they are all failed, seabios will also try to boot from
  un-selected devices.
  
  For example:
  @ qemu-kvm -boot order=n,menu=on ...
  
  Guest will boot from network first, if it's failed, guest will try to
  boot from other un-selected devices (floppy, cdrom, disk) one by one.
  
  Sometimes, user don't want to boot from some devices. This patch changes
  seabios to boot only from selected devices.
 
 I think (i.e. I didn't test) the patch breaks booting if the user didn't
 explicitly specify a boot device.

Hi Gerd,

| #define DEFAULT_PRIO   

If we don't select some devices, their priority will always be 
 
| static int DefaultFloppyPrio = 101;
| static int DefaultCDPrio = 102;
| static int DefaultHDPrio = 103;
| static int DefaultBEVPrio= 104;
 
The priority of selected devices will be changed to above values
first, the priority might be re-changed.

However, we can judge if device is selected or not by checking if the
priority is .

. Boot guest without qemu boot option, guest will try to boot from
  network/hd/floppy/cdrom.

. If seabios ignores the order parameter of qemu, guest will also try
  to boot from network/hd/floppy/cdrom.

-- 
Amos.



Re: [Qemu-devel] [PATCH 1/2] libcacard: use LDFLAGS to produce i686 with --cpu=i386

2012-12-19 Thread Paolo Bonzini
Il 28/11/2012 10:53, Alon Levy ha scritto:
 Il 28/11/2012 10:16, Alon Levy ha scritto:
   diff --git a/roms/openbios b/roms/openbios
   index f095c85..d1d2787 16
   --- a/roms/openbios
   +++ b/roms/openbios
   @@ -1 +1 @@
   -Subproject commit f095c858136896d236931357b8d597f407286f71
   +Subproject commit d1d2787f87167edf487a60e61b9168514d5a7434
  
  This is probably unwanted.
 Yes, my bad. I'll drop it in the pull request.
 

Are you going to send it soon?

Paolo



Re: [Qemu-devel] [PULL 00/45] Include reorganization + PCI patch queue

2012-12-19 Thread Paolo Bonzini
Il 19/12/2012 03:13, Alexander Graf ha scritto:
 Does making libfdt a submodule really change things? Developers would
 still have to init the submodule. They could just as well install the
 libfdt-devel packet from their distro of choice instead :).

RHEL does not have it unfortunately.  I requested it to be added to EPEL
so that us Red Hatters can do more comprehensive testing even when
running on the enterprise distro. :)

Paolo



[Qemu-devel] [PATCH v2] qemu-kvm/pci-assign: 64 bits bar emulation

2012-12-19 Thread Xudong Hao
Enable 64 bits bar emulation.

v2 changes from v1:
- Change 0lx% to 0x%016 when print a 64 bit variable.

Test pass with the current seabios which already support 64bit pci bars.

Signed-off-by: Xudong Hao xudong@intel.com
---
 hw/kvm/pci-assign.c |   22 ++
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/hw/kvm/pci-assign.c b/hw/kvm/pci-assign.c
index 7a0998c..fb58ca9 100644
--- a/hw/kvm/pci-assign.c
+++ b/hw/kvm/pci-assign.c
@@ -46,6 +46,7 @@
 #define IORESOURCE_IRQ  0x0400
 #define IORESOURCE_DMA  0x0800
 #define IORESOURCE_PREFETCH 0x2000  /* No side effects */
+#define IORESOURCE_MEM_64   0x0010
 
 //#define DEVICE_ASSIGNMENT_DEBUG
 
@@ -442,9 +443,13 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
 
 /* handle memory io regions */
 if (cur_region-type  IORESOURCE_MEM) {
-int t = cur_region-type  IORESOURCE_PREFETCH
-? PCI_BASE_ADDRESS_MEM_PREFETCH
-: PCI_BASE_ADDRESS_SPACE_MEMORY;
+int t = PCI_BASE_ADDRESS_SPACE_MEMORY;
+if (cur_region-type  IORESOURCE_PREFETCH) {
+t |= PCI_BASE_ADDRESS_MEM_PREFETCH;
+}
+if (cur_region-type  IORESOURCE_MEM_64) {
+t |= PCI_BASE_ADDRESS_MEM_TYPE_64;
+}
 
 /* map physical memory */
 pci_dev-v_addrs[i].u.r_virtbase = mmap(NULL, cur_region-size,
@@ -468,10 +473,10 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
 (cur_region-base_addr  0xFFF);
 
 if (cur_region-size  0xFFF) {
-error_report(PCI region %d at address 0x% PRIx64  has 
- size 0x% PRIx64 , which is not a multiple of 
- 4K.  You might experience some performance hit 
- due to that.,
+error_report(PCI region %d at address 0x%016 PRIx64  has 
+ size 0x%016 PRIx64 , which is not a multiple 
+ of 4K.  You might experience some performance 
+ hit due to that.,
  i, cur_region-base_addr, cur_region-size);
 memory_region_init_io(pci_dev-v_addrs[i].real_iomem,
   slow_bar_ops, pci_dev-v_addrs[i],
@@ -632,7 +637,8 @@ again:
 rp-valid = 0;
 rp-resource_fd = -1;
 size = end - start + 1;
-flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH;
+flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH
+ | IORESOURCE_MEM_64;
 if (size == 0 || (flags  ~IORESOURCE_PREFETCH) == 0) {
 continue;
 }
-- 
1.5.5




Re: [Qemu-devel] [PATCH 1/2] hw: add isa-debug-exit device v3

2012-12-19 Thread Gerd Hoffmann
 Hello Anthony,
 
 So, there's this device that we need to get the test dev upstream to
 support kvm-unit-tests and get rid of testing qemu-kvm.git once for all.
 Hervé sent a similar patch, with some important differences (access
 sizes 1).

/me updated debug exit device so it handles all access sizes and also
has the size of the io region configurable.  So it should cover all use
cases now.

Also picked up testdev.  Updated series just posted.

cheers,
  Gerd




Re: [Qemu-devel] [PATCH 0/3] virtio: don't poll masked vectors with irqfd

2012-12-19 Thread Asias He
On 12/18/2012 08:39 PM, Michael S. Tsirkin wrote:
 At the moment when vector is masked virtio will poll it
 in userspace, even if it is handled by irqfd.
 This is done in order to update pending bits, but
 it's not really required until someone reads the pending bits.
 On the other hand this read results in extra io thread wakeups.
 
 As we only implement the pending bits as a compatibility
 feature (read - real drivers don't use it), we can defer
 the irqfd poll until the read actually happens.
 
 This does not seem to affect vhost-net speed
 in simple benchmarks but could help block: both
 vhost-blk and dataplane when using irqfd,
 and I also think this is cleaner than enabling/disabling
 notifiers all the time.
 
 This will also be the basis for future optimizations.
 
 Michael S. Tsirkin (3):
   msi: add API to get notified about pending bit poll
   msix: expose access to masked/pending state
   virtio-pci: don't poll masked vectors
 
  hw/pci/msix.c   | 19 +++
  hw/pci/msix.h   |  6 +-
  hw/pci/pci.h|  4 
  hw/vfio_pci.c   |  2 +-
  hw/virtio-pci.c | 53 +
  5 files changed, 66 insertions(+), 18 deletions(-)

The performance boost is significant here. It is close to the
result of dropping msix_fire_vector_notifier() hack.

-- 
Asias



Re: [Qemu-devel] [PATCH 3/3] virtio-pci: don't poll masked vectors

2012-12-19 Thread Asias He
On 12/18/2012 08:39 PM, Michael S. Tsirkin wrote:
 At the moment, when irqfd is in use but a vector is masked,
 qemu will poll it and handle vector masks in userspace.
 Since almost no one ever looks at the pending bits,
 it is better to defer this until pending bits
 are actually read.
 Implement this optimization using the new poll notifier.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 ---
  hw/virtio-pci.c | 52 
  1 file changed, 40 insertions(+), 12 deletions(-)
 
 diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
 index 1c03bb5..bc6b4e0 100644
 --- a/hw/virtio-pci.c
 +++ b/hw/virtio-pci.c
 @@ -509,8 +509,6 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy 
 *proxy,
  }
  return ret;
  }
 -
 -virtio_queue_set_guest_notifier_fd_handler(vq, true, true);
  return 0;
  }
  
 @@ -529,8 +527,6 @@ static void 
 kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
  if (--irqfd-users == 0) {
  kvm_irqchip_release_virq(kvm_state, irqfd-virq);
  }
 -
 -virtio_queue_set_guest_notifier_fd_handler(vq, true, false);
  }
  
  static int kvm_virtio_pci_vector_use(PCIDevice *dev, unsigned vector,
 @@ -581,7 +577,36 @@ static void kvm_virtio_pci_vector_release(PCIDevice 
 *dev, unsigned vector)
  }
  }
  
 -static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign)
 +static void kvm_virtio_pci_vector_poll(PCIDevice *dev,
 +   unsigned int vector_start,
 +   unsigned int vector_end)
 +{
 +VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
 +VirtIODevice *vdev = proxy-vdev;
 +int queue_no;
 +unsigned int vector;
 +EventNotifier *notifier;
 +VirtQueue *vq;
 +
 +for (queue_no = 0; queue_no  VIRTIO_PCI_QUEUE_MAX; queue_no++) {
 +if (!virtio_queue_get_num(vdev, queue_no)) {
 +break;
 +}
 +vector = virtio_queue_vector(vdev, queue_no);
 +if (vector  vector_start || vector = vector_end ||
 +!msix_is_masked(dev, vector)) {
 +continue;
 +}
 +vq = virtio_get_queue(vdev, queue_no);
 +notifier = virtio_queue_get_guest_notifier(vq);
 +if (event_notifier_test_and_clear(notifier)) {
 +msix_set_pending(dev, vector);
 +}
 +}
 +}
 +
 +static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,
 + bool with_irqfd)
  {
  VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
  VirtQueue *vq = virtio_get_queue(proxy-vdev, n);
 @@ -592,9 +617,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, 
 int n, bool assign)
  if (r  0) {
  return r;
  }
 -virtio_queue_set_guest_notifier_fd_handler(vq, true, false);
 +virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);

+  virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);

  } else {
 -virtio_queue_set_guest_notifier_fd_handler(vq, false, false);
 +virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);

+  virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);

Use the 'assign' variable instead of the constants?

  event_notifier_cleanup(notifier);
  }
  
 @@ -612,9 +637,11 @@ static int virtio_pci_set_guest_notifiers(DeviceState 
 *d, bool assign)
  VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
  VirtIODevice *vdev = proxy-vdev;
  int r, n;
 +bool with_irqfd = msix_enabled(proxy-pci_dev) 
 +kvm_msi_via_irqfd_enabled();
  
  /* Must unset vector notifier while guest notifier is still assigned */
 -if (kvm_msi_via_irqfd_enabled()  !assign) {
 +if (with_irqfd  !assign) {
  msix_unset_vector_notifiers(proxy-pci_dev);
  g_free(proxy-vector_irqfd);
  proxy-vector_irqfd = NULL;
 @@ -625,21 +652,22 @@ static int virtio_pci_set_guest_notifiers(DeviceState 
 *d, bool assign)
  break;
  }
  
 -r = virtio_pci_set_guest_notifier(d, n, assign);
 +r = virtio_pci_set_guest_notifier(d, n, assign,
 +  kvm_msi_via_irqfd_enabled());
  if (r  0) {
  goto assign_error;
  }
  }
  
  /* Must set vector notifier after guest notifier has been assigned */
 -if (kvm_msi_via_irqfd_enabled()  assign) {
 +if (with_irqfd  assign) {
  proxy-vector_irqfd =
  g_malloc0(sizeof(*proxy-vector_irqfd) *
msix_nr_vectors_allocated(proxy-pci_dev));
  r = msix_set_vector_notifiers(proxy-pci_dev,
kvm_virtio_pci_vector_use,
kvm_virtio_pci_vector_release,
 -  NULL);
 +  kvm_virtio_pci_vector_poll);
 

Re: [Qemu-devel] [RFC PATCH] Allow building without graphics support

2012-12-19 Thread Gerd Hoffmann
On 12/14/12 19:51, Scott Wood wrote:
 On 12/14/2012 02:13:53 AM, Gerd Hoffmann wrote:
   Hi,

  Yes, I could manually install it, though then I get to deal with
 telling
  the pixman build exactly where to install itself, and repeating the
  process for each toolchain and multilib-variant thereof.

 That part is easy too.  You just need ${cross_prefix}-pkg-config.
 A simple two-liner script which sets PKG_CONFIG_PATH, then calls
 /usr/bin/pkg-config.  That will not only work for pixman, but all
 libraries detected via pkg-config by configure.
 
 I already have that (though I can't just use ${cross_prefx} because I
 have multilib variants to account for, so I set PKG_CONFIG=... when
 running configure), due to the glib dependency.

That works too.

 That just lets pixman
 (and other libraries) be found in the QEMU build; it doesn't reduce the
 burden of building and installing pixman for all targets.

Yep.  Pixman isn't different from all other build dependencies though.

Once you have pkg-config working for your cross-build setup it should do
fine for all packages qemu depends on.

cheers,
  Gerd




[Qemu-devel] [PATCH 0/8] misc acpi updates and test devices

2012-12-19 Thread Gerd Hoffmann
  Hi,

Next round of the minor acpi update patch series.  The acpi bits are
actually unchanged.

The debug-exit device got updates.  It handles byte, word + dword
access.  Also the io region size is configurable now.

While being at it I also picked up the pc-testdev, polished it a bit
(portio list is gone, some QOM cleanups), and sticked it into the
series.

Git tree for pulling is available in case no one objects, but especially
patches 5+6 should get some review first (all others have been on the
list before and are unmodified reposts).

cheers,
  Gerd

The following changes since commit 914606d26e654d4c01bd5186f4d05e3fd445e219:

  Merge remote-tracking branch 'stefanha/trivial-patches' into staging 
(2012-12-18 15:41:43 -0600)

are available in the git repository at:

  git://git.kraxel.org/qemu acpi.1

Gerd Hoffmann (7):
  configure: also symlink *.aml files
  acpi: autoload dsdt
  apci: assign memory regions to piix4 acpi device
  apci: assign memory regions to ich9 lpc device
  switch debugcon to memory api
  add isa-debug-exit device.
  pc: remove bochs bios debug ports

Lucas Meneghel Rodrigues (1):
  hw: Add test device for unittests execution

 configure |1 +
 hw/acpi_ich9.c|6 +-
 hw/acpi_ich9.h|4 +-
 hw/acpi_piix4.c   |   20 --
 hw/debugcon.c |   31 +++--
 hw/debugexit.c|   75 
 hw/i386/Makefile.objs |3 +-
 hw/lpc_ich9.c |2 +-
 hw/pc-testdev.c   |  183 +
 hw/pc.c   |   64 ++---
 hw/pc.h   |1 +
 hw/pc_piix.c  |1 +
 hw/pc_q35.c   |1 +
 13 files changed, 332 insertions(+), 60 deletions(-)
 create mode 100644 hw/debugexit.c
 create mode 100644 hw/pc-testdev.c



Re: [Qemu-devel] [RFC PATCH] Allow building without graphics support

2012-12-19 Thread Gerd Hoffmann
  Hi,

 # ls -l /usr/bin/*-gcc
 -rwxr-xr-x. 2 root root 264112 Aug 23  2011 /usr/bin/i686-pc-mingw32-gcc
 -rwxr-xr-x. 2 root root 268216 Oct 18 18:24
 /usr/bin/x86_64-redhat-linux-gcc

 I think the second part (pc / redhat) can be choosen pretty freely
 when building gcc, so you could name your cross compilers differently,
 then have them in PATH and pick by name instead of typing full paths.
 
 For the most part I don't build these toolchains, so that's not an
 option.

Ok.

 Plus, I like having each toolchain fully contained in its own
 directory.

No need to change that, you can just stick all the directories into the
PATH.  Well, you could if the different compilers would have different
names, thats why I suggested that ...

 ./configure
 --cross-prefix=/home/scott/fsl/tc/gcc-4.5.55-eglibc-2.11.55/powerpc-linux-gnu/bin/powerpc-linux-gnu-

  make ?
 
 A few more options than that, but basically yes.
 
 I can get past this particular obstacle by doing something like:
 
 (PATH=/home/scott/.../powerpc-linux-gnu/bin:$PATH ./configure
 --cross-prefix=powerpc-linu-gnu- ...)

Why do you need this?  Any tools not picked up correctly if you don't
set the PATH?  Which ones?

 ...but then I run into the problem that --extra-cflags and
 --extra-ldflags don't get passed into pixman.

That should be fixable easily.  Have a patch for that?  If so, please
send to the list.  Otherwise I can have a look.

Why do you need --extra-cflags + --extra-ldflags btw?

cheers,
  Gerd




[Qemu-devel] [PATCH 1/8] configure: also symlink *.aml files

2012-12-19 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 configure |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 728caca..ec6f961 100755
--- a/configure
+++ b/configure
@@ -4197,6 +4197,7 @@ FILES=$FILES pc-bios/spapr-rtas/Makefile
 FILES=$FILES roms/seabios/Makefile roms/vgabios/Makefile
 for bios_file in \
 $source_path/pc-bios/*.bin \
+$source_path/pc-bios/*.aml \
 $source_path/pc-bios/*.rom \
 $source_path/pc-bios/*.dtb \
 $source_path/pc-bios/openbios-* \
-- 
1.7.1




[Qemu-devel] [PATCH 3/8] apci: assign memory regions to piix4 acpi device

2012-12-19 Thread Gerd Hoffmann
Get rid of get_system_io() usage.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi_piix4.c |   20 +---
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 0b5b0d3..30bafb6 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -57,6 +57,7 @@ struct pci_status {
 
 typedef struct PIIX4PMState {
 PCIDevice dev;
+
 MemoryRegion io;
 MemoryRegion io_gpe;
 MemoryRegion io_pci;
@@ -83,7 +84,8 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 } PIIX4PMState;
 
-static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
+static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
+   PCIBus *bus, PIIX4PMState *s);
 
 #define ACPI_ENABLE 0xf1
 #define ACPI_DISABLE 0xf0
@@ -406,11 +408,13 @@ static int piix4_pm_initfn(PCIDevice *dev)
 pci_conf[0xd2] = 0x09;
 pm_smbus_init(s-dev.qdev, s-smb);
 memory_region_set_enabled(s-smb.io, pci_conf[0xd2]  1);
-memory_region_add_subregion(get_system_io(), s-smb_io_base, s-smb.io);
+memory_region_add_subregion(pci_address_space_io(dev),
+s-smb_io_base, s-smb.io);
 
 memory_region_init(s-io, piix4-pm, 64);
 memory_region_set_enabled(s-io, false);
-memory_region_add_subregion(get_system_io(), 0, s-io);
+memory_region_add_subregion(pci_address_space_io(dev),
+0, s-io);
 
 acpi_pm_tmr_init(s-ar, pm_tmr_timer, s-io);
 acpi_pm1_evt_init(s-ar, pm_tmr_timer, s-io);
@@ -423,7 +427,8 @@ static int piix4_pm_initfn(PCIDevice *dev)
 s-machine_ready.notify = piix4_pm_machine_ready;
 qemu_add_machine_init_done_notifier(s-machine_ready);
 qemu_register_reset(piix4_reset, s);
-piix4_acpi_system_hot_add_init(dev-bus, s);
+
+piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev-bus, s);
 
 return 0;
 }
@@ -593,15 +598,16 @@ static const MemoryRegionOps piix4_pci_ops = {
 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
 PCIHotplugState state);
 
-static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
+static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
+   PCIBus *bus, PIIX4PMState *s)
 {
 memory_region_init_io(s-io_gpe, piix4_gpe_ops, s, apci-gpe0,
   GPE_LEN);
-memory_region_add_subregion(get_system_io(), GPE_BASE, s-io_gpe);
+memory_region_add_subregion(parent, GPE_BASE, s-io_gpe);
 
 memory_region_init_io(s-io_pci, piix4_pci_ops, s, apci-pci-hotplug,
   PCI_HOTPLUG_SIZE);
-memory_region_add_subregion(get_system_io(), PCI_HOTPLUG_ADDR,
+memory_region_add_subregion(parent, PCI_HOTPLUG_ADDR,
 s-io_pci);
 pci_bus_hotplug(bus, piix4_device_hotplug, s-dev.qdev);
 }
-- 
1.7.1




Re: [Qemu-devel] [PATCH 26/26] usbredir: Add support for buffered bulk input

2012-12-19 Thread Hans de Goede

Hi,

On 12/18/2012 02:36 PM, Gerd Hoffmann wrote:

   Hi,

Added patches 1-25 to the usb queue (using v2 of patch 10).


  hw/usb/redirect-ftdi-ids.h   | 1255 ++
  hw/usb/redirect-pl2303-ids.h |  150 +
  hw/usb/redirect-usb-ids.h|  910 ++


Where does this come from?  Linux kernel I guess?


These 2 are 1 on 1 copies from the kernel:

hw/usb/redirect-ftdi-ids.h   | 1255 ++
hw/usb/redirect-pl2303-ids.h |  150 +

They contain boring stuff like:

#define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */
#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */

Which allows me to easily copy the id tables from the kernel
drivers (.c files).

This one:
hw/usb/redirect-usb-ids.h

Contains the usb-id tables copied from the kernel, as stated
in the comments:

/*
 * Silicon Laboratories CP210x USB to RS232 serial adapter ids
 * copied from linux/drivers/usb/serial/cp210x.c
 *
 * Copyright (C) 2005 Craig Shelley (cr...@microtron.org.uk)
 */
{ USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */


What is the procedure to update them?


I've defined my own version of the USB_DEVICE macro, after that
the tables are just 1 on 1 copies from the kernel tree, with
s/tab//

So updating them can be done by emptying the list and then copying in
the new list from the latest kernel, this is an (easy) manual procedure
for now.


I also think this shouldn't be tied to redir, I think it is better to
have a hw/usb/quirks.c file where the device id database and helper
functions to match devices against the list are living.


Makes sense, one problem I see though is that right now I've
2 id tables, named usbredir_raw_serial_ids and usbredir_ftdi_serial_ids
since ftdi based adapters need some extra special handling (a quirk
to the quirk).

Once we start working with quirk tables it makes sense to have 1 large
table with an extra uint32_t field which contains the actual quirks as
bitmask. All perfectly sensible, but this breaks the easy copy and
paste syncing of the tables from the Linux kernel ...

So any good ideas for this from you ?

Regards,

Hans



[Qemu-devel] [PATCH 4/8] apci: assign memory regions to ich9 lpc device

2012-12-19 Thread Gerd Hoffmann
Get rid of get_system_io() usage.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi_ich9.c |6 --
 hw/acpi_ich9.h |4 +++-
 hw/lpc_ich9.c  |2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi_ich9.c b/hw/acpi_ich9.c
index c5978d3..b895422 100644
--- a/hw/acpi_ich9.c
+++ b/hw/acpi_ich9.c
@@ -201,11 +201,13 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-void ich9_pm_init(ICH9LPCPMRegs *pm, qemu_irq sci_irq, qemu_irq cmos_s3)
+void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
+  qemu_irq sci_irq, qemu_irq cmos_s3)
 {
 memory_region_init(pm-io, ich9-pm, ICH9_PMIO_SIZE);
 memory_region_set_enabled(pm-io, false);
-memory_region_add_subregion(get_system_io(), 0, pm-io);
+memory_region_add_subregion(pci_address_space_io(lpc_pci),
+0, pm-io);
 
 acpi_pm_tmr_init(pm-acpi_regs, ich9_pm_update_sci_fn, pm-io);
 acpi_pm1_evt_init(pm-acpi_regs, ich9_pm_update_sci_fn, pm-io);
diff --git a/hw/acpi_ich9.h b/hw/acpi_ich9.h
index bc221d3..ecb82ab 100644
--- a/hw/acpi_ich9.h
+++ b/hw/acpi_ich9.h
@@ -30,9 +30,11 @@ typedef struct ICH9LPCPMRegs {
  * PM1a_CNT_BLK = 2 in FADT so it is defined as uint16_t.
  */
 ACPIREGS acpi_regs;
+
 MemoryRegion io;
 MemoryRegion io_gpe;
 MemoryRegion io_smi;
+
 uint32_t smi_en;
 uint32_t smi_sts;
 
@@ -42,7 +44,7 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 } ICH9LPCPMRegs;
 
-void ich9_pm_init(ICH9LPCPMRegs *pm,
+void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq, qemu_irq cmos_s3_resume);
 void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base);
 extern const VMStateDescription vmstate_ich9_pm;
diff --git a/hw/lpc_ich9.c b/hw/lpc_ich9.c
index 878a43e..dd67b61 100644
--- a/hw/lpc_ich9.c
+++ b/hw/lpc_ich9.c
@@ -352,7 +352,7 @@ void ich9_lpc_pm_init(PCIDevice *lpc_pci, qemu_irq cmos_s3)
 qemu_irq *sci_irq;
 
 sci_irq = qemu_allocate_irqs(ich9_set_sci, lpc, 1);
-ich9_pm_init(lpc-pm, sci_irq[0], cmos_s3);
+ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0], cmos_s3);
 
 ich9_lpc_reset(lpc-d.qdev);
 }
-- 
1.7.1




[Qemu-devel] [PATCH 5/8] switch debugcon to memory api

2012-12-19 Thread Gerd Hoffmann
Also some QOM glue while being at it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/debugcon.c |   31 ---
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/hw/debugcon.c b/hw/debugcon.c
index 14ab326..3cde16c 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -29,20 +29,27 @@
 #include isa.h
 #include pc.h
 
+#define TYPE_ISA_DEBUGCON_DEVICE isa-debugcon
+#define ISA_DEBUGCON_DEVICE(obj) \
+ OBJECT_CHECK(ISADebugconState, (obj), TYPE_ISA_DEBUGCON_DEVICE)
+
 //#define DEBUG_DEBUGCON
 
 typedef struct DebugconState {
+MemoryRegion io;
 CharDriverState *chr;
 uint32_t readback;
 } DebugconState;
 
 typedef struct ISADebugconState {
-ISADevice dev;
+ISADevice parent_obj;
+
 uint32_t iobase;
 DebugconState state;
 } ISADebugconState;
 
-static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
+  unsigned width)
 {
 DebugconState *s = opaque;
 unsigned char ch = val;
@@ -55,7 +62,7 @@ static void debugcon_ioport_write(void *opaque, uint32_t 
addr, uint32_t val)
 }
 
 
-static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
 {
 DebugconState *s = opaque;
 
@@ -66,6 +73,14 @@ static uint32_t debugcon_ioport_read(void *opaque, uint32_t 
addr)
 return s-readback;
 }
 
+static const MemoryRegionOps debugcon_ops = {
+.read = debugcon_ioport_read,
+.write = debugcon_ioport_write,
+.valid.min_access_size = 1,
+.valid.max_access_size = 1,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 static void debugcon_init_core(DebugconState *s)
 {
 if (!s-chr) {
@@ -78,12 +93,14 @@ static void debugcon_init_core(DebugconState *s)
 
 static int debugcon_isa_initfn(ISADevice *dev)
 {
-ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+ISADebugconState *isa = ISA_DEBUGCON_DEVICE(dev);
 DebugconState *s = isa-state;
 
 debugcon_init_core(s);
-register_ioport_write(isa-iobase, 1, 1, debugcon_ioport_write, s);
-register_ioport_read(isa-iobase, 1, 1, debugcon_ioport_read, s);
+memory_region_init_io(s-io, debugcon_ops, s,
+  TYPE_ISA_DEBUGCON_DEVICE, 1);
+memory_region_add_subregion(isa_address_space_io(dev),
+isa-iobase, s-io);
 return 0;
 }
 
@@ -103,7 +120,7 @@ static void debugcon_isa_class_initfn(ObjectClass *klass, 
void *data)
 }
 
 static TypeInfo debugcon_isa_info = {
-.name  = isa-debugcon,
+.name  = TYPE_ISA_DEBUGCON_DEVICE,
 .parent= TYPE_ISA_DEVICE,
 .instance_size = sizeof(ISADebugconState),
 .class_init= debugcon_isa_class_initfn,
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2 1/2] pc_sysfw: Check for qemu_find_file() failure

2012-12-19 Thread Stefan Hajnoczi
On Wed, Dec 05, 2012 at 03:28:05PM +0100, Markus Armbruster wrote:
 pc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily
 creates a drive without a medium.
 
 When pc_system_flash_init() asks for its size, bdrv_getlength() fails
 with -ENOMEDIUM, which isn't checked either.  It fails relatively
 cleanly only because -ENOMEDIUM isn't a multiple of 4096:
 
 $ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
 qemu: PC system firmware (pflash) must be a multiple of 0x1000
 [Exit 1 ]
 
 Fix by handling the qemu_find_file() failure.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
 v2: Don't report errno, because that can produce misleading error
 messages.  For instance, when seabios/out/bios.bin is unreadable, we
 fall back to $data_dir/seabios/out/bios.bin, which doesn't exist, and
 then report seabios/out/bios.bin: No such file or directory.  No other
 caller reports errno.
 
  hw/pc_sysfw.c | 4 
  1 file changed, 4 insertions(+)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan



Re: [Qemu-devel] [Resend][Seabios PATCH] don't boot from un-selected devices

2012-12-19 Thread Gleb Natapov
On Wed, Dec 19, 2012 at 03:24:45PM +0800, Amos Kong wrote:
 Current seabios will try to boot from selected devices first,
 if they are all failed, seabios will also try to boot from
 un-selected devices.
 
 For example:
 @ qemu-kvm -boot order=n,menu=on ...
 
 Guest will boot from network first, if it's failed, guest will try to
 boot from other un-selected devices (floppy, cdrom, disk) one by one.
 
 Sometimes, user don't want to boot from some devices. This patch changes
And sometimes he want. The patch changes behaviour unconditionally. New
behaviour should be user selectable. Something line -boot order=strict
on qemu command line.

 seabios to boot only from selected devices.
 
 If user choose first boot device from menu, then seabios will try all
 the devices, even some of them are not selected.
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
 Resend for CCing seabios maillist.
 ---
  src/boot.c |   13 -
  1 files changed, 8 insertions(+), 5 deletions(-)
 
 diff --git a/src/boot.c b/src/boot.c
 index 3ca7960..ee810ac 100644
 --- a/src/boot.c
 +++ b/src/boot.c
 @@ -424,6 +424,10 @@ interactive_bootmenu(void)
  maxmenu++;
  printf(%d. %s\n, maxmenu
 , strtcpy(desc, pos-description, ARRAY_SIZE(desc)));
 +/* If user chooses first boot device from menu, we will treat
 + all the devices as selected. */
 +if (pos-priority == DEFAULT_PRIO)
 +pos-priority = DEFAULT_PRIO - 1;
  pos = pos-next;
  }
  
 @@ -490,7 +494,10 @@ boot_prep(void)
  
  // Map drives and populate BEV list
  struct bootentry_s *pos = BootList;
 -while (pos) {
 +
 +/* The priority of un-selected device is not changed,
 +   we only boot from user selected devices. */
 +while (pos  pos-priority != DEFAULT_PRIO) {
  switch (pos-type) {
  case IPL_TYPE_BCV:
  call_bcv(pos-vector.seg, pos-vector.offset);
 @@ -513,10 +520,6 @@ boot_prep(void)
  }
  pos = pos-next;
  }
 -
 -// If nothing added a floppy/hd boot - add it manually.
 -add_bev(IPL_TYPE_FLOPPY, 0);
 -add_bev(IPL_TYPE_HARDDISK, 0);
  }
  
  
 -- 
 1.7.1

--
Gleb.



[Qemu-devel] [PATCH 2/8] acpi: autoload dsdt

2012-12-19 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/pc.c  |   23 +++
 hw/pc.h  |1 +
 hw/pc_piix.c |1 +
 hw/pc_q35.c  |1 +
 4 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index b11e7c4..cc4b260 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -886,6 +886,29 @@ void pc_cpus_init(const char *cpu_model)
 }
 }
 
+void pc_acpi_init(const char *default_dsdt)
+{
+char *filename = NULL, *arg = NULL;
+
+if (acpi_tables != NULL) {
+/* manually set via -acpitable, leave it alone */
+return;
+}
+
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, default_dsdt);
+if (filename == NULL) {
+fprintf(stderr, WARNING: failed to find %s\n, default_dsdt);
+return;
+}
+
+arg = g_strdup_printf(file=%s, filename);
+if (acpi_table_add(arg) != 0) {
+fprintf(stderr, WARNING: failed to load %s\n, filename);
+}
+g_free(arg);
+g_free(filename);
+}
+
 void *pc_memory_init(MemoryRegion *system_memory,
 const char *kernel_filename,
 const char *kernel_cmdline,
diff --git a/hw/pc.h b/hw/pc.h
index 2237e86..9ecccbb 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -79,6 +79,7 @@ void pc_register_ferr_irq(qemu_irq irq);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
 void pc_cpus_init(const char *cpu_model);
+void pc_acpi_init(const char *default_dsdt);
 void *pc_memory_init(MemoryRegion *system_memory,
 const char *kernel_filename,
 const char *kernel_cmdline,
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 19e342a..e032474 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -87,6 +87,7 @@ static void pc_init1(MemoryRegion *system_memory,
 void *fw_cfg = NULL;
 
 pc_cpus_init(cpu_model);
+pc_acpi_init(acpi-dsdt.aml);
 
 if (kvmclock_enabled) {
 kvmclock_create();
diff --git a/hw/pc_q35.c b/hw/pc_q35.c
index 3429a9a..7a8d6fe 100644
--- a/hw/pc_q35.c
+++ b/hw/pc_q35.c
@@ -87,6 +87,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 qemu_irq *cmos_s3;
 
 pc_cpus_init(cpu_model);
+pc_acpi_init(q35-acpi-dsdt.aml);
 
 kvmclock_create();
 
-- 
1.7.1




[Qemu-devel] [PATCH 7/8] hw: Add test device for unittests execution

2012-12-19 Thread Gerd Hoffmann
From: Lucas Meneghel Rodrigues l...@redhat.com

Add a test device which supports the kvmctl ioports,
so one can run the KVM unittest suite.

Intended Usage:

qemu-system-x86_64 -nographic \
-device pc-testdev \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
-kernel /path/to/kvm/unittests/msr.flat

Where msr.flat is one of the KVM unittests, present on a
separate repo,

git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git

[ kraxel: more memory api + qom fixes ]

CC: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Alexander Graf ag...@suse.de
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/i386/Makefile.objs |1 +
 hw/pc-testdev.c   |  183 +
 2 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 hw/pc-testdev.c

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 56aaa9d..1ac5fc5 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -12,5 +12,6 @@ obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
 obj-y += kvm/
 obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
+obj-y += pc-testdev.o
 
 obj-y := $(addprefix ../,$(obj-y))
diff --git a/hw/pc-testdev.c b/hw/pc-testdev.c
new file mode 100644
index 000..1ea3c1c
--- /dev/null
+++ b/hw/pc-testdev.c
@@ -0,0 +1,183 @@
+/*
+ * QEMU x86 ISA testdev
+ *
+ * Copyright (c) 2012 Avi Kivity, Gerd Hoffmann, Marcelo Tosatti
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/*
+ * This device is used to test KVM features specific to the x86 port, such
+ * as emulation, power management, interrupt routing, among others. It's meant
+ * to be used like:
+ *
+ * qemu-system-x86_64 -device pc-testdev -serial stdio \
+ * -device isa-debug-exit,iobase=0xf4,iosize=0x4 \
+ * -kernel /home/lmr/Code/virt-test.git/kvm/unittests/msr.flat
+ *
+ * Where msr.flat is one of the KVM unittests, present on a separate repo,
+ * git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git
+*/
+
+#include sys/mman.h
+#include hw.h
+#include qdev.h
+#include isa.h
+#include exec-memory.h
+
+#define IOMEM_LEN0x1
+
+typedef struct PCTestdev {
+ISADevice parent_obj;
+
+MemoryRegion ioport;
+MemoryRegion flush;
+MemoryRegion irq;
+MemoryRegion iomem;
+uint32_t ioport_data;
+char iomem_buf[IOMEM_LEN];
+} PCTestdev;
+
+#define TYPE_TESTDEV pc-testdev
+#define TESTDEV(obj) \
+ OBJECT_CHECK(struct PCTestdev, (obj), TYPE_TESTDEV)
+
+static void test_irq_line(void *opaque, hwaddr addr, uint64_t data,
+  unsigned len)
+{
+struct PCTestdev *dev = opaque;
+struct ISADevice *isa = ISA_DEVICE(dev);
+
+qemu_set_irq(isa_get_irq(isa, addr), !!data);
+}
+
+static const MemoryRegionOps test_irq_ops = {
+.write = test_irq_line,
+.valid.min_access_size = 1,
+.valid.max_access_size = 1,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void test_ioport_write(void *opaque, hwaddr addr, uint64_t data,
+  unsigned len)
+{
+struct PCTestdev *dev = opaque;
+dev-ioport_data = data;
+}
+
+static uint64_t test_ioport_read(void *opaque, hwaddr addr, unsigned len)
+{
+struct PCTestdev *dev = opaque;
+return dev-ioport_data;
+}
+
+static const MemoryRegionOps test_ioport_ops = {
+.read = test_ioport_read,
+.write = test_ioport_write,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void test_flush_page(void *opaque, hwaddr addr, uint64_t data,
+unsigned len)
+{
+hwaddr page = 4096;
+void *a = cpu_physical_memory_map(data  ~0xffful, page, 0);
+
+/* We might not be able to get the full page, only mprotect what we 
actually
+   have mapped */
+mprotect(a, page, PROT_NONE);
+mprotect(a, 

[Qemu-devel] [PATCH 8/8] pc: remove bochs bios debug ports

2012-12-19 Thread Gerd Hoffmann
Prehistoric leftover, zap it.  We poweroff via acpi these days.

And having a port (0x501,0x502) where any random guest write will make
qemu exit -- with no way to turn it off -- is a bad joke anyway.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/pc.c |   41 -
 1 files changed, 0 insertions(+), 41 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index cc4b260..0997c72 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -524,34 +524,6 @@ static void handle_a20_line_change(void *opaque, int irq, 
int level)
 cpu_x86_set_a20(cpu, level);
 }
 
-/***/
-/* Bochs BIOS debug ports */
-
-static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
-{
-static const char shutdown_str[8] = Shutdown;
-static int shutdown_index = 0;
-
-switch(addr) {
-case 0x8900:
-/* same as Bochs power off */
-if (val == shutdown_str[shutdown_index]) {
-shutdown_index++;
-if (shutdown_index == 8) {
-shutdown_index = 0;
-qemu_system_shutdown_request();
-}
-} else {
-shutdown_index = 0;
-}
-break;
-
-case 0x501:
-case 0x502:
-exit((val  1) | 1);
-}
-}
-
 int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
 {
 int index = le32_to_cpu(e820_table.count);
@@ -569,14 +541,6 @@ int e820_add_entry(uint64_t address, uint64_t length, 
uint32_t type)
 return index;
 }
 
-static const MemoryRegionPortio bochs_bios_portio_list[] = {
-{ 0x500, 1, 1, .write = bochs_bios_write, }, /* 0x500 */
-{ 0x501, 1, 1, .write = bochs_bios_write, }, /* 0x501 */
-{ 0x501, 2, 2, .write = bochs_bios_write, }, /* 0x501 */
-{ 0x8900, 1, 1, .write = bochs_bios_write, }, /* 0x8900 */
-PORTIO_END_OF_LIST(),
-};
-
 static void *bochs_bios_init(void)
 {
 void *fw_cfg;
@@ -584,11 +548,6 @@ static void *bochs_bios_init(void)
 size_t smbios_len;
 uint64_t *numa_fw_cfg;
 int i, j;
-PortioList *bochs_bios_port_list = g_new(PortioList, 1);
-
-portio_list_init(bochs_bios_port_list, bochs_bios_portio_list,
- NULL, bochs-bios);
-portio_list_add(bochs_bios_port_list, get_system_io(), 0x0);
 
 fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
 
-- 
1.7.1




[Qemu-devel] [PATCH 6/8] add isa-debug-exit device.

2012-12-19 Thread Gerd Hoffmann
When present it makes qemu exit on any write.
Mapped to port 0x501 by default.

Without this patch Anthony doesn't allow me to
remove the bochs bios debug ports because his
test suite uses this.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/debugexit.c|   75 +
 hw/i386/Makefile.objs |2 +-
 2 files changed, 76 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugexit.c

diff --git a/hw/debugexit.c b/hw/debugexit.c
new file mode 100644
index 000..90642eb
--- /dev/null
+++ b/hw/debugexit.c
@@ -0,0 +1,75 @@
+/*
+ * debug exit port emulation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) any later version.
+ */
+
+#include hw.h
+#include isa.h
+
+#define TYPE_ISA_DEBUG_EXIT_DEVICE isa-debug-exit
+#define ISA_DEBUG_EXIT_DEVICE(obj) \
+ OBJECT_CHECK(ISADebugExitState, (obj), TYPE_ISA_DEBUG_EXIT_DEVICE)
+
+typedef struct ISADebugExitState {
+ISADevice parent_obj;
+
+uint32_t iobase;
+uint32_t iosize;
+MemoryRegion io;
+} ISADebugExitState;
+
+static void debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
+ unsigned width)
+{
+exit((val  1) | 1);
+}
+
+static const MemoryRegionOps debug_exit_ops = {
+.write = debug_exit_write,
+.valid.min_access_size = 1,
+.valid.max_access_size = 4,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static int debug_exit_initfn(ISADevice *dev)
+{
+ISADebugExitState *isa = ISA_DEBUG_EXIT_DEVICE(dev);
+
+memory_region_init_io(isa-io, debug_exit_ops, isa,
+  TYPE_ISA_DEBUG_EXIT_DEVICE, isa-iosize);
+memory_region_add_subregion(isa_address_space_io(dev),
+isa-iobase, isa-io);
+return 0;
+}
+
+static Property debug_exit_properties[] = {
+DEFINE_PROP_HEX32(iobase, ISADebugExitState, iobase, 0x501),
+DEFINE_PROP_HEX32(iosize, ISADebugExitState, iosize, 0x02),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void debug_exit_class_initfn(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ic-init = debug_exit_initfn;
+dc-props = debug_exit_properties;
+}
+
+static TypeInfo debug_exit_info = {
+.name  = TYPE_ISA_DEBUG_EXIT_DEVICE,
+.parent= TYPE_ISA_DEVICE,
+.instance_size = sizeof(ISADebugExitState),
+.class_init= debug_exit_class_initfn,
+};
+
+static void debug_exit_register_types(void)
+{
+type_register_static(debug_exit_info);
+}
+
+type_init(debug_exit_register_types)
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 0d3f6a8..56aaa9d 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -3,7 +3,7 @@ obj-y += apic_common.o apic.o kvmvapic.o
 obj-y += sga.o ioapic_common.o ioapic.o piix_pci.o
 obj-y += vmport.o
 obj-y += pci-hotplug.o smbios.o wdt_ib700.o
-obj-y += debugcon.o multiboot.o
+obj-y += debugcon.o debugexit.o multiboot.o
 obj-y += pc_piix.o
 obj-y += pc_sysfw.o
 obj-y += lpc_ich9.o q35.o pc_q35.o
-- 
1.7.1




Re: [Qemu-devel] [PATCH 26/26] usbredir: Add support for buffered bulk input

2012-12-19 Thread Gerd Hoffmann
  Hi,

 These 2 are 1 on 1 copies from the kernel:
 
 hw/usb/redirect-ftdi-ids.h   | 1255
 ++
 hw/usb/redirect-pl2303-ids.h |  150 +
 
 They contain boring stuff like:
 
 #define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */
 #define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */

We have header files copyed from linux already (linux-headers/), did you
look into placing them there?  Could be it doesn't work that easily due
to internal / user interface split of the kernel headers, but worth
checking ...

 This one:
 hw/usb/redirect-usb-ids.h
 
 Contains the usb-id tables copied from the kernel, as stated
 in the comments:

Manual process or scripted?  If case of the latter we should put the
scripts into scripts/ for easy future updates.

 So updating them can be done by emptying the list and then copying in
 the new list from the latest kernel, this is an (easy) manual procedure
 for now.

Ah, manual.  ok.

 I also think this shouldn't be tied to redir, I think it is better to
 have a hw/usb/quirks.c file where the device id database and helper
 functions to match devices against the list are living.
 
 Makes sense, one problem I see though is that right now I've
 2 id tables, named usbredir_raw_serial_ids and usbredir_ftdi_serial_ids
 since ftdi based adapters need some extra special handling (a quirk
 to the quirk).
 
 Once we start working with quirk tables it makes sense to have 1 large
 table with an extra uint32_t field which contains the actual quirks as
 bitmask. All perfectly sensible, but this breaks the easy copy and
 paste syncing of the tables from the Linux kernel ...
 
 So any good ideas for this from you ?

With a scripted update we could add the bitmask easily I guess.

But I think for now we can stick to two lists.  Just make sure
usb-quirks.c has a sensible interface.  Pass in device ids+class, get
back a quicks bitmask.  Then we can create the bitmask by just checking
which list has the device in question.

And when we figure some day this becomes too messy we can switch to a
model where where we have the quirk bits next to the devices in the
table and just do a lookup, without users noticing the change.

cheers,
  Gerd




[Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Create the virtio-pci device. This transport device will create a
virtio-pci-bus, so one VirtIODevice can be connected.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-pci.c | 130 
 hw/virtio-pci.h |  19 +
 2 files changed, 149 insertions(+)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 859a1ed..916ed7c 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1118,6 +1118,133 @@ static TypeInfo virtio_scsi_info = {
 .class_init= virtio_scsi_class_init,
 };
 
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+
+/* This is called by virtio-bus just after the device is plugged. */
+static void virtio_pci_device_plugged(void *opaque)
+{
+VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
+VirtioBusState *bus = proxy-bus;
+uint8_t *config;
+uint32_t size;
+
+/* Put the PCI IDs */
+switch (get_virtio_device_id(proxy-bus)) {
+
+
+default:
+error_report(unknown device id\n);
+break;
+
+}
+
+/*
+ * vdev shouldn't be accessed directly by virtio-pci.
+ * We will remove that at the end of the series to keep virtio-x-pci
+ * working.
+ */
+proxy-vdev = proxy-bus-vdev;
+/*
+ */
+
+config = proxy-pci_dev.config;
+if (proxy-class_code) {
+pci_config_set_class(config, proxy-class_code);
+}
+pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
+ pci_get_word(config + PCI_VENDOR_ID));
+pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy-bus));
+config[PCI_INTERRUPT_PIN] = 1;
+
+if (get_virtio_device_nvectors(bus) 
+msix_init_exclusive_bar(proxy-pci_dev,
+get_virtio_device_nvectors(bus), 1)) {
+set_virtio_device_nvectors(bus, 0);
+}
+
+proxy-pci_dev.config_write = virtio_write_config;
+
+size = VIRTIO_PCI_REGION_SIZE(proxy-pci_dev)
+ + get_virtio_device_config_len(bus);
+if (size  (size-1)) {
+size = 1  qemu_fls(size);
+}
+
+memory_region_init_io(proxy-bar, virtio_pci_config_ops, proxy,
+  virtio-pci, size);
+pci_register_bar(proxy-pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
+ proxy-bar);
+
+if (!kvm_has_many_ioeventfds()) {
+proxy-flags = ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
+}
+
+proxy-host_features |= 0x1  VIRTIO_F_NOTIFY_ON_EMPTY;
+proxy-host_features |= 0x1  VIRTIO_F_BAD_FEATURE;
+proxy-host_features = get_virtio_device_features(bus,
+  proxy-host_features);
+}
+
+/* This is called by virtio-bus just before the device is unplugged. */
+static void virtio_pci_device_unplug(void *opaque)
+{
+VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
+virtio_pci_stop_ioeventfd(dev);
+}
+
+static int virtio_pci_init(PCIDevice *pci_dev)
+{
+VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
+VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
+dev-bus = virtio_pci_bus_new(dev);
+if (k-init != NULL) {
+return k-init(dev);
+}
+return 0;
+}
+
+static void virtio_pci_exit(PCIDevice *pci_dev)
+{
+VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
+VirtioBusState *bus = VIRTIO_BUS(proxy-bus);
+BusState *qbus = BUS(proxy-bus);
+virtio_bus_destroy_device(bus);
+qbus_free(qbus);
+}
+
+static void virtio_pci_rst(DeviceState *qdev)
+{
+VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
+VirtioBusState *bus = VIRTIO_BUS(proxy-bus);
+virtio_pci_stop_ioeventfd(proxy);
+virtio_bus_reset(bus);
+msix_unuse_all_vectors(proxy-pci_dev);
+proxy-flags = ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
+}
+
+static void virtio_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+k-init = virtio_pci_init;
+k-exit = virtio_pci_exit;
+k-vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+k-revision = VIRTIO_PCI_ABI_VERSION;
+k-class_id = PCI_CLASS_OTHERS;
+dc-reset = virtio_pci_rst;
+}
+
+static const TypeInfo virtio_pci_info = {
+.name  = TYPE_VIRTIO_PCI,
+.parent= TYPE_PCI_DEVICE,
+.instance_size = sizeof(VirtIOPCIProxy),
+.class_init= virtio_pci_class_init,
+.class_size= sizeof(VirtioPCIClass),
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1144,6 +1271,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, 
void *data)
 k-set_host_notifier = virtio_pci_set_host_notifier;
 k-set_guest_notifiers = virtio_pci_set_guest_notifiers;
 k-vmstate_change = virtio_pci_vmstate_change;
+k-device_plugged = virtio_pci_device_plugged;
+k-device_unplug = virtio_pci_device_unplug;
 }
 
 static const TypeInfo virtio_pci_bus_info = {
@@ -1162,6 +1291,7 @@ static void virtio_pci_register_types(void)
 

[Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Here the virtio-blk-pci is modified for the new API. The device virtio-blk-pci
extends virtio-pci. It creates and connects a virtio-blk during the init.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-pci.c | 106 +---
 hw/virtio-pci.h |  14 +++-
 2 files changed, 53 insertions(+), 67 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 877bf38..e3a8276 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -734,26 +734,6 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice 
*vdev)
 proxy-host_features = vdev-get_features(vdev, proxy-host_features);
 }
 
-static int virtio_blk_init_pci(PCIDevice *pci_dev)
-{
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-VirtIODevice *vdev;
-
-if (proxy-class_code != PCI_CLASS_STORAGE_SCSI 
-proxy-class_code != PCI_CLASS_STORAGE_OTHER)
-proxy-class_code = PCI_CLASS_STORAGE_SCSI;
-
-vdev = virtio_blk_init(pci_dev-qdev, proxy-blk);
-if (!vdev) {
-return -1;
-}
-vdev-nvectors = proxy-nvectors;
-virtio_init_pci(proxy, vdev);
-/* make the actual value visible */
-proxy-nvectors = vdev-nvectors;
-return 0;
-}
-
 static void virtio_exit_pci(PCIDevice *pci_dev)
 {
 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -762,15 +742,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
 msix_uninit_exclusive_bar(pci_dev);
 }
 
-static void virtio_blk_exit_pci(PCIDevice *pci_dev)
-{
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-virtio_pci_stop_ioeventfd(proxy);
-virtio_blk_exit(proxy-vdev);
-virtio_exit_pci(pci_dev);
-}
-
 static int virtio_serial_init_pci(PCIDevice *pci_dev)
 {
 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -888,42 +859,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
 virtio_exit_pci(pci_dev);
 }
 
-static Property virtio_blk_properties[] = {
-DEFINE_PROP_HEX32(class, VirtIOPCIProxy, class_code, 0),
-DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
-DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf),
-DEFINE_PROP_STRING(serial, VirtIOPCIProxy, blk.serial),
-#ifdef __linux__
-DEFINE_PROP_BIT(scsi, VirtIOPCIProxy, blk.scsi, 0, true),
-#endif
-DEFINE_PROP_BIT(ioeventfd, VirtIOPCIProxy, flags, 
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32(vectors, VirtIOPCIProxy, nvectors, 2),
-DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_blk_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-k-init = virtio_blk_init_pci;
-k-exit = virtio_blk_exit_pci;
-k-vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-k-device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
-k-revision = VIRTIO_PCI_ABI_VERSION;
-k-class_id = PCI_CLASS_STORAGE_SCSI;
-dc-reset = virtio_pci_reset;
-dc-props = virtio_blk_properties;
-}
-
-static TypeInfo virtio_blk_info = {
-.name  = virtio-blk-pci,
-.parent= TYPE_PCI_DEVICE,
-.instance_size = sizeof(VirtIOPCIProxy),
-.class_init= virtio_blk_class_init,
-};
-
 static Property virtio_net_properties[] = {
 DEFINE_PROP_BIT(ioeventfd, VirtIOPCIProxy, flags, 
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
 DEFINE_PROP_UINT32(vectors, VirtIOPCIProxy, nvectors, 3),
@@ -1248,6 +1183,45 @@ static const TypeInfo virtio_pci_info = {
 .class_size= sizeof(VirtioPCIClass),
 };
 
+/* virtio-blk-pci */
+
+static Property virtio_blk_pci_properties[] = {
+DEFINE_PROP_HEX32(class, VirtIOBlkPCI, parent_obj.class_code, 0),
+DEFINE_PROP_BIT(ioeventfd, VirtIOBlkPCI, parent_obj.flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+DEFINE_PROP_UINT32(vectors, VirtIOBlkPCI, parent_obj.nvectors, 2),
+DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlkPCI, parent_obj.host_features),
+DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+DeviceState *vdev;
+VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
+vdev = qdev_create(BUS(vpci_dev-bus), virtio-blk);
+virtio_blk_set_conf(vdev, (dev-blk));
+if (qdev_init(vdev)  0) {
+return -1;
+}
+return 0;
+}
+
+static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+dc-props = virtio_blk_pci_properties;
+k-init = virtio_blk_pci_init;
+}
+
+static const TypeInfo virtio_blk_pci_info = {
+.name  = TYPE_VIRTIO_BLK_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIOBlkPCI),
+.class_init= virtio_blk_pci_class_init,
+};
+
 /* 

[Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove the function pointer in VirtIODevice, and use only
VirtioDeviceClass function pointer. It should be applied after all
the device have been refactored.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-blk.c |  5 -
 hw/virtio-pci.c |  2 +-
 hw/virtio.c | 41 ++---
 hw/virtio.h | 12 
 4 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 65932fd..fbb829e 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -628,11 +628,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
 virtio_init(vdev, virtio-blk, VIRTIO_ID_BLOCK,
 sizeof(struct virtio_blk_config));
 
-vdev-get_config = virtio_blk_update_config;
-vdev-set_config = virtio_blk_set_config;
-vdev-get_features = virtio_blk_get_features;
-vdev-set_status = virtio_blk_set_status;
-vdev-reset = virtio_blk_reset;
 s-bs = blk-conf.bs;
 s-conf = blk-conf;
 virtio_blk_set_conf(qdev, blk);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index e3a8276..cdc3473 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -262,7 +262,7 @@ static void virtio_ioport_write(void *opaque, uint32_t 
addr, uint32_t val)
 case VIRTIO_PCI_GUEST_FEATURES:
/* Guest does not negotiate properly?  We have to assume nothing. */
if (val  (1  VIRTIO_F_BAD_FEATURE)) {
-val = vdev-bad_features ? vdev-bad_features(vdev) : 0;
+val = get_virtio_device_bad_features(proxy-bus);
}
 virtio_set_features(vdev, val);
 break;
diff --git a/hw/virtio.c b/hw/virtio.c
index e40fa12..82bf3dd 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
 
 void virtio_set_status(VirtIODevice *vdev, uint8_t val)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 trace_virtio_set_status(vdev, val);
 
-if (vdev-set_status) {
-vdev-set_status(vdev, val);
+if (k-set_status) {
+k-set_status(vdev, val);
 }
 vdev-status = val;
 }
@@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
 void virtio_reset(void *opaque)
 {
 VirtIODevice *vdev = opaque;
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 int i;
 
 virtio_set_status(vdev, 0);
 
-if (vdev-reset)
-vdev-reset(vdev);
+if (k-reset) {
+k-reset(vdev);
+}
 
 vdev-guest_features = 0;
 vdev-queue_sel = 0;
@@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
 
 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint8_t val;
 
-vdev-get_config(vdev, vdev-config);
+k-get_config(vdev, vdev-config);
 
 if (addr  (vdev-config_len - sizeof(val)))
 return (uint32_t)-1;
@@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t 
addr)
 
 uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint16_t val;
 
-vdev-get_config(vdev, vdev-config);
+k-get_config(vdev, vdev-config);
 
 if (addr  (vdev-config_len - sizeof(val)))
 return (uint32_t)-1;
@@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t 
addr)
 
 uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint32_t val;
 
-vdev-get_config(vdev, vdev-config);
+k-get_config(vdev, vdev-config);
 
 if (addr  (vdev-config_len - sizeof(val)))
 return (uint32_t)-1;
@@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t 
addr)
 
 void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint8_t val = data;
 
 if (addr  (vdev-config_len - sizeof(val)))
@@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t 
addr, uint32_t data)
 
 stb_p(vdev-config + addr, val);
 
-if (vdev-set_config)
-vdev-set_config(vdev, vdev-config);
+if (k-set_config)
+k-set_config(vdev, vdev-config);
 }
 
 void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint16_t val = data;
 
 if (addr  (vdev-config_len - sizeof(val)))
@@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t 
addr, uint32_t data)
 
 stw_p(vdev-config + addr, val);
 
-if (vdev-set_config)
-vdev-set_config(vdev, vdev-config);
+if (k-set_config)
+k-set_config(vdev, vdev-config);
 }
 
 void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint32_t val = data;
 
 if (addr  

[Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

The qdev field is not needed, just drop it.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 93b9746..65932fd 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -33,7 +33,6 @@ typedef struct VirtIOBlock
 BlockConf *conf;
 VirtIOBlkConf blk;
 unsigned short sector_mask;
-DeviceState *qdev;
 } VirtIOBlock;
 
 typedef struct VirtIOBlockReq
@@ -643,7 +642,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
 s-vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
 
 qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
-s-qdev = qdev;
 register_savevm(qdev, virtio-blk, virtio_blk_id++, 2,
 virtio_blk_save, virtio_blk_load, s);
 bdrv_set_dev_ops(s-bs, virtio_block_ops, s);
@@ -658,7 +656,7 @@ static int virtio_blk_device_exit(DeviceState *dev)
 {
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 VirtIOBlock *s = VIRTIO_BLK(dev);
-unregister_savevm(s-qdev, virtio-blk, s);
+unregister_savevm(dev, virtio-blk, s);
 blockdev_mark_auto_del(s-bs);
 virtio_common_cleanup(vdev);
 return 0;
-- 
1.7.11.7




[Qemu-devel] [PATCH 0/3] HMP: enable info sub command taking parameter

2012-12-19 Thread Wenchao Xia
  This serial of patch will enhance HMP's info command, make all command
possible to take additional parameter. Please review to see if it have
problem.

Wenchao Xia (3):
  HMP: add QDict to info callback handler
  HMP: pass in parameter for info sub command
  HMP: show internal snapshots on a single device

 hmp-commands.hx |2 +-
 hmp.c   |   36 
 hmp.h   |   36 
 hw/i8259.c  |4 +-
 hw/lm32_pic.c   |4 +-
 hw/lm32_pic.h   |4 +-
 hw/loader.c |2 +-
 hw/loader.h |3 +-
 hw/pc.h |4 +-
 hw/pcmcia.h |2 +-
 hw/qdev-monitor.c   |4 +-
 hw/qdev-monitor.h   |4 +-
 hw/sun4m.c  |4 +-
 hw/sun4m.h  |4 +-
 hw/usb.h|2 +-
 hw/usb/bus.c|2 +-
 hw/usb/host-bsd.c   |2 +-
 hw/usb/host-linux.c |2 +-
 hw/usb/host-stub.c  |2 +-
 monitor.c   |  115 +--
 net.c   |2 +-
 net.h   |2 +-
 net/slirp.c |2 +-
 net/slirp.h |2 +-
 savevm.c|   55 -
 sysemu.h|4 +-
 vl.c|2 +-
 27 files changed, 197 insertions(+), 110 deletions(-)





[Qemu-devel] [PATCH 1/3] HMP: add QDict to info callback handler

2012-12-19 Thread Wenchao Xia
  This patch change all info call back function to take
additional QDict * parameter, which allow those command
take parameter.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 hmp.c   |   36 ++--
 hmp.h   |   36 ++--
 hw/i8259.c  |4 ++--
 hw/lm32_pic.c   |4 ++--
 hw/lm32_pic.h   |4 ++--
 hw/loader.c |2 +-
 hw/loader.h |3 ++-
 hw/pc.h |4 ++--
 hw/pcmcia.h |2 +-
 hw/qdev-monitor.c   |4 ++--
 hw/qdev-monitor.h   |4 ++--
 hw/sun4m.c  |4 ++--
 hw/sun4m.h  |4 ++--
 hw/usb.h|2 +-
 hw/usb/bus.c|2 +-
 hw/usb/host-bsd.c   |2 +-
 hw/usb/host-linux.c |2 +-
 hw/usb/host-stub.c  |2 +-
 monitor.c   |   32 
 net.c   |2 +-
 net.h   |2 +-
 net/slirp.c |2 +-
 net/slirp.h |2 +-
 savevm.c|2 +-
 sysemu.h|4 ++--
 vl.c|2 +-
 26 files changed, 85 insertions(+), 84 deletions(-)

diff --git a/hmp.c b/hmp.c
index 180ba2b..0aab1d8 100644
--- a/hmp.c
+++ b/hmp.c
@@ -30,7 +30,7 @@ static void hmp_handle_error(Monitor *mon, Error **errp)
 }
 }
 
-void hmp_info_name(Monitor *mon)
+void hmp_info_name(Monitor *mon, const QDict *qdict)
 {
 NameInfo *info;
 
@@ -41,7 +41,7 @@ void hmp_info_name(Monitor *mon)
 qapi_free_NameInfo(info);
 }
 
-void hmp_info_version(Monitor *mon)
+void hmp_info_version(Monitor *mon, const QDict *qdict)
 {
 VersionInfo *info;
 
@@ -54,7 +54,7 @@ void hmp_info_version(Monitor *mon)
 qapi_free_VersionInfo(info);
 }
 
-void hmp_info_kvm(Monitor *mon)
+void hmp_info_kvm(Monitor *mon, const QDict *qdict)
 {
 KvmInfo *info;
 
@@ -69,7 +69,7 @@ void hmp_info_kvm(Monitor *mon)
 qapi_free_KvmInfo(info);
 }
 
-void hmp_info_status(Monitor *mon)
+void hmp_info_status(Monitor *mon, const QDict *qdict)
 {
 StatusInfo *info;
 
@@ -88,7 +88,7 @@ void hmp_info_status(Monitor *mon)
 qapi_free_StatusInfo(info);
 }
 
-void hmp_info_uuid(Monitor *mon)
+void hmp_info_uuid(Monitor *mon, const QDict *qdict)
 {
 UuidInfo *info;
 
@@ -97,7 +97,7 @@ void hmp_info_uuid(Monitor *mon)
 qapi_free_UuidInfo(info);
 }
 
-void hmp_info_chardev(Monitor *mon)
+void hmp_info_chardev(Monitor *mon, const QDict *qdict)
 {
 ChardevInfoList *char_info, *info;
 
@@ -110,7 +110,7 @@ void hmp_info_chardev(Monitor *mon)
 qapi_free_ChardevInfoList(char_info);
 }
 
-void hmp_info_mice(Monitor *mon)
+void hmp_info_mice(Monitor *mon, const QDict *qdict)
 {
 MouseInfoList *mice_list, *mouse;
 
@@ -130,7 +130,7 @@ void hmp_info_mice(Monitor *mon)
 qapi_free_MouseInfoList(mice_list);
 }
 
-void hmp_info_migrate(Monitor *mon)
+void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 {
 MigrationInfo *info;
 MigrationCapabilityStatusList *caps, *cap;
@@ -208,7 +208,7 @@ void hmp_info_migrate(Monitor *mon)
 qapi_free_MigrationCapabilityStatusList(caps);
 }
 
-void hmp_info_migrate_capabilities(Monitor *mon)
+void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
 {
 MigrationCapabilityStatusList *caps, *cap;
 
@@ -227,13 +227,13 @@ void hmp_info_migrate_capabilities(Monitor *mon)
 qapi_free_MigrationCapabilityStatusList(caps);
 }
 
-void hmp_info_migrate_cache_size(Monitor *mon)
+void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
 {
 monitor_printf(mon, xbzrel cache size: % PRId64  kbytes\n,
qmp_query_migrate_cache_size(NULL)  10);
 }
 
-void hmp_info_cpus(Monitor *mon)
+void hmp_info_cpus(Monitor *mon, const QDict *qdict)
 {
 CpuInfoList *cpu_list, *cpu;
 
@@ -271,7 +271,7 @@ void hmp_info_cpus(Monitor *mon)
 qapi_free_CpuInfoList(cpu_list);
 }
 
-void hmp_info_block(Monitor *mon)
+void hmp_info_block(Monitor *mon, const QDict *qdict)
 {
 BlockInfoList *block_list, *info;
 
@@ -325,7 +325,7 @@ void hmp_info_block(Monitor *mon)
 qapi_free_BlockInfoList(block_list);
 }
 
-void hmp_info_blockstats(Monitor *mon)
+void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
 {
 BlockStatsList *stats_list, *stats;
 
@@ -359,7 +359,7 @@ void hmp_info_blockstats(Monitor *mon)
 qapi_free_BlockStatsList(stats_list);
 }
 
-void hmp_info_vnc(Monitor *mon)
+void hmp_info_vnc(Monitor *mon, const QDict *qdict)
 {
 VncInfo *info;
 Error *err = NULL;
@@ -405,7 +405,7 @@ out:
 qapi_free_VncInfo(info);
 }
 
-void hmp_info_spice(Monitor *mon)
+void hmp_info_spice(Monitor *mon, const QDict *qdict)
 {
 SpiceChannelList *chan;
 SpiceInfo *info;
@@ -452,7 +452,7 @@ out:
 qapi_free_SpiceInfo(info);
 }
 
-void hmp_info_balloon(Monitor *mon)
+void hmp_info_balloon(Monitor *mon, const QDict *qdict)
 {
 BalloonInfo *info;
 Error *err = NULL;
@@ -569,7 +569,7 @@ static void hmp_info_pci_device(Monitor *mon, const 

[Qemu-devel] [PATCH 2/3] HMP: pass in parameter for info sub command

2012-12-19 Thread Wenchao Xia
  This patch enable sub info command handler getting meaningful
parameter.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 hmp-commands.hx |2 +-
 monitor.c   |   79 +++
 2 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 010b8c9..667fab8 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1486,7 +1486,7 @@ ETEXI
 
 {
 .name   = info,
-.args_type  = item:s?,
+.args_type  = item:S?,
 .params = [subcommand],
 .help   = show various information about the system state,
 .mhandler.cmd = do_info,
diff --git a/monitor.c b/monitor.c
index 797680f..ce0e74d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -464,6 +464,11 @@ QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != 
QEVENT_MAX)
 MonitorEventState monitor_event_state[QEVENT_MAX];
 QemuMutex monitor_event_state_lock;
 
+static const mon_cmd_t *monitor_parse_command(Monitor *mon,
+  const char *cmdline,
+  const mon_cmd_t *table,
+  QDict *qdict);
+
 /*
  * Emits the event to every monitor instance
  */
@@ -809,26 +814,29 @@ static void user_async_cmd_handler(Monitor *mon, const 
mon_cmd_t *cmd,
 static void do_info(Monitor *mon, const QDict *qdict)
 {
 const mon_cmd_t *cmd;
+QDict *qdict_info;
 const char *item = qdict_get_try_str(qdict, item);
 
 if (!item) {
 goto help;
 }
 
-for (cmd = info_cmds; cmd-name != NULL; cmd++) {
-if (compare_cmd(item, cmd-name))
-break;
-}
+qdict_info = qdict_new();
 
-if (cmd-name == NULL) {
-goto help;
+cmd = monitor_parse_command(mon, item, info_cmds, qdict_info);
+if (!cmd) {
+QDECREF(qdict_info);
+/* don't help here, to avoid error message got ignored */
+return;
 }
 
-cmd-mhandler.info(mon, NULL);
+cmd-mhandler.info(mon, qdict_info);
+QDECREF(qdict_info);
 return;
 
 help:
 help_cmd(mon, info);
+return;
 }
 
 CommandInfoList *qmp_query_commands(Error **errp)
@@ -3534,18 +3542,15 @@ static const mon_cmd_t *search_dispatch_table(const 
mon_cmd_t *disp_table,
 return NULL;
 }
 
-static const mon_cmd_t *monitor_find_command(const char *cmdname)
+static const mon_cmd_t *monitor_find_command(const char *cmdname,
+ const mon_cmd_t *table)
 {
-return search_dispatch_table(mon_cmds, cmdname);
-}
-
-static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
-{
-return search_dispatch_table(qmp_cmds, cmdname);
+return search_dispatch_table(table, cmdname);
 }
 
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
   const char *cmdline,
+  const mon_cmd_t *table,
   QDict *qdict)
 {
 const char *p, *typestr;
@@ -3564,7 +3569,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
 if (!p)
 return NULL;
 
-cmd = monitor_find_command(cmdname);
+cmd = monitor_find_command(cmdname, table);
 if (!cmd) {
 monitor_printf(mon, unknown command: '%s'\n, cmdname);
 return NULL;
@@ -3872,6 +3877,31 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
 }
 }
 break;
+case 'S':
+{
+/* package all remaining string */
+int len;
+
+while (qemu_isspace(*p)) {
+p++;
+}
+if (*typestr == '?') {
+typestr++;
+if (*p == '\0') {
+/* no remaining string: NULL argument */
+break;
+}
+}
+len = strlen(p);
+if (len = 0) {
+monitor_printf(mon, %s: string expected\n,
+   cmdname);
+break;
+}
+qdict_put(qdict, key, qstring_from_str(p));
+p += len;
+}
+break;
 default:
 bad_type:
 monitor_printf(mon, %s: unknown type '%c'\n, cmdname, c);
@@ -3925,7 +3955,7 @@ static void handle_user_command(Monitor *mon, const char 
*cmdline)
 
 qdict = qdict_new();
 
-cmd = monitor_parse_command(mon, cmdline, qdict);
+cmd = monitor_parse_command(mon, cmdline, mon_cmds, qdict);
 if (!cmd)
 goto out;
 
@@ -4144,12 +4174,7 @@ static void monitor_find_completion(const char *cmdline)
 break;
 case 's':
 /* XXX: more generic ? */
-if (!strcmp(cmd-name, info)) {
-readline_set_completion_index(cur_mon-rs, strlen(str));
-  

[Qemu-devel] [PATCH 3/3] HMP: show internal snapshots on a single device

2012-12-19 Thread Wenchao Xia
  This patch add an option to show snapshots on a single block
device, so some snapshot do not exist on other block device
could be shown.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 monitor.c |6 +++---
 savevm.c  |   55 ++-
 2 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index ce0e74d..b019618 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2613,9 +2613,9 @@ static mon_cmd_t info_cmds[] = {
 },
 {
 .name   = snapshots,
-.args_type  = ,
-.params = ,
-.help   = show the currently saved VM snapshots,
+.args_type  = device:B?,
+.params = [device],
+.help   = show snapshots of whole vm or a single device,
 .mhandler.info = do_info_snapshots,
 },
 {
diff --git a/savevm.c b/savevm.c
index fa32171..438eb24 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2358,7 +2358,7 @@ void do_delvm(Monitor *mon, const QDict *qdict)
 }
 }
 
-void do_info_snapshots(Monitor *mon, const QDict *qdict)
+static void do_info_snapshots_vm(Monitor *mon)
 {
 BlockDriverState *bs, *bs1;
 QEMUSnapshotInfo *sn_tab, *sn, s, *sn_info = s;
@@ -2422,6 +2422,59 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
 
 }
 
+static void do_info_snapshots_blk(Monitor *mon, const char *device)
+{
+BlockDriverState *bs;
+QEMUSnapshotInfo *sn_tab, *sn;
+int nb_sns, i;
+char buf[256];
+
+/* find the target bs */
+bs = bdrv_find(device);
+if (!bs) {
+monitor_printf(mon, Device '%s' not found.\n, device);
+return ;
+}
+
+if (!bdrv_can_snapshot(bs)) {
+monitor_printf(mon, Device '%s' can't have snapshot.\n, device);
+return ;
+}
+
+nb_sns = bdrv_snapshot_list(bs, sn_tab);
+if (nb_sns  0) {
+monitor_printf(mon, Device %s bdrv_snapshot_list: error %d\n,
+   device, nb_sns);
+return;
+}
+
+if (nb_sns == 0) {
+monitor_printf(mon, There is no snapshot available.\n);
+return;
+}
+
+monitor_printf(mon, Device %s:\n, device);
+monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+for (i = 0; i  nb_sns; i++) {
+sn = sn_tab[i];
+monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), sn));
+}
+g_free(sn_tab);
+return;
+}
+
+void do_info_snapshots(Monitor *mon, const QDict *qdict)
+{
+/* Todo, there should be a layer rebuild qdict before enter this func. */
+const char *device = qdict_get_try_str(qdict, device);
+if (!device) {
+do_info_snapshots_vm(mon);
+} else {
+do_info_snapshots_blk(mon, device);
+}
+return;
+}
+
 void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
 {
 qemu_ram_set_idstr(memory_region_get_ram_addr(mr)  TARGET_PAGE_MASK,
-- 
1.7.1





[Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Create the virtio-device which is abstract. All the virtio-device can extend
this class.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio.c | 70 ++---
 hw/virtio.h | 31 +++
 2 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index f40a8c5..e40fa12 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -16,6 +16,7 @@
 #include trace.h
 #include qemu-error.h
 #include virtio.h
+#include virtio-bus.h
 #include qemu-barrier.h
 
 /* The alignment to use between consumer and producer parts of vring.
@@ -875,11 +876,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 return 0;
 }
 
-void virtio_cleanup(VirtIODevice *vdev)
+void virtio_common_cleanup(VirtIODevice *vdev)
 {
 qemu_del_vm_change_state_handler(vdev-vmstate);
 g_free(vdev-config);
 g_free(vdev-vq);
+}
+
+void virtio_cleanup(VirtIODevice *vdev)
+{
+virtio_common_cleanup(vdev);
 g_free(vdev);
 }
 
@@ -902,14 +908,10 @@ static void virtio_vmstate_change(void *opaque, int 
running, RunState state)
 }
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size)
+void virtio_init(VirtIODevice *vdev, const char *name,
+ uint16_t device_id, size_t config_size)
 {
-VirtIODevice *vdev;
 int i;
-
-vdev = g_malloc0(struct_size);
-
 vdev-device_id = device_id;
 vdev-status = 0;
 vdev-isr = 0;
@@ -917,20 +919,28 @@ VirtIODevice *virtio_common_init(const char *name, 
uint16_t device_id,
 vdev-config_vector = VIRTIO_NO_VECTOR;
 vdev-vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
 vdev-vm_running = runstate_is_running();
-for(i = 0; i  VIRTIO_PCI_QUEUE_MAX; i++) {
+for (i = 0; i  VIRTIO_PCI_QUEUE_MAX; i++) {
 vdev-vq[i].vector = VIRTIO_NO_VECTOR;
 vdev-vq[i].vdev = vdev;
 }
 
 vdev-name = name;
 vdev-config_len = config_size;
-if (vdev-config_len)
+if (vdev-config_len) {
 vdev-config = g_malloc0(config_size);
-else
+} else {
 vdev-config = NULL;
+}
+vdev-vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
+ vdev);
+}
 
-vdev-vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, 
vdev);
-
+VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
+ size_t config_size, size_t struct_size)
+{
+VirtIODevice *vdev;
+vdev = g_malloc0(struct_size);
+virtio_init(vdev, name, device_id, config_size);
 return vdev;
 }
 
@@ -1056,3 +1066,39 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue 
*vq)
 {
 return vq-host_notifier;
 }
+
+static int virtio_device_init(DeviceState *qdev)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
+assert(k-init != NULL);
+if (k-init(vdev)  0) {
+return -1;
+}
+virtio_bus_plug_device(vdev);
+return 0;
+}
+
+static void virtio_device_class_init(ObjectClass *klass, void *data)
+{
+/* Set the default value here. */
+DeviceClass *dc = DEVICE_CLASS(klass);
+dc-init = virtio_device_init;
+dc-bus_type = TYPE_VIRTIO_BUS;
+}
+
+static const TypeInfo virtio_device_info = {
+.name = TYPE_VIRTIO_DEVICE,
+.parent = TYPE_DEVICE,
+.instance_size = sizeof(VirtIODevice),
+.class_init = virtio_device_class_init,
+.abstract = true,
+.class_size = sizeof(VirtioDeviceClass),
+};
+
+static void virtio_register_types(void)
+{
+type_register_static(virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio.h b/hw/virtio.h
index 7c17f7b..98596a9 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -108,8 +108,17 @@ typedef struct {
 
 #define VIRTIO_NO_VECTOR 0x
 
+#define TYPE_VIRTIO_DEVICE virtio-device
+#define VIRTIO_DEVICE_GET_CLASS(obj) \
+OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE_CLASS(klass) \
+OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE(obj) \
+OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
+
 struct VirtIODevice
 {
+DeviceState parent_obj;
 const char *name;
 uint8_t status;
 uint8_t isr;
@@ -119,6 +128,10 @@ struct VirtIODevice
 void *config;
 uint16_t config_vector;
 int nvectors;
+/*
+ * Will be removed ( at the end of the series ) as we have it in
+ * VirtioDeviceClass.
+ */
 uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
 uint32_t (*bad_features)(VirtIODevice *vdev);
 void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -126,6 +139,7 @@ struct VirtIODevice
 void (*set_config)(VirtIODevice *vdev, const uint8_t 

[Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the new API.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Here the virtio-blk-s390 is modified for the new API. The device virtio-blk-s390
extends virtio-s390-device. It creates and connects a virtio-blk during the
init.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390-virtio-bus.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 849adab..eba4f3f 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -165,14 +165,13 @@ static int s390_virtio_net_init(VirtIOS390Device *dev)
 
 static int s390_virtio_blk_init(VirtIOS390Device *dev)
 {
-VirtIODevice *vdev;
-
-vdev = virtio_blk_init((DeviceState *)dev, dev-blk);
-if (!vdev) {
+DeviceState *vdev;
+vdev = qdev_create(BUS(dev-bus), virtio-blk);
+virtio_blk_set_conf(vdev, (dev-blk));
+if (qdev_init(vdev)  0) {
 return -1;
 }
-
-return s390_virtio_device_init(dev, vdev);
+return s390_virtio_device_init(dev, VIRTIO_DEVICE(vdev));
 }
 
 static int s390_virtio_serial_init(VirtIOS390Device *dev)
-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_v8


The new modifications :
* start the s390-virtio-bus refactoring.
* add some virtio cleanup as moving VirtioBindings to VirtioBusClass and
  moving the VirtIODevice function pointers to VirtioDeviceClass, it breaks
  everything as all the device have not been refactored in this RFC.

For testing just remove the three last steps.

Is the s390 modifications working and making sense ?


Changes v7 - v8:
* Moved virtio-blk-pci PCI IDs to Add the virtio-blk device..
* virtio : Added virtio_device_init which init children and plug the device.
* virtio : Added virtio_common_cleanup in the same way as
  virtio_common_init.
* virtio-blk : Moved virtio_plug_device to virtio-device init.
* virtio-blk : Inline the virtio_blk_exit function in
  virtio_blk_device_exit and use virtio_common_cleanup.
* virtio-s390-bus : Added virtio-s390-bus.
* virtio-s390-device : Added a virtio-s390-bus.
* virtio-blk-s390 : Switched to the new API.
* virtio : removed function pointer.
* virtio : removed VirtinBindings.
* virtio : cleaned up init and exit function.

Changes v6 - v7:
* virtio-bus : Added virtio-bus-reset.
* virtio-pci : Fixed virtio-pci-exit.
* virtio-pci : Added virtio-pci-rst.
* virtio-pci : Added VirtioPCIClass filled with an init function.
* virtio-blk : Added virtio_blk_set_conf.
* virtio-blk : QOM casts.
* virtio-blk-pci : Switched to the new API.

Changes v5 - v6:
* Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to
  allocate and call virtio_init. Drop the unused structure size parameters.
* Renamed init/exit callback in VirtioBusClass.
* Renamed virtio_blk_init virtio_blk_common_init.
* Modified virtio_blk_init to call virtio_blk_common_init.

Changes v4 - v5:
* use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for
  the maximum device limitation. ( Peter )
* Removed bus_in_use function. We assume that the virtio-bus is not in use,
  when plugin in. ( Peter )
* Added virtio_bus_destroy_device().
* Implemented the exit function of virtio-pci.
* Implemented the init callback for virtio-pci ( must be modified, it still
  access vdev directly. ).
* Implemented the exit callback for virtio-pci.
* Started virtio-device refactoring.
* Started virtio-blk refactoring. 

Changes v3 - v4:
* Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
* *const* TypeInfo in virtio-bus.
* Introduced virtio-pci-bus.
* Reintroduced virtio-pci.
* Introduced virtio-device.
* Started virtio-blk refactoring.
* Added an error type in qerror.h for the bus full error.

Changes v2 - v3:
* Added VirtioBusClass.
* Renamed VirtioBus - VirtioBusState.
* Renamed qbus - parent_obj.
* Plug the device only in a non-full bus.

Changes v1 - v2:
* All the little fix you suggest ( License, Debug printf, naming convention,
  ...)
* Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus
  structure.
* Added virtio_bus_reset().
* Added cast macros VIRTIO_BUS.
* Added virtio_bus_plug_device.
* Replaced the old-style bus-qbus by BUS() macro.

Fred.

KONRAD Frederic (15):
  qdev : add a maximum device allowed field for the bus.
  virtio-bus : Introduce virtio-bus
  virtio-pci-bus : Introduce virtio-pci-bus.
  virtio-pci : Refactor virtio-pci device.
  virtio-device : Refactor virtio-device.
  virtio-s390-bus : Add virtio-s390-bus.
  virtio-s390-device : create a virtio-s390-bus during init.
  virtio-blk : Add the virtio-blk device.
  virtio-blk-pci : Switch to new API.
  virtio-blk-s390 : Switch to the new API.
  virtio-blk : cleanup : use QOM cast.
  virtio-blk : cleanup : remove qdev field.
  virtio : Remove the function pointer.
  virtio : Remove VirtIOBindings.
  virtio : cleanup : init and exit function.

 hw/Makefile.objs |   1 +
 hw/qdev-core.h   |   2 +
 hw/qdev-monitor.c|  11 ++
 hw/s390-virtio-bus.c |  41 ++--
 hw/s390-virtio-bus.h |  14 +++
 hw/virtio-blk.c  | 129 +++-
 hw/virtio-blk.h  |  21 
 hw/virtio-bus.c  | 149 +++
 hw/virtio-bus.h  |  92 +
 hw/virtio-pci.c  | 278 ++-
 hw/virtio-pci.h  |  52 +-
 hw/virtio.c  | 154 ++--
 hw/virtio.h  |  52 +-
 13 files changed, 793 insertions(+), 203 deletions(-)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h

-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Add a max_dev field to BusState to specify the maximum amount of devices allowed
on the bus ( have no effect if max_dev=0 )

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/qdev-core.h|  2 ++
 hw/qdev-monitor.c | 11 +++
 2 files changed, 13 insertions(+)

diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index d672cca..af909b9 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -104,6 +104,8 @@ struct BusState {
 const char *name;
 int allow_hotplug;
 int max_index;
+/* maximum devices allowed on the bus, 0 : no limit. */
+int max_dev;
 QTAILQ_HEAD(ChildrenHead, BusChild) children;
 QLIST_ENTRY(BusState) sibling;
 };
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index a1b4d6a..7a9d275 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const 
char *name,
 if (bus_typename  !object_dynamic_cast(OBJECT(bus), bus_typename)) {
 match = 0;
 }
+if ((bus-max_dev != 0)  (bus-max_dev = bus-max_index)) {
+if (name != NULL) {
+/* bus was explicitly specified : return an error. */
+qerror_report(ERROR_CLASS_GENERIC_ERROR, Bus '%s' is full,
+  bus-name);
+return NULL;
+} else {
+/* bus was not specified : try to find another one. */
+match = 0;
+}
+}
 if (match) {
 return bus;
 }
-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Create a virtio-s390-bus during init, so the refactored virtio device can be
connected.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390-virtio-bus.c | 2 ++
 hw/s390-virtio-bus.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 720dbb9..849adab 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -490,6 +490,8 @@ static int s390_virtio_busdev_init(DeviceState *dev)
 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
 VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
 
+_dev-bus = virtio_s390_bus_new(_dev);
+
 return _info-init(_dev);
 }
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 7c5a945..08e68c2 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -90,6 +90,7 @@ struct VirtIOS390Device {
 virtio_net_conf net;
 VirtIOSCSIConf scsi;
 VirtIORNGConf rng;
+VirtioBusState *bus;
 };
 
 typedef struct VirtIOS390Bus {
-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Introduce virtio-bus. Refactored transport device will create a bus which
extends virtio-bus.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/Makefile.objs |   1 +
 hw/virtio-bus.c  | 169 +++
 hw/virtio-bus.h  |  98 
 3 files changed, 268 insertions(+)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d581d8d..6fa4de4 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -3,6 +3,7 @@ common-obj-y += loader.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
 common-obj-y += fw_cfg.o
 common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
 common-obj-$(CONFIG_PCI) += msix.o msi.o
diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
new file mode 100644
index 000..7a3d06e
--- /dev/null
+++ b/hw/virtio-bus.c
@@ -0,0 +1,169 @@
+/*
+ * VirtioBus
+ *
+ *  Copyright (C) 2012 : GreenSocs Ltd
+ *  http://www.greensocs.com/ , email: i...@greensocs.com
+ *
+ *  Developed by :
+ *  Frederic Konrad   fred.kon...@greensocs.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see http://www.gnu.org/licenses/.
+ *
+ */
+
+#include hw.h
+#include qemu-error.h
+#include qdev.h
+#include virtio-bus.h
+#include virtio.h
+
+/* #define DEBUG_VIRTIO_BUS */
+
+#ifdef DEBUG_VIRTIO_BUS
+#define DPRINTF(fmt, ...) \
+do { printf(virtio_bus:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) do { } while (0)
+#endif
+
+/* Plug the VirtIODevice */
+int virtio_bus_plug_device(VirtIODevice *vdev)
+{
+DeviceState *qdev = DEVICE(vdev);
+BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+VirtioBusState *bus = VIRTIO_BUS(qbus);
+VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+DPRINTF(%s : plug device.\n, qbus-name);
+
+bus-vdev = vdev;
+
+if (klass-device_plugged != NULL) {
+klass-device_plugged(qbus-parent);
+}
+
+/*
+ * The lines below will disappear when we drop VirtIOBindings, at the end
+ * of the serie.
+ */
+bus-bindings.notify = klass-notify;
+bus-bindings.save_config = klass-save_config;
+bus-bindings.save_queue = klass-save_queue;
+bus-bindings.load_config = klass-load_config;
+bus-bindings.load_queue = klass-load_queue;
+bus-bindings.load_done = klass-load_done;
+bus-bindings.get_features = klass-get_features;
+bus-bindings.query_guest_notifiers = klass-query_guest_notifiers;
+bus-bindings.set_guest_notifiers = klass-set_guest_notifiers;
+bus-bindings.set_host_notifier = klass-set_host_notifier;
+bus-bindings.vmstate_change = klass-vmstate_change;
+virtio_bind_device(bus-vdev, (bus-bindings), qbus-parent);
+/*
+ */
+
+return 0;
+}
+
+/* Reset the virtio_bus */
+void virtio_bus_reset(VirtioBusState *bus)
+{
+DPRINTF(%s : reset device.\n, qbus-name);
+if (bus-vdev != NULL) {
+virtio_reset(bus-vdev);
+}
+}
+
+/* Destroy the VirtIODevice */
+void virtio_bus_destroy_device(VirtioBusState *bus)
+{
+DeviceState *qdev;
+BusState *qbus = BUS(bus);
+VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+DPRINTF(%s : remove device.\n, qbus-name);
+
+if (bus-vdev != NULL) {
+if (klass-device_unplug != NULL) {
+klass-device_unplug(qbus-parent);
+}
+qdev = DEVICE(bus-vdev);
+qdev_free(qdev);
+bus-vdev = NULL;
+}
+}
+
+/* Get the device id of the plugged device. */
+uint16_t get_virtio_device_id(VirtioBusState *bus)
+{
+assert(bus-vdev != NULL);
+return bus-vdev-device_id;
+}
+
+/* Get the nvectors field of the plugged device. */
+int get_virtio_device_nvectors(VirtioBusState *bus)
+{
+assert(bus-vdev != NULL);
+return bus-vdev-nvectors;
+}
+
+/* Set the nvectors field of the plugged device. */
+void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors)
+{
+assert(bus-vdev != NULL);
+bus-vdev-nvectors = nvectors;
+}
+
+/* Get the config_len field of the plugged device. */
+size_t get_virtio_device_config_len(VirtioBusState *bus)
+{
+assert(bus-vdev != NULL);
+return bus-vdev-config_len;
+}
+
+/* Get the features of the plugged device. */

[Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

As the virtio-blk-pci is switched to the new API, we can use QOM casts and
remove the separate init for the old API. This shouldn't been applyied
before virtio-blk-pci refactoring and virtio-blk-s390 refactoring.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-blk.c | 117 ++--
 1 file changed, 37 insertions(+), 80 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5511999..93b9746 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -25,7 +25,7 @@
 
 typedef struct VirtIOBlock
 {
-VirtIODevice vdev;
+VirtIODevice parent_obj;
 BlockDriverState *bs;
 VirtQueue *vq;
 void *rq;
@@ -36,14 +36,6 @@ typedef struct VirtIOBlock
 DeviceState *qdev;
 } VirtIOBlock;
 
-/*
- * Moving to QOM later in this series.
- */
-static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
-{
-return (VirtIOBlock *)vdev;
-}
-
 typedef struct VirtIOBlockReq
 {
 VirtIOBlock *dev;
@@ -59,12 +51,13 @@ typedef struct VirtIOBlockReq
 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
 {
 VirtIOBlock *s = req-dev;
+VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
 trace_virtio_blk_req_complete(req, status);
 
 stb_p(req-in-status, status);
 virtqueue_push(s-vq, req-elem, req-qiov.size + sizeof(*req-in));
-virtio_notify(s-vdev, s-vq);
+virtio_notify(vdev, s-vq);
 }
 
 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
@@ -405,7 +398,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
 
 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 VirtIOBlockReq *req;
 MultiReqBuffer mrb = {
 .num_writes = 0,
@@ -426,7 +419,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, 
VirtQueue *vq)
 
 static void virtio_blk_dma_restart_bh(void *opaque)
 {
-VirtIOBlock *s = opaque;
+VirtIOBlock *s = VIRTIO_BLK(opaque);
 VirtIOBlockReq *req = s-rq;
 MultiReqBuffer mrb = {
 .num_writes = 0,
@@ -448,7 +441,7 @@ static void virtio_blk_dma_restart_bh(void *opaque)
 static void virtio_blk_dma_restart_cb(void *opaque, int running,
   RunState state)
 {
-VirtIOBlock *s = opaque;
+VirtIOBlock *s = VIRTIO_BLK(opaque);
 
 if (!running)
 return;
@@ -472,7 +465,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
  */
 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 struct virtio_blk_config blkcfg;
 uint64_t capacity;
 int blk_size = s-conf-logical_block_size;
@@ -511,7 +504,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, 
uint8_t *config)
 
 static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 struct virtio_blk_config blkcfg;
 
 memcpy(blkcfg, config, sizeof(blkcfg));
@@ -520,7 +513,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const 
uint8_t *config)
 
 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 
 features |= (1  VIRTIO_BLK_F_SEG_MAX);
 features |= (1  VIRTIO_BLK_F_GEOMETRY);
@@ -539,7 +532,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, 
uint32_t features)
 
 static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 uint32_t features;
 
 if (!(status  VIRTIO_CONFIG_S_DRIVER_OK)) {
@@ -552,10 +545,11 @@ static void virtio_blk_set_status(VirtIODevice *vdev, 
uint8_t status)
 
 static void virtio_blk_save(QEMUFile *f, void *opaque)
 {
-VirtIOBlock *s = opaque;
+VirtIOBlock *s = VIRTIO_BLK(opaque);
+VirtIODevice *vdev = VIRTIO_DEVICE(s);
 VirtIOBlockReq *req = s-rq;
 
-virtio_save(s-vdev, f);
+virtio_save(vdev, f);
 
 while (req) {
 qemu_put_sbyte(f, 1);
@@ -567,13 +561,14 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
 
 static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
 {
-VirtIOBlock *s = opaque;
+VirtIOBlock *s = VIRTIO_BLK(opaque);
+VirtIODevice *vdev = VIRTIO_DEVICE(s);
 int ret;
 
 if (version_id != 2)
 return -EINVAL;
 
-ret = virtio_load(s-vdev, f);
+ret = virtio_load(vdev, f);
 if (ret) {
 return ret;
 }
@@ -595,9 +590,9 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int 
version_id)
 
 static void virtio_blk_resize(void *opaque)
 {
-VirtIOBlock *s = opaque;
+VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 
-virtio_notify_config(s-vdev);
+

[Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Clean the init and the exit function. It should be applied when all the device
have been refactored.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio.c | 15 ---
 hw/virtio.h |  4 
 2 files changed, 19 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index d124ca0..39cdebe 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -908,12 +908,6 @@ void virtio_common_cleanup(VirtIODevice *vdev)
 g_free(vdev-vq);
 }
 
-void virtio_cleanup(VirtIODevice *vdev)
-{
-virtio_common_cleanup(vdev);
-g_free(vdev);
-}
-
 static void virtio_vmstate_change(void *opaque, int running, RunState state)
 {
 VirtIODevice *vdev = opaque;
@@ -963,15 +957,6 @@ void virtio_init(VirtIODevice *vdev, const char *name,
  vdev);
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size)
-{
-VirtIODevice *vdev;
-vdev = g_malloc0(struct_size);
-virtio_init(vdev, name, device_id, config_size);
-return vdev;
-}
-
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
 {
 return vdev-vq[n].vring.desc;
diff --git a/hw/virtio.h b/hw/virtio.h
index 82726a3..de46098 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -162,8 +162,6 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f);
 
-void virtio_cleanup(VirtIODevice *vdev);
-
 void virtio_notify_config(VirtIODevice *vdev);
 
 void virtio_queue_set_notification(VirtQueue *vq, int enable);
@@ -174,8 +172,6 @@ int virtio_queue_empty(VirtQueue *vq);
 
 /* Host binding interface.  */
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size);
 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr);
 uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr);
 uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr);
-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Create virtio-blk which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-blk.c | 101 +++-
 hw/virtio-blk.h |  19 +++
 hw/virtio-pci.c |   7 ++--
 3 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index e25cc96..5511999 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -21,6 +21,7 @@
 #ifdef __linux__
 # include scsi/sg.h
 #endif
+#include virtio-bus.h
 
 typedef struct VirtIOBlock
 {
@@ -30,11 +31,14 @@ typedef struct VirtIOBlock
 void *rq;
 QEMUBH *bh;
 BlockConf *conf;
-VirtIOBlkConf *blk;
+VirtIOBlkConf blk;
 unsigned short sector_mask;
 DeviceState *qdev;
 } VirtIOBlock;
 
+/*
+ * Moving to QOM later in this series.
+ */
 static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
 {
 return (VirtIOBlock *)vdev;
@@ -164,7 +168,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
  */
 req-scsi = (void *)req-elem.in_sg[req-elem.in_num - 2].iov_base;
 
-if (!req-dev-blk-scsi) {
+if (!req-dev-blk.scsi) {
 status = VIRTIO_BLK_S_UNSUPP;
 goto fail;
 }
@@ -384,7 +388,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
  * terminated by '\0' only when shorter than buffer.
  */
 strncpy(req-elem.in_sg[0].iov_base,
-s-blk-serial ? s-blk-serial : ,
+s-blk.serial ? s-blk.serial : ,
 MIN(req-elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
 g_free(req);
@@ -600,9 +604,16 @@ static const BlockDevOps virtio_block_ops = {
 .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
+{
+VirtIOBlock *s = VIRTIO_BLK(dev);
+memcpy((s-blk), blk, sizeof(struct VirtIOBlkConf));
+}
+
+static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
+  VirtIOBlkConf *blk, VirtIOBlock **ps)
 {
-VirtIOBlock *s;
+VirtIOBlock *s = *ps;
 static int virtio_blk_id;
 
 if (!blk-conf.bs) {
@@ -619,9 +630,20 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, 
VirtIOBlkConf *blk)
 return NULL;
 }
 
-s = (VirtIOBlock *)virtio_common_init(virtio-blk, VIRTIO_ID_BLOCK,
-  sizeof(struct virtio_blk_config),
-  sizeof(VirtIOBlock));
+/*
+ * We have two cases here : the old virtio-blk-pci device, and the
+ * refactored virtio-blk.
+ */
+if (s == NULL) {
+/* virtio-blk-pci */
+s = (VirtIOBlock *)virtio_common_init(virtio-blk, VIRTIO_ID_BLOCK,
+  sizeof(struct virtio_blk_config),
+  sizeof(VirtIOBlock));
+} else {
+/* virtio-blk */
+virtio_init(VIRTIO_DEVICE(s), virtio-blk, VIRTIO_ID_BLOCK,
+sizeof(struct virtio_blk_config));
+}
 
 s-vdev.get_config = virtio_blk_update_config;
 s-vdev.set_config = virtio_blk_set_config;
@@ -630,7 +652,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, 
VirtIOBlkConf *blk)
 s-vdev.reset = virtio_blk_reset;
 s-bs = blk-conf.bs;
 s-conf = blk-conf;
-s-blk = blk;
+virtio_blk_set_conf(dev, blk);
 s-rq = NULL;
 s-sector_mask = (s-conf-logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
@@ -649,6 +671,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, 
VirtIOBlkConf *blk)
 return s-vdev;
 }
 
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+{
+VirtIOBlock *s = NULL;
+return virtio_blk_common_init(dev, blk, s);
+}
+
 void virtio_blk_exit(VirtIODevice *vdev)
 {
 VirtIOBlock *s = to_virtio_blk(vdev);
@@ -656,3 +684,58 @@ void virtio_blk_exit(VirtIODevice *vdev)
 blockdev_mark_auto_del(s-bs);
 virtio_cleanup(vdev);
 }
+
+
+static int virtio_blk_device_init(VirtIODevice *vdev)
+{
+DeviceState *qdev = DEVICE(vdev);
+VirtIOBlock *s = VIRTIO_BLK(vdev);
+VirtIOBlkConf *blk = (s-blk);
+if (virtio_blk_common_init(qdev, blk, s) == NULL) {
+return -1;
+}
+return 0;
+}
+
+static int virtio_blk_device_exit(DeviceState *dev)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+VirtIOBlock *s = VIRTIO_BLK(dev);
+unregister_savevm(s-qdev, virtio-blk, s);
+blockdev_mark_auto_del(s-bs);
+virtio_common_cleanup(vdev);
+return 0;
+}
+
+static Property virtio_blk_properties[] = {
+DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioDeviceClass *vdc = 

[Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Introduce virtio-s390-bus, which extends virtio-bus. It is used with s390
transport device.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390-virtio-bus.c | 28 
 hw/s390-virtio-bus.h | 13 +
 2 files changed, 41 insertions(+)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index e0ac2d1..720dbb9 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -33,6 +33,7 @@
 #include kvm.h
 
 #include hw/s390-virtio-bus.h
+#include hw/virtio-bus.h
 
 /* #define DEBUG_S390 */
 
@@ -556,8 +557,35 @@ static TypeInfo s390_virtio_bridge_info = {
 .class_init= s390_virtio_bridge_class_init,
 };
 
+/* virtio-s390-bus */
+
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev)
+{
+DeviceState *qdev = DEVICE(dev);
+BusState *qbus = qbus_create(TYPE_VIRTIO_S390_BUS, qdev, NULL);
+VirtioBusState *bus = VIRTIO_BUS(qbus);
+qbus-allow_hotplug = 0;
+qbus-max_dev = 1;
+return bus;
+}
+
+static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
+{
+VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+k-notify = virtio_s390_notify;
+k-get_features = virtio_s390_get_features;
+}
+
+static const TypeInfo virtio_s390_bus_info = {
+.name  = TYPE_VIRTIO_S390_BUS,
+.parent= TYPE_VIRTIO_BUS,
+.instance_size = sizeof(VirtioBusState),
+.class_init= virtio_s390_bus_class_init,
+};
+
 static void s390_virtio_register_types(void)
 {
+type_register_static(virtio_s390_bus_info);
 type_register_static(s390_virtio_bus_info);
 type_register_static(virtio_s390_device_info);
 type_register_static(s390_virtio_serial);
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index a83afe7..7c5a945 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -22,6 +22,7 @@
 #include virtio-rng.h
 #include virtio-serial.h
 #include virtio-scsi.h
+#include virtio-bus.h
 
 #define VIRTIO_DEV_OFFS_TYPE   0   /* 8 bits */
 #define VIRTIO_DEV_OFFS_NUM_VQ 1   /* 8 bits */
@@ -57,8 +58,20 @@
 #define S390_VIRTIO_BUS(obj) \
  OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
 
+/* virtio-s390-bus */
+
+#define TYPE_VIRTIO_S390_BUS virtio-s390-bus
+#define VIRTIO_S390_BUS_GET_CLASS(obj) \
+OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_S390_BUS)
+
 typedef struct VirtIOS390Device VirtIOS390Device;
 
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev);
+
 typedef struct VirtIOS390DeviceClass {
 DeviceClass qdev;
 int (*init)(VirtIOS390Device *dev);
-- 
1.7.11.7




[Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove VirtIOBindings and use VirtioBusClass instead. It should be applied
when all the device have been refactored.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-bus.c | 20 
 hw/virtio-bus.h |  6 --
 hw/virtio.c | 52 +++-
 hw/virtio.h | 19 ---
 4 files changed, 31 insertions(+), 66 deletions(-)

diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
index 7a3d06e..6da587d 100644
--- a/hw/virtio-bus.c
+++ b/hw/virtio-bus.c
@@ -51,26 +51,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
 if (klass-device_plugged != NULL) {
 klass-device_plugged(qbus-parent);
 }
-
-/*
- * The lines below will disappear when we drop VirtIOBindings, at the end
- * of the serie.
- */
-bus-bindings.notify = klass-notify;
-bus-bindings.save_config = klass-save_config;
-bus-bindings.save_queue = klass-save_queue;
-bus-bindings.load_config = klass-load_config;
-bus-bindings.load_queue = klass-load_queue;
-bus-bindings.load_done = klass-load_done;
-bus-bindings.get_features = klass-get_features;
-bus-bindings.query_guest_notifiers = klass-query_guest_notifiers;
-bus-bindings.set_guest_notifiers = klass-set_guest_notifiers;
-bus-bindings.set_host_notifier = klass-set_host_notifier;
-bus-bindings.vmstate_change = klass-vmstate_change;
-virtio_bind_device(bus-vdev, (bus-bindings), qbus-parent);
-/*
- */
-
 return 0;
 }
 
diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
index a2e2012..a5e2a87 100644
--- a/hw/virtio-bus.h
+++ b/hw/virtio-bus.h
@@ -70,12 +70,6 @@ struct VirtioBusState {
  * Only one VirtIODevice can be plugged on the bus.
  */
 VirtIODevice *vdev;
-/*
- * This will be removed at the end of the serie.
- */
-VirtIOBindings bindings;
-/*
- */
 };
 
 int virtio_bus_plug_device(VirtIODevice *vdev);
diff --git a/hw/virtio.c b/hw/virtio.c
index 82bf3dd..d124ca0 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -505,8 +505,12 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 /* virtio device */
 static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
 {
-if (vdev-binding-notify) {
-vdev-binding-notify(vdev-binding_opaque, vector);
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+
+if (k-notify) {
+k-notify(qbus-parent, vector);
 }
 }
 
@@ -776,10 +780,14 @@ void virtio_notify_config(VirtIODevice *vdev)
 
 void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 int i;
 
-if (vdev-binding-save_config)
-vdev-binding-save_config(vdev-binding_opaque, f);
+if (k-save_config) {
+k-save_config(qbus-parent, f);
+}
 
 qemu_put_8s(f, vdev-status);
 qemu_put_8s(f, vdev-isr);
@@ -802,16 +810,19 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_be32(f, vdev-vq[i].vring.num);
 qemu_put_be64(f, vdev-vq[i].pa);
 qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
-if (vdev-binding-save_queue)
-vdev-binding-save_queue(vdev-binding_opaque, i, f);
+if (k-save_queue)
+k-save_queue(qbus-parent, i, f);
 }
 }
 
 int virtio_set_features(VirtIODevice *vdev, uint32_t val)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(vbus);
 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 uint32_t supported_features =
-vdev-binding-get_features(vdev-binding_opaque);
+vbusk-get_features(qbus-parent);
 bool bad = (val  ~supported_features) != 0;
 
 val = supported_features;
@@ -827,9 +838,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 int num, i, ret;
 uint32_t features;
 uint32_t supported_features;
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 
-if (vdev-binding-load_config) {
-ret = vdev-binding-load_config(vdev-binding_opaque, f);
+if (k-load_config) {
+ret = k-load_config(qbus-parent, f);
 if (ret)
 return ret;
 }
@@ -840,7 +854,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 qemu_get_be32s(f, features);
 
 if (virtio_set_features(vdev, features)  0) {
-supported_features = vdev-binding-get_features(vdev-binding_opaque);
+supported_features = k-get_features(qbus-parent);
 error_report(Features 0x%x unsupported. Allowed features: 0x%x,
  features, 

[Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus.

2012-12-19 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
transport device.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio-pci.c | 37 +
 hw/virtio-pci.h | 19 +--
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7684ac9..859a1ed 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -32,6 +32,7 @@
 #include blockdev.h
 #include virtio-pci.h
 #include range.h
+#include virtio-bus.h
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -1117,6 +1118,41 @@ static TypeInfo virtio_scsi_info = {
 .class_init= virtio_scsi_class_init,
 };
 
+/* virtio-pci-bus */
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
+{
+DeviceState *qdev = DEVICE(dev);
+BusState *qbus = qbus_create(TYPE_VIRTIO_PCI_BUS, qdev, NULL);
+VirtioBusState *bus = VIRTIO_BUS(qbus);
+qbus-allow_hotplug = 0;
+/* Only one virtio-device allowed for virtio-pci. */
+qbus-max_dev = 1;
+return bus;
+}
+
+static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
+{
+VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+k-notify = virtio_pci_notify;
+k-save_config = virtio_pci_save_config;
+k-load_config = virtio_pci_load_config;
+k-save_queue = virtio_pci_save_queue;
+k-load_queue = virtio_pci_load_queue;
+k-get_features = virtio_pci_get_features;
+k-query_guest_notifiers = virtio_pci_query_guest_notifiers;
+k-set_host_notifier = virtio_pci_set_host_notifier;
+k-set_guest_notifiers = virtio_pci_set_guest_notifiers;
+k-vmstate_change = virtio_pci_vmstate_change;
+}
+
+static const TypeInfo virtio_pci_bus_info = {
+.name  = TYPE_VIRTIO_PCI_BUS,
+.parent= TYPE_VIRTIO_BUS,
+.instance_size = sizeof(VirtioBusState),
+.class_init= virtio_pci_bus_class_init,
+};
+
 static void virtio_pci_register_types(void)
 {
 type_register_static(virtio_blk_info);
@@ -1125,6 +1161,7 @@ static void virtio_pci_register_types(void)
 type_register_static(virtio_balloon_info);
 type_register_static(virtio_scsi_info);
 type_register_static(virtio_rng_info);
+type_register_static(virtio_pci_bus_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index b58d9a2..0e3288e 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -20,6 +20,21 @@
 #include virtio-rng.h
 #include virtio-serial.h
 #include virtio-scsi.h
+#include virtio-bus.h
+
+/* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
+typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+
+/* virtio-pci-bus */
+#define TYPE_VIRTIO_PCI_BUS virtio-pci-bus
+#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
+OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_PCI_BUS)
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev);
 
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
@@ -31,7 +46,7 @@ typedef struct {
 unsigned int users;
 } VirtIOIRQFD;
 
-typedef struct {
+struct VirtIOPCIProxy {
 PCIDevice pci_dev;
 VirtIODevice *vdev;
 MemoryRegion bar;
@@ -51,7 +66,7 @@ typedef struct {
 bool ioeventfd_disabled;
 bool ioeventfd_started;
 VirtIOIRQFD *vector_irqfd;
-} VirtIOPCIProxy;
+};
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH 3/3] virtio-pci: don't poll masked vectors

2012-12-19 Thread Michael S. Tsirkin
On Wed, Dec 19, 2012 at 04:59:05PM +0800, Asias He wrote:
 On 12/18/2012 08:39 PM, Michael S. Tsirkin wrote:
  At the moment, when irqfd is in use but a vector is masked,
  qemu will poll it and handle vector masks in userspace.
  Since almost no one ever looks at the pending bits,
  it is better to defer this until pending bits
  are actually read.
  Implement this optimization using the new poll notifier.
  
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
  ---
   hw/virtio-pci.c | 52 
   1 file changed, 40 insertions(+), 12 deletions(-)
  
  diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
  index 1c03bb5..bc6b4e0 100644
  --- a/hw/virtio-pci.c
  +++ b/hw/virtio-pci.c
  @@ -509,8 +509,6 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy 
  *proxy,
   }
   return ret;
   }
  -
  -virtio_queue_set_guest_notifier_fd_handler(vq, true, true);
   return 0;
   }
   
  @@ -529,8 +527,6 @@ static void 
  kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
   if (--irqfd-users == 0) {
   kvm_irqchip_release_virq(kvm_state, irqfd-virq);
   }
  -
  -virtio_queue_set_guest_notifier_fd_handler(vq, true, false);
   }
   
   static int kvm_virtio_pci_vector_use(PCIDevice *dev, unsigned vector,
  @@ -581,7 +577,36 @@ static void kvm_virtio_pci_vector_release(PCIDevice 
  *dev, unsigned vector)
   }
   }
   
  -static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool 
  assign)
  +static void kvm_virtio_pci_vector_poll(PCIDevice *dev,
  +   unsigned int vector_start,
  +   unsigned int vector_end)
  +{
  +VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
  +VirtIODevice *vdev = proxy-vdev;
  +int queue_no;
  +unsigned int vector;
  +EventNotifier *notifier;
  +VirtQueue *vq;
  +
  +for (queue_no = 0; queue_no  VIRTIO_PCI_QUEUE_MAX; queue_no++) {
  +if (!virtio_queue_get_num(vdev, queue_no)) {
  +break;
  +}
  +vector = virtio_queue_vector(vdev, queue_no);
  +if (vector  vector_start || vector = vector_end ||
  +!msix_is_masked(dev, vector)) {
  +continue;
  +}
  +vq = virtio_get_queue(vdev, queue_no);
  +notifier = virtio_queue_get_guest_notifier(vq);
  +if (event_notifier_test_and_clear(notifier)) {
  +msix_set_pending(dev, vector);
  +}
  +}
  +}
  +
  +static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool 
  assign,
  + bool with_irqfd)
   {
   VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
   VirtQueue *vq = virtio_get_queue(proxy-vdev, n);
  @@ -592,9 +617,9 @@ static int virtio_pci_set_guest_notifier(DeviceState 
  *d, int n, bool assign)
   if (r  0) {
   return r;
   }
  -virtio_queue_set_guest_notifier_fd_handler(vq, true, false);
  +virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
 
 +  virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
 
   } else {
  -virtio_queue_set_guest_notifier_fd_handler(vq, false, false);
  +virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
 
 +  virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
 
 Use the 'assign' variable instead of the constants?

I don't care either way (this is within if (assign)).
But all this patch does is add a parameter,
unrelated code refactorings should be separate.

   event_notifier_cleanup(notifier);
   }
   
  @@ -612,9 +637,11 @@ static int virtio_pci_set_guest_notifiers(DeviceState 
  *d, bool assign)
   VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
   VirtIODevice *vdev = proxy-vdev;
   int r, n;
  +bool with_irqfd = msix_enabled(proxy-pci_dev) 
  +kvm_msi_via_irqfd_enabled();
   
   /* Must unset vector notifier while guest notifier is still assigned */
  -if (kvm_msi_via_irqfd_enabled()  !assign) {
  +if (with_irqfd  !assign) {
   msix_unset_vector_notifiers(proxy-pci_dev);
   g_free(proxy-vector_irqfd);
   proxy-vector_irqfd = NULL;
  @@ -625,21 +652,22 @@ static int virtio_pci_set_guest_notifiers(DeviceState 
  *d, bool assign)
   break;
   }
   
  -r = virtio_pci_set_guest_notifier(d, n, assign);
  +r = virtio_pci_set_guest_notifier(d, n, assign,
  +  kvm_msi_via_irqfd_enabled());
   if (r  0) {
   goto assign_error;
   }
   }
   
   /* Must set vector notifier after guest notifier has been assigned */
  -if (kvm_msi_via_irqfd_enabled()  assign) {
  +if (with_irqfd  assign) {
   proxy-vector_irqfd =
   g_malloc0(sizeof(*proxy-vector_irqfd) *
 

Re: [Qemu-devel] [PATCH 0/3] virtio: don't poll masked vectors with irqfd

2012-12-19 Thread Michael S. Tsirkin
On Wed, Dec 19, 2012 at 04:53:22PM +0800, Asias He wrote:
 On 12/18/2012 08:39 PM, Michael S. Tsirkin wrote:
  At the moment when vector is masked virtio will poll it
  in userspace, even if it is handled by irqfd.
  This is done in order to update pending bits, but
  it's not really required until someone reads the pending bits.
  On the other hand this read results in extra io thread wakeups.
  
  As we only implement the pending bits as a compatibility
  feature (read - real drivers don't use it), we can defer
  the irqfd poll until the read actually happens.
  
  This does not seem to affect vhost-net speed
  in simple benchmarks but could help block: both
  vhost-blk and dataplane when using irqfd,
  and I also think this is cleaner than enabling/disabling
  notifiers all the time.
  
  This will also be the basis for future optimizations.
  
  Michael S. Tsirkin (3):
msi: add API to get notified about pending bit poll
msix: expose access to masked/pending state
virtio-pci: don't poll masked vectors
  
   hw/pci/msix.c   | 19 +++
   hw/pci/msix.h   |  6 +-
   hw/pci/pci.h|  4 
   hw/vfio_pci.c   |  2 +-
   hw/virtio-pci.c | 53 +
   5 files changed, 66 insertions(+), 18 deletions(-)
 
 The performance boost is significant here. It is close to the
 result of dropping msix_fire_vector_notifier() hack.

Okay great. I have one other last optimization up my sleeve,
that should hopefully make it as fast as with the hack.

 -- 
 Asias



Re: [Qemu-devel] [PATCH 1/3] balloon: drop old stats code API

2012-12-19 Thread Luiz Capitulino
On Tue, 18 Dec 2012 14:34:16 -0700
Eric Blake ebl...@redhat.com wrote:

 On 12/17/2012 03:13 AM, Dietmar Maurer wrote:
  Next commit will re-enable balloon stats with a different interface, but 
  this
  old code conflicts with it. Let's drop it.
  
  I don't really see any conflicts here?
  
  It's important to note that the QMP and HMP interfaces are also dropped by
  this commit. That shouldn't be a problem though, because:
 
   1. All QMP fields are optional
   2. This has never been really used
 
 Libvirt has been using it when available (although reluctantly, as it
 risks hanging on an uncooperative guest);

This has always been disabled and qemu never returns the stats info.
I believe libvirt's code is rotting just like qemu's is.

 and while libvirt can be
 patched to call 6 QOM commands in a row to query six different QOM
 stats, I still think it would be nicer to add a command that provides
 all the stats at once.  In particular, when calling 6 commands in
 series, you no longer have an atomic picture of the guest (the polling
 interval could hit between two QOM queries, resulting in a combined set
 of statistics that has no counterpart to the transition of states that
 the guest actually went through). On the other hand, since the stats
 are already polling-based, and since it requires cooperation from the
 guest, not having a guarantee of an atomic set of stats is not really
 much of a loss.

Something I have been wondering if whether it's possible to have only
one property (say balloon-statistics) and return all properties in a
dict. QOM properties return a visitor, so maybe that's possible.

I'll check that.



Re: [Qemu-devel] [RFC 3/3] virtio-balloon: add auto-ballooning support

2012-12-19 Thread Luiz Capitulino
On Tue, 18 Dec 2012 14:53:30 -0800
Anton Vorontsov anton.voront...@linaro.org wrote:

 Hello Luiz,
 
 On Tue, Dec 18, 2012 at 06:16:55PM -0200, Luiz Capitulino wrote:
  The auto-ballooning feature automatically performs balloon inflate
  or deflate based on host and guest memory pressure. This can help to
  avoid swapping or worse in both, host and guest.
  
  Auto-ballooning has a host and a guest part. The host performs
  automatic inflate by requesting the guest to inflate its balloon
  when the host is facing memory pressure. The guest performs
  automatic deflate when it's facing memory pressure itself. It's
  expected that auto-inflate and auto-deflate will balance each
  other over time.
  
  This commit implements the host side of auto-ballooning.
  
  To be notified of host memory pressure, this commit makes use of this
  kernel API proposal being discussed upstream:
  
   http://marc.info/?l=linux-mmm=135513372205134w=2
 
 Wow, you're fast! And I'm glad that it works for you, so we have two
 full-featured mempressure cgroup users already.

Thanks, although I think we need more testing to be sure this does what
we want. I mean, the basic mechanics does work, but my testing has been
very light so far.

 Even though it is a qemu patch, I think we should Cc linux-mm folks on it,
 just to let them know the great news.

I'll do it next time.



Re: [Qemu-devel] [RFC PATCH v4 00/30] ACPI memory hotplug

2012-12-19 Thread Vasilis Liaskovitis
Hi,

On Wed, Dec 19, 2012 at 08:27:36AM +0100, Gerd Hoffmann wrote:
   Hi,
 
  - multiple memory buses can be registered. Memory buses of the real 
  hw/chipset
or a paravirtual memory bus can be added.
 
 IIRC q35 supports memory hotplug natively (picked up in some
 discussion).  Is that correct?
 
 What does the code emulate?  It doesn't look like it emulates q35 memory
 hotplug ...

correct, only the number of channels and ranks(dimms) per channel has been
emulated so far (2 channels of 4 dimms each). So it is still paravirtual memory
hotplug, not native. Native support still needs to be worked on.

From previous discussion I also understand that q35 supports native hotplug. 
Sections 5.1 and 5.2 of the spec describe the MCH registers but the native
acpi-memory hotplug specifics are not yet clear to me. Any pointers from the
spec are welcome.

 
 I think the paravirtual memory hotplug controller should be a PCI device
 (which we then can add as function to the chipset).  Having some fixed
 magic addresses is bad.

ok, so in your opinion a pci-based hotplug controller sounds better than adding
acpi ports to piix4 or ich9?

Magic acpi_ich9 ports can be avoided if q35 native support is implemented. For
i440fx/piix4 it was discussed and more or less decided we would only support
a paravirtual way of memory hotplug. 

In the description. I meant paravirtual memory bus to describe a memory bus
with unlimited number of dimm devices. But the hotplug control has always
been acpi-based so far and not a pci device.

thanks,

- Vasilis



Re: [Qemu-devel] [RFC PATCH v4 00/30] ACPI memory hotplug

2012-12-19 Thread Vasilis Liaskovitis
On Wed, Dec 19, 2012 at 12:45:46AM +0800, Zhi Yong Wu wrote:
 HI,
 
 One stupid question, 'dimm' presents one guest memory, then why it is
 called as dimm? what is its full name?

it's a bad name coming from dram technology (dual in-line memory module).
Memory-slot or memory-module is probably a better name, since we are not really
modelling a specific memory technology.

thanks,

- Vasilis



Re: [Qemu-devel] [PATCH] e1000: Discard oversized packets based on SBP|LPE

2012-12-19 Thread Stefan Hajnoczi
On Tue, Dec 18, 2012 at 12:34:22PM -0500, Michael Contreras wrote:
 On Tue, Dec 18, 2012 at 05:49:16PM +0100, Stefan Hajnoczi wrote:
  On Tue, Dec 18, 2012 at 5:20 PM, Michael Tokarev m...@tls.msk.ru wrote:
   On 18.12.2012 17:44, Stefan Hajnoczi wrote:
   On Wed, Dec 05, 2012 at 01:31:30PM -0500, Michael Contreras wrote:
   Discard packets longer than 16384 when !SBP to match the hardware 
   behavior.
  
   Signed-off-by: Michael Contreras mich...@inetric.com
   ---
hw/e1000.c | 7 +--
1 file changed, 5 insertions(+), 2 deletions(-)
  
   It looks like another very good candidate for -stable (up to quite some
   releases of qemu ago), together with the previous similar patch.
  
  Yes, it's good for -stable.
  
  Stefan
 
 Thanks guys. Any update on the CVE number? Seems the KVM qemu git tree
 still has this vulnerability. Xen has the fix in their qemu unstable
 git mirror, but hasn't applied it yet either.

Your original LPE patch went into QEMU 1.3.  qemu-kvm.git is no longer
relevant - it has been merged back into qemu.git and has therefore not
been updated since October 11.  Use qemu.git.

Perhaps others can provide info on the CVE and Xen.

Stefan



Re: [Qemu-devel] [PATCH 26/26] usbredir: Add support for buffered bulk input

2012-12-19 Thread Hans de Goede

Hi,

On 12/19/2012 10:51 AM, Gerd Hoffmann wrote:

   Hi,


These 2 are 1 on 1 copies from the kernel:

hw/usb/redirect-ftdi-ids.h   | 1255
++
hw/usb/redirect-pl2303-ids.h |  150 +

They contain boring stuff like:

#define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */
#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */


We have header files copyed from linux already (linux-headers/), did you
look into placing them there?  Could be it doesn't work that easily due
to internal / user interface split of the kernel headers, but worth
checking ...


That seem to be only headers from under linux/include. And not from
under linux/drivers/usb/ like I'm doing, so for now I'm just
going to leave the headers in hw/usb.




This one:
hw/usb/redirect-usb-ids.h

Contains the usb-id tables copied from the kernel, as stated
in the comments:


Manual process or scripted?  If case of the latter we should put the
scripts into scripts/ for easy future updates.


So updating them can be done by emptying the list and then copying in
the new list from the latest kernel, this is an (easy) manual procedure
for now.


Ah, manual.  ok.


I also think this shouldn't be tied to redir, I think it is better to
have a hw/usb/quirks.c file where the device id database and helper
functions to match devices against the list are living.


Makes sense, one problem I see though is that right now I've
2 id tables, named usbredir_raw_serial_ids and usbredir_ftdi_serial_ids
since ftdi based adapters need some extra special handling (a quirk
to the quirk).

Once we start working with quirk tables it makes sense to have 1 large
table with an extra uint32_t field which contains the actual quirks as
bitmask. All perfectly sensible, but this breaks the easy copy and
paste syncing of the tables from the Linux kernel ...

So any good ideas for this from you ?


With a scripted update we could add the bitmask easily I guess.

But I think for now we can stick to two lists.  Just make sure
usb-quirks.c has a sensible interface.  Pass in device ids+class, get
back a quicks bitmask.  Then we can create the bitmask by just checking
which list has the device in question.

And when we figure some day this becomes too messy we can switch to a
model where where we have the quirk bits next to the devices in the
table and just do a lookup, without users noticing the change.


Ok, I'll send a new version with this implemented.

Regards,

Hans



Re: [Qemu-devel] [Bug 1091766] Re: Physical host crash with Mellanox IB PCI passthrough

2012-12-19 Thread Vlastimil Holer
Both patches against qemu 1.3 *works*, first with traditional PCI
pass., second with VFIO. Mellanox IB card in guest works fine again.
Great early Christmas present, thank you!

Just FYI: between both ways I can see little difference on host system
regarding the numbers of IRQs for MSI/MSI-X:

* VFIO:
| vfio_ecap_init: :20:00.0 hiding ecap 0x19@0x18c
| vfio-pci :20:00.0: irq 150 for MSI/MSI-X
| vfio-pci :20:00.0: irq 150 for MSI/MSI-X
| vfio-pci :20:00.0: irq 151 for MSI/MSI-X
| vfio-pci :20:00.0: irq 150 for MSI/MSI-X
| vfio-pci :20:00.0: irq 151 for MSI/MSI-X
| vfio-pci :20:00.0: irq 152 for MSI/MSI-X
| vfio-pci :20:00.0: irq 150 for MSI/MSI-X
| vfio-pci :20:00.0: irq 151 for MSI/MSI-X
| vfio-pci :20:00.0: irq 152 for MSI/MSI-X
| vfio-pci :20:00.0: irq 153 for MSI/MSI-X

* old way:
| assign device 0:20:0.0
| pci-stub :20:00.0: restoring config space at offset 0xf (was
0x100, writing 0x10a)
| pci-stub :20:00.0: restoring config space at offset 0x6 (was
0xc, writing 0xdf0c)
| pci-stub :20:00.0: restoring config space at offset 0x4 (was
0x4, writing 0x91b4)
| pci-stub :20:00.0: restoring config space at offset 0x3 (was
0x0, writing 0x10)
| pci-stub :20:00.0: restoring config space at offset 0x1 (was
0x10, writing 0x100042)
| pci-stub :20:00.0: irq 134 for MSI/MSI-X
| pci-stub :20:00.0: irq 135 for MSI/MSI-X
| pci-stub :20:00.0: irq 136 for MSI/MSI-X
| pci-stub :20:00.0: irq 137 for MSI/MSI-X
| pci-stub :20:00.0: irq 138 for MSI/MSI-X
| pci-stub :20:00.0: irq 139 for MSI/MSI-X
| pci-stub :20:00.0: irq 140 for MSI/MSI-X
| pci-stub :20:00.0: irq 141 for MSI/MSI-X
| pci-stub :20:00.0: irq 142 for MSI/MSI-X
| pci-stub :20:00.0: irq 143 for MSI/MSI-X
| pci-stub :20:00.0: irq 144 for MSI/MSI-X
| pci-stub :20:00.0: irq 145 for MSI/MSI-X
| pci-stub :20:00.0: irq 146 for MSI/MSI-X
| pci-stub :20:00.0: irq 147 for MSI/MSI-X
| pci-stub :20:00.0: irq 148 for MSI/MSI-X
| pci-stub :20:00.0: irq 149 for MSI/MSI-X
| pci-stub :20:00.0: irq 150 for MSI/MSI-X
| pci-stub :20:00.0: irq 151 for MSI/MSI-X
| pci-stub :20:00.0: irq 152 for MSI/MSI-X
| pci-stub :20:00.0: irq 153 for MSI/MSI-X
| pci-stub :20:00.0: irq 154 for MSI/MSI-X
| pci-stub :20:00.0: irq 155 for MSI/MSI-X
| pci-stub :20:00.0: irq 156 for MSI/MSI-X
| pci-stub :20:00.0: irq 157 for MSI/MSI-X
| pci-stub :20:00.0: irq 158 for MSI/MSI-X
| pci-stub :20:00.0: irq 159 for MSI/MSI-X
| pci-stub :20:00.0: irq 160 for MSI/MSI-X
| pci-stub :20:00.0: irq 161 for MSI/MSI-X
| pci-stub :20:00.0: irq 162 for MSI/MSI-X
| pci-stub :20:00.0: irq 163 for MSI/MSI-X
| pci-stub :20:00.0: irq 134 for MSI/MSI-X
| pci-stub :20:00.0: irq 135 for MSI/MSI-X
| pci-stub :20:00.0: irq 136 for MSI/MSI-X
| pci-stub :20:00.0: irq 137 for MSI/MSI-X
| pci-stub :20:00.0: irq 138 for MSI/MSI-X
| pci-stub :20:00.0: irq 139 for MSI/MSI-X
| pci-stub :20:00.0: irq 140 for MSI/MSI-X
| pci-stub :20:00.0: irq 141 for MSI/MSI-X
| pci-stub :20:00.0: irq 142 for MSI/MSI-X
| pci-stub :20:00.0: irq 143 for MSI/MSI-X
| pci-stub :20:00.0: irq 144 for MSI/MSI-X
| pci-stub :20:00.0: irq 145 for MSI/MSI-X
| pci-stub :20:00.0: irq 146 for MSI/MSI-X
| pci-stub :20:00.0: irq 147 for MSI/MSI-X
| pci-stub :20:00.0: irq 148 for MSI/MSI-X
| pci-stub :20:00.0: irq 149 for MSI/MSI-X
| pci-stub :20:00.0: irq 150 for MSI/MSI-X
| pci-stub :20:00.0: irq 151 for MSI/MSI-X
| pci-stub :20:00.0: irq 152 for MSI/MSI-X
| pci-stub :20:00.0: irq 153 for MSI/MSI-X
| pci-stub :20:00.0: irq 154 for MSI/MSI-X
| pci-stub :20:00.0: irq 155 for MSI/MSI-X
| pci-stub :20:00.0: irq 156 for MSI/MSI-X
| pci-stub :20:00.0: irq 157 for MSI/MSI-X
| pci-stub :20:00.0: irq 158 for MSI/MSI-X
| pci-stub :20:00.0: irq 159 for MSI/MSI-X
| pci-stub :20:00.0: irq 160 for MSI/MSI-X
| pci-stub :20:00.0: irq 161 for MSI/MSI-X
| pci-stub :20:00.0: irq 162 for MSI/MSI-X
| pci-stub :20:00.0: irq 163 for MSI/MSI-X

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

Title:
  Physical host crash with Mellanox IB PCI passthrough

Status in QEMU:
  New

Bug description:
  (from
  http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/100736)

  We have been using PCI passthrough with the Mellanox IB interface
  (MT27500 Family [ConnectX-3]) on Debian 6.0.6, kernel 3.2.23 and
  qemu-kvm-1.0 (both from backports). It worked fine until latest
  update in backports to qemu-kvm-1.1.2. With newer qemu-kvm versions
  IB device probe in guest fails leaving firmware to kill whole physical 
machine.

  I have then compiled qemu-kvm from source, 1.0.1 was OK, 1.1.2 fails and
  even 1.2.0 fails as well. Our setup is based on IBM System X iDataPlex
  dx360 M4 Server.

  

[Qemu-devel] [PATCH 05/34] migration-fd: remove duplicate include

2012-12-19 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-fd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/migration-fd.c b/migration-fd.c
index c501c4b..b8d16ad 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -20,7 +20,6 @@
 #include qemu-char.h
 #include qemu-file.h
 #include block.h
-#include qemu_socket.h

 //#define DEBUG_MIGRATION_FD

-- 
1.7.11.7




[Qemu-devel] [PATCH 20/34] savevm: New save live migration method: pending

2012-12-19 Thread Juan Quintela
Code just now does (simplified for clarity)

if (qemu_savevm_state_iterate(s-file) == 1) {
   vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
   qemu_savevm_state_complete(s-file);
}

Problem here is that qemu_savevm_state_iterate() returns 1 when it
knows that remaining memory to sent takes less than max downtime.

But this means that we could end spending 2x max_downtime, one
downtime in qemu_savevm_iterate, and the other in
qemu_savevm_state_complete.

Changed code to:

pending_size = qemu_savevm_state_pending(s-file, max_size);
DPRINTF(pending size %lu max %lu\n, pending_size, max_size);
if (pending_size = max_size) {
ret = qemu_savevm_state_iterate(s-file);
 } else {
vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
qemu_savevm_state_complete(s-file);
 }

So what we do is: at current network speed, we calculate the maximum
number of bytes we can sent: max_size.

Then we ask every save_live section how much they have pending.  If
they are less than max_size, we move to complete phase, otherwise we
do an iterate one.

This makes things much simpler, because now individual sections don't
have to caluclate the bandwidth (it was implossible to do right from
there).

Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
---
 arch_init.c   | 48 ++--
 block-migration.c | 49 ++---
 buffered_file.c   | 25 ++---
 migration.c   | 22 +++---
 migration.h   |  2 +-
 savevm.c  | 19 +++
 sysemu.h  |  1 +
 vmstate.h |  1 +
 8 files changed, 83 insertions(+), 84 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 9cee58a..f092ea2 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -582,12 +582,9 @@ static int ram_save_setup(QEMUFile *f, void *opaque)

 static int ram_save_iterate(QEMUFile *f, void *opaque)
 {
-uint64_t bytes_transferred_last;
-double bwidth = 0;
 int ret;
 int i;
-uint64_t expected_downtime;
-MigrationState *s = migrate_get_current();
+int64_t t0;

 qemu_mutex_lock_ramlist();

@@ -595,9 +592,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 reset_ram_globals();
 }

-bytes_transferred_last = bytes_transferred;
-bwidth = qemu_get_clock_ns(rt_clock);
-
+t0 = qemu_get_clock_ns(rt_clock);
 i = 0;
 while ((ret = qemu_file_rate_limit(f)) == 0) {
 int bytes_sent;
@@ -615,7 +610,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
iterations
 */
 if ((i  63) == 0) {
-uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 100;
+uint64_t t1 = (qemu_get_clock_ns(rt_clock) - t0) / 100;
 if (t1  MAX_WAIT) {
 DPRINTF(big wait: % PRIu64  milliseconds, %d iterations\n,
 t1, i);
@@ -629,31 +624,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 return ret;
 }

-bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
-bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
-
-/* if we haven't transferred anything this round, force
- * expected_downtime to a very high value, but without
- * crashing */
-if (bwidth == 0) {
-bwidth = 0.01;
-}
-
 qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);

-expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
-DPRINTF(ram_save_live: expected(% PRIu64 ) = max( PRIu64 )?\n,
-expected_downtime, migrate_max_downtime());
-
-if (expected_downtime = migrate_max_downtime()) {
-migration_bitmap_sync();
-expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
-s-expected_downtime = expected_downtime / 100; /* ns - ms */
-
-return expected_downtime = migrate_max_downtime();
-}
-return 0;
+return i;
 }

 static int ram_save_complete(QEMUFile *f, void *opaque)
@@ -683,6 +657,19 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 return 0;
 }

+static uint64_t ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size)
+{
+uint64_t remaining_size;
+
+remaining_size = ram_save_remaining() * TARGET_PAGE_SIZE;
+
+if (remaining_size  max_size) {
+migration_bitmap_sync();
+remaining_size = ram_save_remaining() * TARGET_PAGE_SIZE;
+}
+return remaining_size;
+}
+
 static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
 {
 int ret, rc = 0;
@@ -869,6 +856,7 @@ SaveVMHandlers savevm_ram_handlers = {
 .save_live_setup = ram_save_setup,
 .save_live_iterate = ram_save_iterate,
 .save_live_complete = ram_save_complete,
+.save_live_pending = ram_save_pending,
 .load_state = ram_load,
 .cancel = ram_migration_cancel,
 };
diff --git a/block-migration.c b/block-migration.c

[Qemu-devel] [PATCH 21/34] migration: move buffered_file.c code into migration.c

2012-12-19 Thread Juan Quintela
This only moves the code (also from buffered_file.h to migration.h).
Fix whitespace until checkpatch is happy.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 Makefile.objs   |   2 +-
 buffered_file.c | 259 
 buffered_file.h |  22 -
 migration.c | 233 +-
 migration.h |   1 +
 5 files changed, 234 insertions(+), 283 deletions(-)
 delete mode 100644 buffered_file.c
 delete mode 100644 buffered_file.h

diff --git a/Makefile.objs b/Makefile.objs
index 3c7abca..f0309ac 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -79,7 +79,7 @@ extra-obj-$(CONFIG_LINUX) += fsdev/

 common-obj-y += tcg-runtime.o host-utils.o main-loop.o
 common-obj-y += input.o
-common-obj-y += buffered_file.o migration.o migration-tcp.o
+common-obj-y += migration.o migration-tcp.o
 common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o iohandler.o
 common-obj-y += bitmap.o bitops.o
diff --git a/buffered_file.c b/buffered_file.c
deleted file mode 100644
index dda9db8..000
--- a/buffered_file.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * QEMU buffered QEMUFile
- *
- * Copyright IBM, Corp. 2008
- *
- * Authors:
- *  Anthony Liguori   aligu...@us.ibm.com
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- *
- * Contributions after 2012-01-13 are licensed under the terms of the
- * GNU GPL, version 2 or (at your option) any later version.
- */
-
-#include qemu-common.h
-#include hw/hw.h
-#include qemu-timer.h
-#include qemu-char.h
-#include buffered_file.h
-#include qemu-thread.h
-
-//#define DEBUG_BUFFERED_FILE
-
-typedef struct QEMUFileBuffered
-{
-MigrationState *migration_state;
-QEMUFile *file;
-size_t bytes_xfer;
-size_t xfer_limit;
-uint8_t *buffer;
-size_t buffer_size;
-size_t buffer_capacity;
-QemuThread thread;
-} QEMUFileBuffered;
-
-#ifdef DEBUG_BUFFERED_FILE
-#define DPRINTF(fmt, ...) \
-do { printf(buffered-file:  fmt, ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) \
-do { } while (0)
-#endif
-
-static ssize_t buffered_flush(QEMUFileBuffered *s)
-{
-size_t offset = 0;
-ssize_t ret = 0;
-
-DPRINTF(flushing %zu byte(s) of data\n, s-buffer_size);
-
-while (s-bytes_xfer  s-xfer_limit  offset  s-buffer_size) {
-size_t to_send = MIN(s-buffer_size - offset, s-xfer_limit - 
s-bytes_xfer);
-ret = migrate_fd_put_buffer(s-migration_state, s-buffer + offset,
-to_send);
-if (ret = 0) {
-DPRINTF(error flushing data, %zd\n, ret);
-break;
-} else {
-DPRINTF(flushed %zd byte(s)\n, ret);
-offset += ret;
-s-bytes_xfer += ret;
-}
-}
-
-DPRINTF(flushed %zu of %zu byte(s)\n, offset, s-buffer_size);
-memmove(s-buffer, s-buffer + offset, s-buffer_size - offset);
-s-buffer_size -= offset;
-
-if (ret  0) {
-return ret;
-}
-return offset;
-}
-
-static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, 
int size)
-{
-QEMUFileBuffered *s = opaque;
-ssize_t error;
-
-DPRINTF(putting %d bytes at % PRId64 \n, size, pos);
-
-error = qemu_file_get_error(s-file);
-if (error) {
-DPRINTF(flush when error, bailing: %s\n, strerror(-error));
-return error;
-}
-
-if (size = 0) {
-return size;
-}
-
-if (size  (s-buffer_capacity - s-buffer_size)) {
-DPRINTF(increasing buffer capacity from %zu by %zu\n,
-s-buffer_capacity, size + 1024);
-
-s-buffer_capacity += size + 1024;
-
-s-buffer = g_realloc(s-buffer, s-buffer_capacity);
-}
-
-memcpy(s-buffer + s-buffer_size, buf, size);
-s-buffer_size += size;
-
-return size;
-}
-
-static int buffered_close(void *opaque)
-{
-QEMUFileBuffered *s = opaque;
-ssize_t ret = 0;
-int ret2;
-
-DPRINTF(closing\n);
-
-s-xfer_limit = INT_MAX;
-while (!qemu_file_get_error(s-file)  s-buffer_size) {
-ret = buffered_flush(s);
-if (ret  0) {
-break;
-}
-}
-
-ret2 = migrate_fd_close(s-migration_state);
-if (ret = 0) {
-ret = ret2;
-}
-ret = migrate_fd_close(s-migration_state);
-s-migration_state-complete = true;
-return ret;
-}
-
-/*
- * The meaning of the return values is:
- *   0: We can continue sending
- *   1: Time to stop
- *   negative: There has been an error
- */
-static int buffered_get_fd(void *opaque)
-{
-QEMUFileBuffered *s = opaque;
-
-return qemu_get_fd(s-file);
-}
-
-static int buffered_rate_limit(void *opaque)
-{
-QEMUFileBuffered *s = opaque;
-int ret;
-
-ret = qemu_file_get_error(s-file);
-if (ret) {
-return ret;
-}
-
-if (s-bytes_xfer  s-xfer_limit)
-return 1;
-
-return 0;
-}
-
-static int64_t 

[Qemu-devel] [PATCH 24/34] migration: Inline qemu_fopen_ops_buffered into migrate_fd_connect

2012-12-19 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 11 +++
 migration.h |  2 --
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/migration.c b/migration.c
index 7a27987..5a4ad74 100644
--- a/migration.c
+++ b/migration.c
@@ -371,13 +371,6 @@ bool migration_has_failed(MigrationState *s)
 s-state == MIG_STATE_ERROR);
 }

-void migrate_fd_connect(MigrationState *s)
-{
-s-state = MIG_STATE_ACTIVE;
-s-first_time = true;
-qemu_fopen_ops_buffered(s);
-}
-
 static MigrationState *migrate_init(const MigrationParams *params)
 {
 MigrationState *s = migrate_get_current();
@@ -803,10 +796,12 @@ static const QEMUFileOps buffered_file_ops = {
 .set_rate_limit = buffered_set_rate_limit,
 };

-void qemu_fopen_ops_buffered(MigrationState *migration_state)
+void migrate_fd_connect(MigrationState *migration_state)
 {
 QEMUFileBuffered *s;

+migration_state-state = MIG_STATE_ACTIVE;
+migration_state-first_time = true;
 s = g_malloc0(sizeof(*s));

 s-migration_state = migration_state;
diff --git a/migration.h b/migration.h
index 705a331..542197e 100644
--- a/migration.h
+++ b/migration.h
@@ -127,6 +127,4 @@ int migrate_use_xbzrle(void);
 int64_t migrate_xbzrle_cache_size(void);

 int64_t xbzrle_cache_resize(int64_t new_size);
-
-void qemu_fopen_ops_buffered(MigrationState *migration_state);
 #endif
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH 00/34] migration thread and queue

2012-12-19 Thread Paolo Bonzini
Il 19/12/2012 13:33, Juan Quintela ha scritto:
 Hi
 
 This is my queue for migration-thread and patches associated.  This
 integrates review comments  code for Paolo.  This is the subset from
 both approachs that we agreed with. rest of patches need more review
 and are not here.
 
 Migrating and idle guest with upstwream:
 
 (qemu) info migrate
 capabilities: xbzrle: off
 Migration status: completed
 total time: 34251 milliseconds
 downtime: 492 milliseconds
 transferred ram: 762458 kbytes
 remaining ram: 0 kbytes
 total ram: 14688768 kbytes
 duplicate: 3492606 pages
 normal: 189762 pages
 normal bytes: 759048 kbytes
 
 with this series of patches.
 
 (qemu) info migrate
 capabilities: xbzrle: off
 Migration status: completed
 total time: 30712 milliseconds
 downtime: 29 milliseconds
 transferred ram: 738857 kbytes
 remaining ram: 0 kbytes
 total ram: 14688768 kbytes
 duplicate: 3503423 pages
 normal: 176671 pages
 normal bytes: 706684 kbytes
 
 Notice the big difference in downtime.  And that is also seen inside
 the guest a program that just do an idle loop seeing how long it
 takes to wait for 10ms.
 
 with upstream:
 
 [root@d1 ~]# ./timer
 delay of 452 ms
 delay of 114 ms
 delay of 136 ms
 delay of 135 ms
 delay of 136 ms
 delay of 131 ms
 delay of 134 ms
 
 with this series of patches, wait never takes 100ms, nothing is printed.
 
 Please review.
 
 Thanks, Juan.
 
 
 The following changes since commit 914606d26e654d4c01bd5186f4d05e3fd445e219:
 
   Merge remote-tracking branch 'stefanha/trivial-patches' into staging 
 (2012-12-18 15:41:43 -0600)
 
 are available in the git repository at:
 
 
   git://repo.or.cz/qemu/quintela.git thread.next
 
 for you to fetch changes up to 065bebbacf54dcad48aad42112417dbb44451499:
 
   migration: merge QEMUFileBuffered into MigrationState (2012-12-19 13:21:29 
 +0100)
 
 
 Juan Quintela (25):
   migration: include qemu-file.h
   migration-fd: remove duplicate include
   buffered_file: Move from using a timer to use a thread
   migration: make qemu_fopen_ops_buffered() return void
   migration: move migration thread init code to migrate_fd_put_ready
   migration: make writes blocking
   migration: remove unfreeze logic
   migration: just lock migrate_fd_put_ready
   buffered_file: Unfold the trick to restart generating migration data
   buffered_file: don't flush on put buffer
   buffered_file: unfold buffered_append in buffered_put_buffer
   savevm: New save live migration method: pending
   migration: move buffered_file.c code into migration.c
   migration: add XFER_LIMIT_RATIO
   migration: move migration_fd_put_ready()
   migration: Inline qemu_fopen_ops_buffered into migrate_fd_connect
   migration: move migration notifier
   ram: rename last_block to last_seen_block
   ram: Add last_sent_block
   memory: introduce memory_region_test_and_clear_dirty
   ram: Use memory_region_test_and_clear_dirty
   ram: optimize migration bitmap walking
   ram: account the amount of transferred ram better
   ram: refactor ram_save_block() return value
   migration: merge QEMUFileBuffered into MigrationState
 
 Paolo Bonzini (7):
   migration: fix migration_bitmap leak
   buffered_file: do not send more than s-bytes_xfer bytes per tick
   migration: remove double call to migrate_fd_close
   exec: change ramlist from MRU order to a 1-item cache
   exec: change RAM list to a TAILQ
   exec: sort the memory from biggest to smallest
   migration: fix qemu_get_fd for BufferedFile
 
 Umesh Deshpande (2):
   add a version number to ram_list
   protect the ramlist with a separate mutex
 
  Makefile.objs   |   2 +-
  arch_init.c | 245 +++---
  block-migration.c   |  49 ++
  buffered_file.c | 269 -
  buffered_file.h |  22 ---
  cpu-all.h   |  15 +-
  dump.c  |   8 +-
  exec.c  | 128 +++-
  memory.c|  16 ++
  memory.h|  16 ++
  memory_mapping.c|   4 +-
  migration-exec.c|   3 +-
  migration-fd.c  |   4 +-
  migration-tcp.c |   3 +-
  migration-unix.c|   3 +-
  migration.c | 390 
 
  migration.h |  13 +-
  qemu-file.h |   5 -
  savevm.c|  24 ++-
  sysemu.h|   1 +
  target-i386/arch_dump.c |   2 +-
  vmstate.h   |   1 +
  22 files changed, 599 insertions(+), 624 deletions(-)
  delete mode 100644 buffered_file.c
  delete mode 100644 buffered_file.h
 
 

Yay.

Acked-by: Paolo Bonzini pbonz...@redhat.com

Paolo



[Qemu-devel] [PATCH 07/34] exec: change RAM list to a TAILQ

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 24 
 cpu-all.h   |  4 ++--
 dump.c  |  8 
 exec.c  | 34 +-
 memory_mapping.c|  4 ++--
 target-i386/arch_dump.c |  2 +-
 6 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index b03b1d4..3c1aa00 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -382,7 +382,7 @@ static void migration_bitmap_sync(void)
 trace_migration_bitmap_sync_start();
 memory_global_sync_dirty_bitmap(get_system_memory());

-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 for (addr = 0; addr  block-length; addr += TARGET_PAGE_SIZE) {
 if (memory_region_get_dirty(block-mr, addr, TARGET_PAGE_SIZE,
 DIRTY_MEMORY_MIGRATION)) {
@@ -424,7 +424,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 ram_addr_t current_addr;

 if (!block)
-block = QLIST_FIRST(ram_list.blocks);
+block = QTAILQ_FIRST(ram_list.blocks);

 do {
 mr = block-mr;
@@ -465,9 +465,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 offset += TARGET_PAGE_SIZE;
 if (offset = block-length) {
 offset = 0;
-block = QLIST_NEXT(block, next);
+block = QTAILQ_NEXT(block, next);
 if (!block)
-block = QLIST_FIRST(ram_list.blocks);
+block = QTAILQ_FIRST(ram_list.blocks);
 }
 } while (block != last_block || offset != last_offset);

@@ -499,7 +499,7 @@ uint64_t ram_bytes_total(void)
 RAMBlock *block;
 uint64_t total = 0;

-QLIST_FOREACH(block, ram_list.blocks, next)
+QTAILQ_FOREACH(block, ram_list.blocks, next)
 total += block-length;

 return total;
@@ -518,18 +518,18 @@ static void sort_ram_list(void)
 RAMBlock *block, *nblock, **blocks;
 int n;
 n = 0;
-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 ++n;
 }
 blocks = g_malloc(n * sizeof *blocks);
 n = 0;
-QLIST_FOREACH_SAFE(block, ram_list.blocks, next, nblock) {
+QTAILQ_FOREACH_SAFE(block, ram_list.blocks, next, nblock) {
 blocks[n++] = block;
-QLIST_REMOVE(block, next);
+QTAILQ_REMOVE(ram_list.blocks, block, next);
 }
 qsort(blocks, n, sizeof *blocks, block_compar);
 while (--n = 0) {
-QLIST_INSERT_HEAD(ram_list.blocks, blocks[n], next);
+QTAILQ_INSERT_HEAD(ram_list.blocks, blocks[n], next);
 }
 g_free(blocks);
 }
@@ -597,7 +597,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)

 qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);

-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 qemu_put_byte(f, strlen(block-idstr));
 qemu_put_buffer(f, (uint8_t *)block-idstr, strlen(block-idstr));
 qemu_put_be64(f, block-length);
@@ -763,7 +763,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
 qemu_get_buffer(f, (uint8_t *)id, len);
 id[len] = 0;

-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 if (!strncmp(id, block-idstr, sizeof(id)))
 return memory_region_get_ram_ptr(block-mr) + offset;
 }
@@ -807,7 +807,7 @@ static int ram_load(QEMUFile *f, void *opaque, int 
version_id)
 id[len] = 0;
 length = qemu_get_be64(f);

-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 if (!strncmp(id, block-idstr, sizeof(id))) {
 if (block-length != length) {
 ret =  -EINVAL;
diff --git a/cpu-all.h b/cpu-all.h
index 973b504..cd61320 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -487,7 +487,7 @@ typedef struct RAMBlock {
 ram_addr_t length;
 uint32_t flags;
 char idstr[256];
-QLIST_ENTRY(RAMBlock) next;
+QTAILQ_ENTRY(RAMBlock) next;
 #if defined(__linux__)  !defined(TARGET_S390X)
 int fd;
 #endif
@@ -496,7 +496,7 @@ typedef struct RAMBlock {
 typedef struct RAMList {
 uint8_t *phys_dirty;
 RAMBlock *mru_block;
-QLIST_HEAD(, RAMBlock) blocks;
+QTAILQ_HEAD(, RAMBlock) blocks;
 } RAMList;
 extern RAMList ram_list;

diff --git a/dump.c b/dump.c
index 5640c2c..b088cb4 100644
--- a/dump.c
+++ b/dump.c
@@ -427,7 +427,7 @@ static hwaddr get_offset(hwaddr phys_addr,
 }
 }

-QLIST_FOREACH(block, ram_list.blocks, next) {
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
 if (s-has_filter) {
 if (block-offset = s-begin + 

Re: [Qemu-devel] [PATCH qom-cpu v2] cpu: Introduce CPUListState struct

2012-12-19 Thread Eduardo Habkost
On Wed, Dec 19, 2012 at 02:00:32PM +0100, Igor Mammedov wrote:
 On Wed, 19 Dec 2012 02:03:55 +0100
 Andreas Färber afaer...@suse.de wrote:
 
  This generalizes {ARM,M68k,Alpha}CPUListState to avoid declaring it for
  each target. Place it in cpu-common.h to avoid circular dependencies.
  
  Signed-off-by: Andreas Färber afaer...@suse.de
  Cc: Eduardo Habkost ehabk...@redhat.com
  Cc: Igor Mammedov imamm...@redhat.com

Reviewed-by: Eduardo Habkost ehabk...@redhat.com

  ---
   cpu-common.h |   12 
   target-alpha/cpu.c   |9 ++---
   target-arm/helper.c  |9 ++---
   target-m68k/helper.c |9 ++---
   4 Dateien geändert, 18 Zeilen hinzugefügt(+), 21 Zeilen entfernt(-)
  
  diff --git a/cpu-common.h b/cpu-common.h
  index d2fbafa..a62b6ea 100644
  --- a/cpu-common.h
  +++ b/cpu-common.h
  @@ -12,6 +12,18 @@
   #include bswap.h
   #include qemu-queue.h
   
  +/**
  + * CPUListState:
  + * @cpu_fprintf: Print function.
  + * @file: File to print to using @cpu_fprint.
  + *
  + * State commonly used for iterating over CPU models.
  + */
  +typedef struct CPUListState {
  +fprintf_function cpu_fprintf;
  +FILE *file;
  +} CPUListState;
  +
   #if !defined(CONFIG_USER_ONLY)
   
   enum device_endian {
  diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
  index 2deb3c1..59d8669 100644
  --- a/target-alpha/cpu.c
  +++ b/target-alpha/cpu.c
  @@ -33,11 +33,6 @@ static void alpha_cpu_realize(Object *obj, Error **errp)
   #endif
   }
   
  -typedef struct AlphaCPUListState {
  -fprintf_function cpu_fprintf;
  -FILE *file;
  -} AlphaCPUListState;
  -
   /* Sort alphabetically by type name. */
   static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
   {
  @@ -53,7 +48,7 @@ static gint alpha_cpu_list_compare(gconstpointer a,
  gconstpointer b) static void alpha_cpu_list_entry(gpointer data, gpointer
  user_data) {
   ObjectClass *oc = data;
  -AlphaCPUListState *s = user_data;
  +CPUListState *s = user_data;
   
   (*s-cpu_fprintf)(s-file,   %s\n,
 object_class_get_name(oc));
  @@ -61,7 +56,7 @@ static void alpha_cpu_list_entry(gpointer data, gpointer
  user_data) 
   void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
   {
  -AlphaCPUListState s = {
  +CPUListState s = {
   .file = f,
   .cpu_fprintf = cpu_fprintf,
   };
  diff --git a/target-arm/helper.c b/target-arm/helper.c
  index ab8b734..d2f2fb4 100644
  --- a/target-arm/helper.c
  +++ b/target-arm/helper.c
  @@ -1291,11 +1291,6 @@ ARMCPU *cpu_arm_init(const char *cpu_model)
   return cpu;
   }
   
  -typedef struct ARMCPUListState {
  -fprintf_function cpu_fprintf;
  -FILE *file;
  -} ARMCPUListState;
  -
   /* Sort alphabetically by type name, except for any. */
   static gint arm_cpu_list_compare(gconstpointer a, gconstpointer b)
   {
  @@ -1317,7 +1312,7 @@ static gint arm_cpu_list_compare(gconstpointer a,
  gconstpointer b) static void arm_cpu_list_entry(gpointer data, gpointer
  user_data) {
   ObjectClass *oc = data;
  -ARMCPUListState *s = user_data;
  +CPUListState *s = user_data;
   
   (*s-cpu_fprintf)(s-file,   %s\n,
 object_class_get_name(oc));
  @@ -1325,7 +1320,7 @@ static void arm_cpu_list_entry(gpointer data,
  gpointer user_data) 
   void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
   {
  -ARMCPUListState s = {
  +CPUListState s = {
   .file = f,
   .cpu_fprintf = cpu_fprintf,
   };
  diff --git a/target-m68k/helper.c b/target-m68k/helper.c
  index a5d0100..875a71a 100644
  --- a/target-m68k/helper.c
  +++ b/target-m68k/helper.c
  @@ -25,11 +25,6 @@
   
   #define SIGNBIT (1u  31)
   
  -typedef struct M68kCPUListState {
  -fprintf_function cpu_fprintf;
  -FILE *file;
  -} M68kCPUListState;
  -
   /* Sort alphabetically, except for any. */
   static gint m68k_cpu_list_compare(gconstpointer a, gconstpointer b)
   {
  @@ -51,7 +46,7 @@ static gint m68k_cpu_list_compare(gconstpointer a,
  gconstpointer b) static void m68k_cpu_list_entry(gpointer data, gpointer
  user_data) {
   ObjectClass *c = data;
  -M68kCPUListState *s = user_data;
  +CPUListState *s = user_data;
   
   (*s-cpu_fprintf)(s-file, %s\n,
 object_class_get_name(c));
  @@ -59,7 +54,7 @@ static void m68k_cpu_list_entry(gpointer data, gpointer
  user_data) 
   void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
   {
  -M68kCPUListState s = {
  +CPUListState s = {
   .file = f,
   .cpu_fprintf = cpu_fprintf,
   };
 
 Reviewed-By: Igor Mammedov imamm...@redhat.com

-- 
Eduardo



[Qemu-devel] [PATCH 11/34] buffered_file: Move from using a timer to use a thread

2012-12-19 Thread Juan Quintela
We still protect everything except the wait with the iothread lock.
But we moved from a timer to a thread.  Steps one by one.

We also need to detect when we have finished with a variable complete.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 buffered_file.c | 58 +++--
 1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 9a8bd04..2750cc3 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -18,6 +18,7 @@
 #include qemu-timer.h
 #include qemu-char.h
 #include buffered_file.h
+#include qemu-thread.h

 //#define DEBUG_BUFFERED_FILE

@@ -31,7 +32,8 @@ typedef struct QEMUFileBuffered
 uint8_t *buffer;
 size_t buffer_size;
 size_t buffer_capacity;
-QEMUTimer *timer;
+QemuThread thread;
+bool complete;
 } QEMUFileBuffered;

 #ifdef DEBUG_BUFFERED_FILE
@@ -160,11 +162,8 @@ static int buffered_close(void *opaque)
 if (ret = 0) {
 ret = ret2;
 }
-qemu_del_timer(s-timer);
-qemu_free_timer(s-timer);
-g_free(s-buffer);
-g_free(s);
-
+ret = migrate_fd_close(s-migration_state);
+s-complete = true;
 return ret;
 }

@@ -222,23 +221,38 @@ static int64_t buffered_get_rate_limit(void *opaque)
 return s-xfer_limit;
 }

-static void buffered_rate_tick(void *opaque)
+/* 10ms  xfer_limit is the limit that we should write each 10ms */
+#define BUFFER_DELAY 100
+
+static void *buffered_file_thread(void *opaque)
 {
 QEMUFileBuffered *s = opaque;
+int64_t expire_time = qemu_get_clock_ms(rt_clock) + BUFFER_DELAY;

-if (qemu_file_get_error(s-file)) {
-buffered_close(s);
-return;
-}
-
-qemu_mod_timer(s-timer, qemu_get_clock_ms(rt_clock) + 100);
-
-if (s-freeze_output)
-return;
-
-s-bytes_xfer = 0;
+while (true) {
+int64_t current_time = qemu_get_clock_ms(rt_clock);

-buffered_put_buffer(s, NULL, 0, 0);
+if (s-complete) {
+break;
+}
+if (s-freeze_output) {
+continue;
+}
+if (current_time = expire_time) {
+s-bytes_xfer = 0;
+expire_time = current_time + BUFFER_DELAY;
+}
+if (s-bytes_xfer = s-xfer_limit) {
+/* usleep expects microseconds */
+g_usleep((expire_time - current_time)*1000);
+}
+qemu_mutex_lock_iothread();
+buffered_put_buffer(s, NULL, 0, 0);
+qemu_mutex_unlock_iothread();
+}
+g_free(s-buffer);
+g_free(s);
+return NULL;
 }

 static const QEMUFileOps buffered_file_ops = {
@@ -258,12 +272,12 @@ QEMUFile *qemu_fopen_ops_buffered(MigrationState 
*migration_state)

 s-migration_state = migration_state;
 s-xfer_limit = migration_state-bandwidth_limit / 10;
+s-complete = false;

 s-file = qemu_fopen_ops(s, buffered_file_ops);

-s-timer = qemu_new_timer_ms(rt_clock, buffered_rate_tick, s);
-
-qemu_mod_timer(s-timer, qemu_get_clock_ms(rt_clock) + 100);
+qemu_thread_create(s-thread, buffered_file_thread, s,
+   QEMU_THREAD_DETACHED);

 return s-file;
 }
-- 
1.7.11.7




[Qemu-devel] [PATCH 23/34] migration: move migration_fd_put_ready()

2012-12-19 Thread Juan Quintela
Put it near its use and un-export it.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 130 ++--
 migration.h |   1 -
 2 files changed, 65 insertions(+), 66 deletions(-)

diff --git a/migration.c b/migration.c
index a233215..7a27987 100644
--- a/migration.c
+++ b/migration.c
@@ -321,71 +321,6 @@ ssize_t migrate_fd_put_buffer(MigrationState *s, const 
void *data,
 return ret;
 }

-bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
-{
-int ret;
-uint64_t pending_size;
-bool last_round = false;
-
-qemu_mutex_lock_iothread();
-if (s-state != MIG_STATE_ACTIVE) {
-DPRINTF(put_ready returning because of non-active state\n);
-qemu_mutex_unlock_iothread();
-return false;
-}
-if (s-first_time) {
-s-first_time = false;
-DPRINTF(beginning savevm\n);
-ret = qemu_savevm_state_begin(s-file, s-params);
-if (ret  0) {
-DPRINTF(failed, %d\n, ret);
-migrate_fd_error(s);
-qemu_mutex_unlock_iothread();
-return false;
-}
-}
-
-DPRINTF(iterate\n);
-pending_size = qemu_savevm_state_pending(s-file, max_size);
-DPRINTF(pending size %lu max %lu\n, pending_size, max_size);
-if (pending_size = max_size) {
-ret = qemu_savevm_state_iterate(s-file);
-if (ret  0) {
-migrate_fd_error(s);
-}
-} else {
-int old_vm_running = runstate_is_running();
-int64_t start_time, end_time;
-
-DPRINTF(done iterating\n);
-start_time = qemu_get_clock_ms(rt_clock);
-qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
-if (old_vm_running) {
-vm_stop(RUN_STATE_FINISH_MIGRATE);
-} else {
-vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-}
-
-if (qemu_savevm_state_complete(s-file)  0) {
-migrate_fd_error(s);
-} else {
-migrate_fd_completed(s);
-}
-end_time = qemu_get_clock_ms(rt_clock);
-s-total_time = end_time - s-total_time;
-s-downtime = end_time - start_time;
-if (s-state != MIG_STATE_COMPLETED) {
-if (old_vm_running) {
-vm_start();
-}
-}
-last_round = true;
-}
-qemu_mutex_unlock_iothread();
-
-return last_round;
-}
-
 static void migrate_fd_cancel(MigrationState *s)
 {
 if (s-state != MIG_STATE_ACTIVE)
@@ -748,6 +683,71 @@ static int64_t buffered_get_rate_limit(void *opaque)
 return s-xfer_limit;
 }

+static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
+{
+int ret;
+uint64_t pending_size;
+bool last_round = false;
+
+qemu_mutex_lock_iothread();
+if (s-state != MIG_STATE_ACTIVE) {
+DPRINTF(put_ready returning because of non-active state\n);
+qemu_mutex_unlock_iothread();
+return false;
+}
+if (s-first_time) {
+s-first_time = false;
+DPRINTF(beginning savevm\n);
+ret = qemu_savevm_state_begin(s-file, s-params);
+if (ret  0) {
+DPRINTF(failed, %d\n, ret);
+migrate_fd_error(s);
+qemu_mutex_unlock_iothread();
+return false;
+}
+}
+
+DPRINTF(iterate\n);
+pending_size = qemu_savevm_state_pending(s-file, max_size);
+DPRINTF(pending size %lu max %lu\n, pending_size, max_size);
+if (pending_size = max_size) {
+ret = qemu_savevm_state_iterate(s-file);
+if (ret  0) {
+migrate_fd_error(s);
+}
+} else {
+int old_vm_running = runstate_is_running();
+int64_t start_time, end_time;
+
+DPRINTF(done iterating\n);
+start_time = qemu_get_clock_ms(rt_clock);
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+if (old_vm_running) {
+vm_stop(RUN_STATE_FINISH_MIGRATE);
+} else {
+vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+}
+
+if (qemu_savevm_state_complete(s-file)  0) {
+migrate_fd_error(s);
+} else {
+migrate_fd_completed(s);
+}
+end_time = qemu_get_clock_ms(rt_clock);
+s-total_time = end_time - s-total_time;
+s-downtime = end_time - start_time;
+if (s-state != MIG_STATE_COMPLETED) {
+if (old_vm_running) {
+vm_start();
+}
+}
+last_round = true;
+}
+qemu_mutex_unlock_iothread();
+
+return last_round;
+}
+
 static void *buffered_file_thread(void *opaque)
 {
 QEMUFileBuffered *s = opaque;
diff --git a/migration.h b/migration.h
index 31ed7af..705a331 100644
--- a/migration.h
+++ b/migration.h
@@ -81,7 +81,6 @@ void migrate_fd_connect(MigrationState *s);

 ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
   size_t size);
-bool 

[Qemu-devel] [PATCH 13/34] migration: move migration thread init code to migrate_fd_put_ready

2012-12-19 Thread Juan Quintela
This way everything related with migration is run on the migration
thread and no locking is needed.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 29 +
 migration.h |  1 +
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/migration.c b/migration.c
index f32fe3e..90dbe8e 100644
--- a/migration.c
+++ b/migration.c
@@ -20,6 +20,7 @@
 #include sysemu.h
 #include block.h
 #include qemu_socket.h
+#include qemu-thread.h
 #include block-migration.h
 #include qmp-commands.h

@@ -339,6 +340,16 @@ void migrate_fd_put_ready(MigrationState *s)
 DPRINTF(put_ready returning because of non-active state\n);
 return;
 }
+if (s-first_time) {
+s-first_time = false;
+DPRINTF(beginning savevm\n);
+ret = qemu_savevm_state_begin(s-file, s-params);
+if (ret  0) {
+DPRINTF(failed, %d\n, ret);
+migrate_fd_error(s);
+return;
+}
+}

 DPRINTF(iterate\n);
 ret = qemu_savevm_state_iterate(s-file);
@@ -351,7 +362,11 @@ void migrate_fd_put_ready(MigrationState *s)
 DPRINTF(done iterating\n);
 start_time = qemu_get_clock_ms(rt_clock);
 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
-vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+if (old_vm_running) {
+vm_stop(RUN_STATE_FINISH_MIGRATE);
+} else {
+vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+}

 if (qemu_savevm_state_complete(s-file)  0) {
 migrate_fd_error(s);
@@ -445,19 +460,9 @@ bool migration_has_failed(MigrationState *s)

 void migrate_fd_connect(MigrationState *s)
 {
-int ret;
-
 s-state = MIG_STATE_ACTIVE;
+s-first_time = true;
 qemu_fopen_ops_buffered(s);
-
-DPRINTF(beginning savevm\n);
-ret = qemu_savevm_state_begin(s-file, s-params);
-if (ret  0) {
-DPRINTF(failed, %d\n, ret);
-migrate_fd_error(s);
-return;
-}
-migrate_fd_put_ready(s);
 }

 static MigrationState *migrate_init(const MigrationParams *params)
diff --git a/migration.h b/migration.h
index b66fd60..8f2ff8a 100644
--- a/migration.h
+++ b/migration.h
@@ -46,6 +46,7 @@ struct MigrationState
 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 int64_t xbzrle_cache_size;
 bool complete;
+bool first_time;
 };

 void process_incoming_migration(QEMUFile *f);
-- 
1.7.11.7




[Qemu-devel] [PATCH 06/34] exec: change ramlist from MRU order to a 1-item cache

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Most of the time, only 2 items will be active (from/to for a string operation,
or code/data).  But TCG guests likely won't have gigabytes of memory, so
this actually goes down to 1 item.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c |  1 +
 cpu-all.h   |  1 +
 exec.c  | 49 -
 3 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 0d7844c..b03b1d4 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -48,6 +48,7 @@
 #include qemu/page_cache.h
 #include qmp-commands.h
 #include trace.h
+#include cpu-all.h

 #ifdef DEBUG_ARCH_INIT
 #define DPRINTF(fmt, ...) \
diff --git a/cpu-all.h b/cpu-all.h
index d6b2b19..973b504 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -495,6 +495,7 @@ typedef struct RAMBlock {

 typedef struct RAMList {
 uint8_t *phys_dirty;
+RAMBlock *mru_block;
 QLIST_HEAD(, RAMBlock) blocks;
 } RAMList;
 extern RAMList ram_list;
diff --git a/exec.c b/exec.c
index 4c1246a..a3dbe2f 100644
--- a/exec.c
+++ b/exec.c
@@ -42,6 +42,7 @@
 #include xen-mapcache.h
 #include trace.h
 #endif
+#include cpu-all.h

 #include cputlb.h
 #include translate-all.h
@@ -1042,6 +1043,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 new_block-length = size;

 QLIST_INSERT_HEAD(ram_list.blocks, new_block, next);
+ram_list.mru_block = NULL;

 ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
last_ram_offset()  TARGET_PAGE_BITS);
@@ -1070,6 +1072,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr)
 QLIST_FOREACH(block, ram_list.blocks, next) {
 if (addr == block-offset) {
 QLIST_REMOVE(block, next);
+ram_list.mru_block = NULL;
 g_free(block);
 return;
 }
@@ -1083,6 +1086,7 @@ void qemu_ram_free(ram_addr_t addr)
 QLIST_FOREACH(block, ram_list.blocks, next) {
 if (addr == block-offset) {
 QLIST_REMOVE(block, next);
+ram_list.mru_block = NULL;
 if (block-flags  RAM_PREALLOC_MASK) {
 ;
 } else if (mem_path) {
@@ -1188,37 +1192,40 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
 {
 RAMBlock *block;

+block = ram_list.mru_block;
+if (block  addr - block-offset  block-length) {
+goto found;
+}
 QLIST_FOREACH(block, ram_list.blocks, next) {
 if (addr - block-offset  block-length) {
-/* Move this entry to to start of the list.  */
-if (block != QLIST_FIRST(ram_list.blocks)) {
-QLIST_REMOVE(block, next);
-QLIST_INSERT_HEAD(ram_list.blocks, block, next);
-}
-if (xen_enabled()) {
-/* We need to check if the requested address is in the RAM
- * because we don't want to map the entire memory in QEMU.
- * In that case just map until the end of the page.
- */
-if (block-offset == 0) {
-return xen_map_cache(addr, 0, 0);
-} else if (block-host == NULL) {
-block-host =
-xen_map_cache(block-offset, block-length, 1);
-}
-}
-return block-host + (addr - block-offset);
+goto found;
 }
 }

 fprintf(stderr, Bad ram offset % PRIx64 \n, (uint64_t)addr);
 abort();

-return NULL;
+found:
+ram_list.mru_block = block;
+if (xen_enabled()) {
+/* We need to check if the requested address is in the RAM
+ * because we don't want to map the entire memory in QEMU.
+ * In that case just map until the end of the page.
+ */
+if (block-offset == 0) {
+return xen_map_cache(addr, 0, 0);
+} else if (block-host == NULL) {
+block-host =
+xen_map_cache(block-offset, block-length, 1);
+}
+}
+return block-host + (addr - block-offset);
 }

-/* Return a host pointer to ram allocated with qemu_ram_alloc.
- * Same as qemu_get_ram_ptr but avoid reordering ramblocks.
+/* Return a host pointer to ram allocated with qemu_ram_alloc.  Same as
+ * qemu_get_ram_ptr but do not touch ram_list.mru_block.
+ *
+ * ??? Is this still necessary?
  */
 static void *qemu_safe_ram_ptr(ram_addr_t addr)
 {
-- 
1.7.11.7




[Qemu-devel] [PATCH] spice: drop incorrect vm_change_state_handler() opaque

2012-12-19 Thread Stefan Hajnoczi
The spice_server pointer is a global variable and
vm_change_state_handler() therefore does not use its opaque parameter.

The vm change state handler is added with a pointer to the spice_server
pointer.  This is useless and we probably would not want 2 levels of
pointers.

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 ui/spice-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index ac46deb..c128c0b 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -709,7 +709,7 @@ void qemu_spice_init(void)
 qemu_spice_input_init();
 qemu_spice_audio_init();
 
-qemu_add_vm_change_state_handler(vm_change_state_handler, spice_server);
+qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
 
 g_free(x509_key_file);
 g_free(x509_cert_file);
@@ -736,8 +736,7 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin)
  */
 spice_server = spice_server_new();
 spice_server_init(spice_server, core_interface);
-qemu_add_vm_change_state_handler(vm_change_state_handler,
- spice_server);
+qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
 }
 
 return spice_server_add_interface(spice_server, sin);
-- 
1.8.0.2




Re: [Qemu-devel] [PATCH 3/3] virtio-pci: don't poll masked vectors

2012-12-19 Thread Stefan Hajnoczi
On Tue, Dec 18, 2012 at 02:39:19PM +0200, Michael S. Tsirkin wrote:
 -static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign)
 +static void kvm_virtio_pci_vector_poll(PCIDevice *dev,
 +   unsigned int vector_start,
 +   unsigned int vector_end)
 +{
 +VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
 +VirtIODevice *vdev = proxy-vdev;
 +int queue_no;
 +unsigned int vector;
 +EventNotifier *notifier;
 +VirtQueue *vq;
 +
 +for (queue_no = 0; queue_no  VIRTIO_PCI_QUEUE_MAX; queue_no++) {
 +if (!virtio_queue_get_num(vdev, queue_no)) {
 +break;
 +}
 +vector = virtio_queue_vector(vdev, queue_no);
 +if (vector  vector_start || vector = vector_end ||
 +!msix_is_masked(dev, vector)) {
 +continue;
 +}
 +vq = virtio_get_queue(vdev, queue_no);
 +notifier = virtio_queue_get_guest_notifier(vq);
 +if (event_notifier_test_and_clear(notifier)) {
 +msix_set_pending(dev, vector);
 +}

Small difference to virtio_queue_guest_notifier_read() here: we do not
set vq-vdev-isr |= 0x01.  I guess no guest drivers use isr with MSIX
but should we still set it or even just call
virtio_queue_guest_notifier_read() instead of duplicating that event
notifier read here?

Stefan



[Qemu-devel] [PATCH 17/34] buffered_file: Unfold the trick to restart generating migration data

2012-12-19 Thread Juan Quintela
This was needed before due to the way that the callbacks worked.

Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
---
 buffered_file.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 5cd477a..f4f5110 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -113,14 +113,6 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in
 return error;
 }

-if (pos == 0  size == 0) {
-DPRINTF(file is ready\n);
-if (s-bytes_xfer  s-xfer_limit) {
-DPRINTF(notifying client\n);
-migrate_fd_put_ready(s-migration_state);
-}
-}
-
 return size;
 }

@@ -223,8 +215,17 @@ static void *buffered_file_thread(void *opaque)
 /* usleep expects microseconds */
 g_usleep((expire_time - current_time)*1000);
 }
-buffered_put_buffer(s, NULL, 0, 0);
+if (buffered_flush(s)  0) {
+break;
+}
+
+DPRINTF(file is ready\n);
+if (s-bytes_xfer  s-xfer_limit) {
+DPRINTF(notifying client\n);
+migrate_fd_put_ready(s-migration_state);
+}
 }
+
 g_free(s-buffer);
 g_free(s);
 return NULL;
-- 
1.7.11.7




[Qemu-devel] [PATCH 27/34] ram: Add last_sent_block

2012-12-19 Thread Juan Quintela
This is the last block from where we have sent data.

Signed-off-by: Orit Wasserman owass...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch_init.c b/arch_init.c
index 34a2f4b..af57cdb 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -336,6 +336,8 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t 
*current_data,
 /* This is the last block that we have visited serching for dirty pages
  */
 static RAMBlock *last_seen_block;
+/* This is the last block from where we have sent data */
+static RAMBlock *last_sent_block;
 static ram_addr_t last_offset;
 static unsigned long *migration_bitmap;
 static uint64_t migration_dirty_pages;
@@ -433,7 +435,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 mr = block-mr;
 if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
 uint8_t *p;
-int cont = (block == last_seen_block) ?
+int cont = (block == last_sent_block) ?
 RAM_SAVE_FLAG_CONTINUE : 0;

 p = memory_region_get_ram_ptr(mr) + offset;
@@ -462,6 +464,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)

 /* if page is unmodified, continue to the next */
 if (bytes_sent != 0) {
+last_sent_block = block;
 break;
 }
 }
@@ -535,6 +538,7 @@ static void ram_migration_cancel(void *opaque)
 static void reset_ram_globals(void)
 {
 last_seen_block = NULL;
+last_sent_block = NULL;
 last_offset = 0;
 last_version = ram_list.version;
 }
-- 
1.7.11.7




[Qemu-devel] [PATCH 12/34] migration: make qemu_fopen_ops_buffered() return void

2012-12-19 Thread Juan Quintela
We want the file assignment to happen before the thread is created to
avoid locking, so we just do it before creating the thread.

Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Orit Wasserman owass...@redhat.com
---
 buffered_file.c | 13 ++---
 buffered_file.h |  2 +-
 migration.c |  2 +-
 migration.h |  1 +
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 2750cc3..18da74b 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -33,7 +33,6 @@ typedef struct QEMUFileBuffered
 size_t buffer_size;
 size_t buffer_capacity;
 QemuThread thread;
-bool complete;
 } QEMUFileBuffered;

 #ifdef DEBUG_BUFFERED_FILE
@@ -163,7 +162,7 @@ static int buffered_close(void *opaque)
 ret = ret2;
 }
 ret = migrate_fd_close(s-migration_state);
-s-complete = true;
+s-migration_state-complete = true;
 return ret;
 }

@@ -232,7 +231,7 @@ static void *buffered_file_thread(void *opaque)
 while (true) {
 int64_t current_time = qemu_get_clock_ms(rt_clock);

-if (s-complete) {
+if (s-migration_state-complete) {
 break;
 }
 if (s-freeze_output) {
@@ -264,7 +263,7 @@ static const QEMUFileOps buffered_file_ops = {
 .set_rate_limit = buffered_set_rate_limit,
 };

-QEMUFile *qemu_fopen_ops_buffered(MigrationState *migration_state)
+void qemu_fopen_ops_buffered(MigrationState *migration_state)
 {
 QEMUFileBuffered *s;

@@ -272,12 +271,12 @@ QEMUFile *qemu_fopen_ops_buffered(MigrationState 
*migration_state)

 s-migration_state = migration_state;
 s-xfer_limit = migration_state-bandwidth_limit / 10;
-s-complete = false;
+s-migration_state-complete = false;

 s-file = qemu_fopen_ops(s, buffered_file_ops);

+migration_state-file = s-file;
+
 qemu_thread_create(s-thread, buffered_file_thread, s,
QEMU_THREAD_DETACHED);
-
-return s-file;
 }
diff --git a/buffered_file.h b/buffered_file.h
index ef010fe..8a246fd 100644
--- a/buffered_file.h
+++ b/buffered_file.h
@@ -17,6 +17,6 @@
 #include hw/hw.h
 #include migration.h

-QEMUFile *qemu_fopen_ops_buffered(MigrationState *migration_state);
+void qemu_fopen_ops_buffered(MigrationState *migration_state);

 #endif
diff --git a/migration.c b/migration.c
index bde4956..f32fe3e 100644
--- a/migration.c
+++ b/migration.c
@@ -448,7 +448,7 @@ void migrate_fd_connect(MigrationState *s)
 int ret;

 s-state = MIG_STATE_ACTIVE;
-s-file = qemu_fopen_ops_buffered(s);
+qemu_fopen_ops_buffered(s);

 DPRINTF(beginning savevm\n);
 ret = qemu_savevm_state_begin(s-file, s-params);
diff --git a/migration.h b/migration.h
index c3a23cc..b66fd60 100644
--- a/migration.h
+++ b/migration.h
@@ -45,6 +45,7 @@ struct MigrationState
 int64_t dirty_pages_rate;
 bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 int64_t xbzrle_cache_size;
+bool complete;
 };

 void process_incoming_migration(QEMUFile *f);
-- 
1.7.11.7




[Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smallest

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 30 --
 exec.c  | 14 --
 2 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 3c1aa00..8b5980f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -505,35 +505,6 @@ uint64_t ram_bytes_total(void)
 return total;
 }

-static int block_compar(const void *a, const void *b)
-{
-RAMBlock * const *ablock = a;
-RAMBlock * const *bblock = b;
-
-return strcmp((*ablock)-idstr, (*bblock)-idstr);
-}
-
-static void sort_ram_list(void)
-{
-RAMBlock *block, *nblock, **blocks;
-int n;
-n = 0;
-QTAILQ_FOREACH(block, ram_list.blocks, next) {
-++n;
-}
-blocks = g_malloc(n * sizeof *blocks);
-n = 0;
-QTAILQ_FOREACH_SAFE(block, ram_list.blocks, next, nblock) {
-blocks[n++] = block;
-QTAILQ_REMOVE(ram_list.blocks, block, next);
-}
-qsort(blocks, n, sizeof *blocks, block_compar);
-while (--n = 0) {
-QTAILQ_INSERT_HEAD(ram_list.blocks, blocks[n], next);
-}
-g_free(blocks);
-}
-
 static void migration_end(void)
 {
 if (migration_bitmap) {
@@ -562,7 +533,6 @@ static void reset_ram_globals(void)
 {
 last_block = NULL;
 last_offset = 0;
-sort_ram_list();
 }

 #define MAX_WAIT 50 /* ms, half buffered_file limit */
diff --git a/exec.c b/exec.c
index 13c894d..5f501d4 100644
--- a/exec.c
+++ b/exec.c
@@ -1006,7 +1006,7 @@ static int memory_try_enable_merging(void *addr, size_t 
len)
 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
MemoryRegion *mr)
 {
-RAMBlock *new_block;
+RAMBlock *block, *new_block;

 size = TARGET_PAGE_ALIGN(size);
 new_block = g_malloc0(sizeof(*new_block));
@@ -1042,7 +1042,17 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 }
 new_block-length = size;

-QTAILQ_INSERT_HEAD(ram_list.blocks, new_block, next);
+/* Keep the list sorted from biggest to smallest block.  */
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
+if (block-length  new_block-length) {
+break;
+}
+}
+if (block) {
+QTAILQ_INSERT_BEFORE(block, new_block, next);
+} else {
+QTAILQ_INSERT_TAIL(ram_list.blocks, new_block, next);
+}
 ram_list.mru_block = NULL;

 ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
-- 
1.7.11.7




[Qemu-devel] [PATCH 31/34] ram: account the amount of transferred ram better

2012-12-19 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 34 --
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 978fe37..43a5b9e 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -265,16 +265,21 @@ uint64_t xbzrle_mig_pages_overflow(void)
 return acct_info.xbzrle_overflows;
 }

-static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
-int cont, int flag)
+static size_t save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
+ int cont, int flag)
 {
-qemu_put_be64(f, offset | cont | flag);
-if (!cont) {
-qemu_put_byte(f, strlen(block-idstr));
-qemu_put_buffer(f, (uint8_t *)block-idstr,
-strlen(block-idstr));
-}
+size_t size;
+
+qemu_put_be64(f, offset | cont | flag);
+size = 8;

+if (!cont) {
+qemu_put_byte(f, strlen(block-idstr));
+qemu_put_buffer(f, (uint8_t *)block-idstr,
+strlen(block-idstr));
+size += 1 + strlen(block-idstr);
+}
+return size;
 }

 #define ENCODING_FLAG_XBZRLE 0x1
@@ -321,11 +326,11 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t 
*current_data,
 }

 /* Send XBZRLE based compressed page */
-save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
+bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
 qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
 qemu_put_be16(f, encoded_len);
 qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
-bytes_sent = encoded_len + 1 + 2;
+bytes_sent += encoded_len + 1 + 2;
 acct_info.xbzrle_pages++;
 acct_info.xbzrle_bytes += bytes_sent;

@@ -457,9 +462,10 @@ static int ram_save_block(QEMUFile *f, bool last_stage)

 if (is_dup_page(p)) {
 acct_info.dup_pages++;
-save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
+bytes_sent = save_block_hdr(f, block, offset, cont,
+RAM_SAVE_FLAG_COMPRESS);
 qemu_put_byte(f, *p);
-bytes_sent = 1;
+bytes_sent += 1;
 } else if (migrate_use_xbzrle()) {
 current_addr = block-offset + offset;
 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
@@ -471,9 +477,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage)

 /* either we didn't send yet (we may have had XBZRLE overflow) */
 if (bytes_sent == -1) {
-save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
+bytes_sent = save_block_hdr(f, block, offset, cont, 
RAM_SAVE_FLAG_PAGE);
 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
-bytes_sent = TARGET_PAGE_SIZE;
+bytes_sent += TARGET_PAGE_SIZE;
 acct_info.norm_pages++;
 }

-- 
1.7.11.7




[Qemu-devel] [PATCH 20/20] MAINTAINERS: Include X86CPU in CPU maintenance area

2012-12-19 Thread Andreas Färber
Document that the x86 CPU refactorings are going through the qom-cpu
tree. This does not contradict the established practice that patches
adding KVM features to the x86 CPU go through the KVM maintainers,
it merely takes it out of target-i386 TCG's Odd Fixes status.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Marcello Tosatti mtosa...@redhat.com
---
 MAINTAINERS |1 +
 1 Datei geändert, 1 Zeile hinzugefügt(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2ede20d..61d5a4b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -599,6 +599,7 @@ M: Andreas Färber afaer...@suse.de
 S: Supported
 F: qom/cpu.c
 F: include/qemu/cpu.h
+F: target-i386/cpu.c
 
 Device Tree
 M: Peter Crosthwaite peter.crosthwa...@petalogix.com
-- 
1.7.10.4




[Qemu-devel] [PATCH 11/20] kvm: Pass CPUState to kvm_vcpu_ioctl()

2012-12-19 Thread Andreas Färber
Adapt helper functions to pass X86CPU / PowerPCCPU / S390CPU.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/kvm/apic.c  |   10 +--
 hw/kvm/clock.c |2 +-
 hw/ppc.c   |2 +-
 hw/s390-virtio-bus.c   |   12 ++--
 hw/spapr.c |2 +-
 kvm-all.c  |   14 ++--
 kvm.h  |2 +-
 target-i386/kvm.c  |  158 
 target-ppc/kvm.c   |   55 ---
 target-ppc/kvm_ppc.h   |8 +--
 target-s390x/cpu.h |   12 ++--
 target-s390x/interrupt.c   |3 +-
 target-s390x/kvm.c |   62 +
 target-s390x/misc_helper.c |2 +-
 14 Dateien geändert, 188 Zeilen hinzugefügt(+), 156 Zeilen entfernt(-)

diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
index 8b65d51..c4d74ee 100644
--- a/hw/kvm/apic.c
+++ b/hw/kvm/apic.c
@@ -104,7 +104,7 @@ static void kvm_apic_enable_tpr_reporting(APICCommonState 
*s, bool enable)
 .enabled = enable
 };
 
-kvm_vcpu_ioctl(s-cpu-env, KVM_TPR_ACCESS_REPORTING, ctl);
+kvm_vcpu_ioctl(CPU(s-cpu), KVM_TPR_ACCESS_REPORTING, ctl);
 }
 
 static void kvm_apic_vapic_base_update(APICCommonState *s)
@@ -114,7 +114,7 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
 };
 int ret;
 
-ret = kvm_vcpu_ioctl(s-cpu-env, KVM_SET_VAPIC_ADDR, vapid_addr);
+ret = kvm_vcpu_ioctl(CPU(s-cpu), KVM_SET_VAPIC_ADDR, vapid_addr);
 if (ret  0) {
 fprintf(stderr, KVM: setting VAPIC address failed (%s)\n,
 strerror(-ret));
@@ -125,15 +125,15 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
 static void do_inject_external_nmi(void *data)
 {
 APICCommonState *s = data;
-CPUX86State *env = s-cpu-env;
+CPUState *cpu = CPU(s-cpu);
 uint32_t lvt;
 int ret;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(s-cpu-env);
 
 lvt = s-lvt[APIC_LVT_LINT1];
 if (!(lvt  APIC_LVT_MASKED)  ((lvt  8)  7) == APIC_DM_NMI) {
-ret = kvm_vcpu_ioctl(env, KVM_NMI);
+ret = kvm_vcpu_ioctl(cpu, KVM_NMI);
 if (ret  0) {
 fprintf(stderr, KVM: injection failed, NMI lost (%s)\n,
 strerror(-ret));
diff --git a/hw/kvm/clock.c b/hw/kvm/clock.c
index 824b978..4cf62f6 100644
--- a/hw/kvm/clock.c
+++ b/hw/kvm/clock.c
@@ -76,7 +76,7 @@ static void kvmclock_vm_state_change(void *opaque, int 
running,
 return;
 }
 for (penv = first_cpu; penv != NULL; penv = penv-next_cpu) {
-ret = kvm_vcpu_ioctl(penv, KVM_KVMCLOCK_CTRL, 0);
+ret = kvm_vcpu_ioctl(ENV_GET_CPU(penv), KVM_KVMCLOCK_CTRL, 0);
 if (ret) {
 if (ret != -EINVAL) {
 fprintf(stderr, %s: %s\n, __func__, strerror(-ret));
diff --git a/hw/ppc.c b/hw/ppc.c
index 11fd199..e99a93d 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -65,7 +65,7 @@ void ppc_set_irq(CPUPPCState *env, int n_IRQ, int level)
 
 if (old_pending != env-pending_interrupts) {
 #ifdef CONFIG_KVM
-kvmppc_set_interrupt(env, n_IRQ, level);
+kvmppc_set_interrupt(ppc_env_get_cpu(env), n_IRQ, level);
 #endif
 }
 
diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index e0ac2d1..716028d 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -111,10 +111,12 @@ VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
 return bus;
 }
 
-static void s390_virtio_irq(CPUS390XState *env, int config_change, uint64_t 
token)
+static void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token)
 {
+CPUS390XState *env = cpu-env;
+
 if (kvm_enabled()) {
-kvm_s390_virtio_irq(env, config_change, token);
+kvm_s390_virtio_irq(cpu, config_change, token);
 } else {
 cpu_inject_ext(env, VIRTIO_EXT_CODE, config_change, token);
 }
@@ -143,8 +145,7 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, 
VirtIODevice *vdev)
 s390_virtio_reset_idx(dev);
 if (dev-qdev.hotplugged) {
 S390CPU *cpu = s390_cpu_addr2state(0);
-CPUS390XState *env = cpu-env;
-s390_virtio_irq(env, VIRTIO_PARAM_DEV_ADD, dev-dev_offs);
+s390_virtio_irq(cpu, VIRTIO_PARAM_DEV_ADD, dev-dev_offs);
 }
 
 return 0;
@@ -369,9 +370,8 @@ static void virtio_s390_notify(void *opaque, uint16_t 
vector)
 VirtIOS390Device *dev = (VirtIOS390Device*)opaque;
 uint64_t token = s390_virtio_device_vq_token(dev, vector);
 S390CPU *cpu = s390_cpu_addr2state(0);
-CPUS390XState *env = cpu-env;
 
-s390_virtio_irq(env, 0, token);
+s390_virtio_irq(cpu, 0, token);
 }
 
 static unsigned virtio_s390_get_features(void *opaque)
diff --git a/hw/spapr.c b/hw/spapr.c
index 504d0fc..341f0b9 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -797,7 +797,7 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
 /* Tell KVM that we're in PAPR mode */
 if (kvm_enabled()) {
-

[Qemu-devel] [PATCH 08/20] qdev-properties.c: Separate core from the code used only by qemu-system-*

2012-12-19 Thread Andreas Färber
From: Eduardo Habkost ehabk...@redhat.com

This separates the qdev properties code in two parts:
 - qdev-properties.c, that contains most of the qdev properties code;
 - qdev-properties-system.c for code specific for qemu-system-*,
   containing:
   - Property types: drive, chr, netdev, vlan, that depend on code that
 won't be included on *-user
   - qemu_add_globals(), that depends on qemu-config.o.

This change should help on two things:
 - Allowing DeviceState to be used by *-user without pulling
   dependencies that are specific for qemu-system-*;
 - Writing qdev unit tests without pulling too many dependencies.

The copyright/license of qdev-properties.c isn't explicitly stated at
the file, so add a simple copyright/license header pointing to the
commit ID of the original file.

Signed-off-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/Makefile.objs|1 +
 hw/qdev-properties-system.c |  357 +++
 hw/qdev-properties.c|  327 +--
 hw/qdev-properties.h|1 +
 hw/qdev.c   |   14 --
 5 Dateien geändert, 360 Zeilen hinzugefügt(+), 340 Zeilen entfernt(-)
 create mode 100644 hw/qdev-properties-system.c

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d581d8d..96a8365 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -185,6 +185,7 @@ common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
 common-obj-y += bt-hci-csr.o
 common-obj-y += msmouse.o ps2.o
 common-obj-y += qdev.o qdev-properties.o qdev-monitor.o
+common-obj-y += qdev-properties-system.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 
 # xen backend driver support
diff --git a/hw/qdev-properties-system.c b/hw/qdev-properties-system.c
new file mode 100644
index 000..86b4cf6
--- /dev/null
+++ b/hw/qdev-properties-system.c
@@ -0,0 +1,357 @@
+/*
+ * qdev property parsing and global properties
+ * (parts specific for qemu-system-*)
+ *
+ * This file is based on code from hw/qdev-properties.c from
+ * commit 074a86fccd185616469dfcdc0e157f438aebba18,
+ * Copyright (c) Gerd Hoffmann kra...@redhat.com and other contributors.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include net.h
+#include qdev.h
+#include qerror.h
+#include blockdev.h
+#include hw/block-common.h
+#include net/hub.h
+#include qapi/qapi-visit-core.h
+
+static void get_pointer(Object *obj, Visitor *v, Property *prop,
+const char *(*print)(void *ptr),
+const char *name, Error **errp)
+{
+DeviceState *dev = DEVICE(obj);
+void **ptr = qdev_get_prop_ptr(dev, prop);
+char *p;
+
+p = (char *) (*ptr ? print(*ptr) : );
+visit_type_str(v, p, name, errp);
+}
+
+static void set_pointer(Object *obj, Visitor *v, Property *prop,
+int (*parse)(DeviceState *dev, const char *str,
+ void **ptr),
+const char *name, Error **errp)
+{
+DeviceState *dev = DEVICE(obj);
+Error *local_err = NULL;
+void **ptr = qdev_get_prop_ptr(dev, prop);
+char *str;
+int ret;
+
+if (dev-state != DEV_STATE_CREATED) {
+error_set(errp, QERR_PERMISSION_DENIED);
+return;
+}
+
+visit_type_str(v, str, name, local_err);
+if (local_err) {
+error_propagate(errp, local_err);
+return;
+}
+if (!*str) {
+g_free(str);
+*ptr = NULL;
+return;
+}
+ret = parse(dev, str, ptr);
+error_set_from_qdev_prop_error(errp, ret, dev, prop, str);
+g_free(str);
+}
+
+/* --- drive --- */
+
+static int parse_drive(DeviceState *dev, const char *str, void **ptr)
+{
+BlockDriverState *bs;
+
+bs = bdrv_find(str);
+if (bs == NULL) {
+return -ENOENT;
+}
+if (bdrv_attach_dev(bs, dev)  0) {
+return -EEXIST;
+}
+*ptr = bs;
+return 0;
+}
+
+static void release_drive(Object *obj, const char *name, void *opaque)
+{
+DeviceState *dev = DEVICE(obj);
+Property *prop = opaque;
+BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
+
+if (*ptr) {
+bdrv_detach_dev(*ptr, dev);
+blockdev_auto_del(*ptr);
+}
+}
+
+static const char *print_drive(void *ptr)
+{
+return bdrv_get_device_name(ptr);
+}
+
+static void get_drive(Object *obj, Visitor *v, void *opaque,
+  const char *name, Error **errp)
+{
+get_pointer(obj, v, opaque, print_drive, name, errp);
+}
+
+static void set_drive(Object *obj, Visitor *v, void *opaque,
+  const char *name, Error **errp)
+{
+set_pointer(obj, v, opaque, parse_drive, name, errp);
+}
+
+PropertyInfo qdev_prop_drive = {
+.name  = drive,
+.get   = get_drive,
+.set   = set_drive,
+.release = release_drive,
+};
+
+/* --- character device --- */
+
+static int 

[Qemu-devel] How to make TCP/IP applications run on guest OS?

2012-12-19 Thread GaoYi
Hi all,

   I have bridged the network of the host. There was one br0 and several
taps on it. When I started up a guest using:

 #kvm -hda ubuntu.img -localtime -m 1G  -net nic, -net
tap,ifname=tap0,script=no

   The guest can ping to other VMs or physical PCs within the same LAN.
However, when I tried to communicate with other VMs/PCs using TCP/IP,
the incoming IP at the receiver side is the same as the host IP instead of
the VM's IP. Then how to configure the network so that
the TCP/IP applications run well just like the phsical PC?

   Thanks,

Yi


Re: [Qemu-devel] [RFC PATCH v4 00/30] ACPI memory hotplug

2012-12-19 Thread Gerd Hoffmann
  Hi,

 correct, only the number of channels and ranks(dimms) per channel has been
 emulated so far (2 channels of 4 dimms each). So it is still paravirtual 
 memory
 hotplug, not native. Native support still needs to be worked on.

Ok.

 I think the paravirtual memory hotplug controller should be a PCI device
 (which we then can add as function to the chipset).  Having some fixed
 magic addresses is bad.
 
 ok, so in your opinion a pci-based hotplug controller sounds better than 
 adding
 acpi ports to piix4 or ich9?
 
 Magic acpi_ich9 ports can be avoided if q35 native support is implemented.

Yes.  We should go that route for q35.

 For
 i440fx/piix4 it was discussed and more or less decided we would only support
 a paravirtual way of memory hotplug. 

Sure, there is no other way to do it.

It is probably a good idea to model piix4 paravirtual to work simliar to
q35 native.

 In the description. I meant paravirtual memory bus to describe a memory bus
 with unlimited number of dimm devices. But the hotplug control has always
 been acpi-based so far and not a pci device.

It still can (and should) be acpi-based.  It is just that:

  (a) Instead of using get_system_io() as parent memory region you use
  create a pci device and place the memory region in one of the PCI
  bars.
  (b) Instead of using OperationRegion($name, SystemIO, $magicaddress)
  you use OperationRegion($name, PciBarTarget, ...) to access the
  registers.

cheers,
  Gerd



[Qemu-devel] [PATCH 22/34] migration: add XFER_LIMIT_RATIO

2012-12-19 Thread Juan Quintela
The magic divisions by 10 are there because of the value of BUFFER_DELAY.
Introduce a constant to explain them better.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/migration.c b/migration.c
index 26bb85e..a233215 100644
--- a/migration.c
+++ b/migration.c
@@ -44,6 +44,11 @@ enum {

 #define MAX_THROTTLE  (32  20)  /* Migration speed throttling */

+/* Amount of time to allocate to each chunk of bandwidth-throttled
+ * data. */
+#define BUFFER_DELAY 100
+#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
+
 /* Migration XBZRLE default cache size */
 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)

@@ -743,9 +748,6 @@ static int64_t buffered_get_rate_limit(void *opaque)
 return s-xfer_limit;
 }

-/* 100ms  xfer_limit is the limit that we should write each 100ms */
-#define BUFFER_DELAY 100
-
 static void *buffered_file_thread(void *opaque)
 {
 QEMUFileBuffered *s = opaque;
@@ -808,7 +810,7 @@ void qemu_fopen_ops_buffered(MigrationState 
*migration_state)
 s = g_malloc0(sizeof(*s));

 s-migration_state = migration_state;
-s-xfer_limit = migration_state-bandwidth_limit / 10;
+s-xfer_limit = s-migration_state-bandwidth_limit / XFER_LIMIT_RATIO;
 s-migration_state-complete = false;

 s-file = qemu_fopen_ops(s, buffered_file_ops);
-- 
1.7.11.7




[Qemu-devel] [PATCH 05/20] target-alpha: Add support for -cpu ?

2012-12-19 Thread Andreas Färber
Implement alphabetical listing of CPU subclasses.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Richard Henderson r...@twiddle.net
---
 target-alpha/cpu.c |   41 +
 target-alpha/cpu.h |2 ++
 2 Dateien geändert, 43 Zeilen hinzugefügt(+)

diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
index a5a98d0..2deb3c1 100644
--- a/target-alpha/cpu.c
+++ b/target-alpha/cpu.c
@@ -33,6 +33,47 @@ static void alpha_cpu_realize(Object *obj, Error **errp)
 #endif
 }
 
+typedef struct AlphaCPUListState {
+fprintf_function cpu_fprintf;
+FILE *file;
+} AlphaCPUListState;
+
+/* Sort alphabetically by type name. */
+static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
+{
+ObjectClass *class_a = (ObjectClass *)a;
+ObjectClass *class_b = (ObjectClass *)b;
+const char *name_a, *name_b;
+
+name_a = object_class_get_name(class_a);
+name_b = object_class_get_name(class_b);
+return strcmp(name_a, name_b);
+}
+
+static void alpha_cpu_list_entry(gpointer data, gpointer user_data)
+{
+ObjectClass *oc = data;
+AlphaCPUListState *s = user_data;
+
+(*s-cpu_fprintf)(s-file,   %s\n,
+  object_class_get_name(oc));
+}
+
+void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
+{
+AlphaCPUListState s = {
+.file = f,
+.cpu_fprintf = cpu_fprintf,
+};
+GSList *list;
+
+list = object_class_get_list(TYPE_ALPHA_CPU, false);
+list = g_slist_sort(list, alpha_cpu_list_compare);
+(*cpu_fprintf)(f, Available CPUs:\n);
+g_slist_foreach(list, alpha_cpu_list_entry, s);
+g_slist_free(list);
+}
+
 /* Models */
 
 #define TYPE(model) model - TYPE_ALPHA_CPU
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 0d08458..23f06c5 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -289,6 +289,7 @@ struct CPUAlphaState {
 int implver;
 };
 
+#define cpu_list alpha_cpu_list
 #define cpu_exec cpu_alpha_exec
 #define cpu_gen_code cpu_alpha_gen_code
 #define cpu_signal_handler cpu_alpha_signal_handler
@@ -438,6 +439,7 @@ static inline CPUAlphaState *cpu_init(const char *cpu_model)
 return cpu-env;
 }
 
+void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 int cpu_alpha_exec(CPUAlphaState *s);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
signal handlers to inform the virtual CPU of exceptions. non zero
-- 
1.7.10.4




[Qemu-devel] [PATCH 02/34] buffered_file: do not send more than s-bytes_xfer bytes per tick

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Sending more was possible if the buffer was large.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 buffered_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index bd0f61d..9a8bd04 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -66,9 +66,9 @@ static ssize_t buffered_flush(QEMUFileBuffered *s)
 DPRINTF(flushing %zu byte(s) of data\n, s-buffer_size);

 while (s-bytes_xfer  s-xfer_limit  offset  s-buffer_size) {
-
+size_t to_send = MIN(s-buffer_size - offset, s-xfer_limit - 
s-bytes_xfer);
 ret = migrate_fd_put_buffer(s-migration_state, s-buffer + offset,
-s-buffer_size - offset);
+to_send);
 if (ret == -EAGAIN) {
 DPRINTF(backend not ready, freezing\n);
 ret = 0;
-- 
1.7.11.7




[Qemu-devel] [PULL] QOM CPUState patch queue 2012-12-19

2012-12-19 Thread Andreas Färber
Hello,

This is my current QOM CPU patch queue. Please pull.

It includes:
* CPU subclasses for target-alpha,
* CPUListState cleanup (basis for all subsequent subclasses series),
* more steps towards CPU as a device (qdev-properties.c split),
* more CPUState field movements and API changes for KVM,
* adding target-i386/cpu.c to supported MAINTAINERS section.

The final CPU-as-a-device change is deferred to January, waiting on merge of
Paolo's header reorganization (esp. -Iinclude/ for stubs).

Happy holidays,
Andreas

Cc: Eduardo Habkost ehabk...@redhat.com
Cc: Igor Mammedov imamm...@redhat.com
Cc: Paolo Bonzini pbonz...@redhat.com
Cc: Marcello Tosatti mtosa...@redhat.com
Cc: Alexander Graf ag...@suse.de


The following changes since commit 914606d26e654d4c01bd5186f4d05e3fd445e219:

  Merge remote-tracking branch 'stefanha/trivial-patches' into staging 
(2012-12-18 15:41:43 -0600)

are available in the git repository at:


  git://github.com/afaerber/qemu-cpu.git qom-cpu

for you to fetch changes up to 62e0c095450f6a7eb37914991f3f7966aa4da7a1:

  MAINTAINERS: Include X86CPU in CPU maintenance area (2012-12-19 14:09:32 
+0100)


Andreas Färber (18):
  target-alpha: Let cpu_alpha_init() return AlphaCPU
  alpha: Pass AlphaCPU array to Typhoon
  target-alpha: Avoid leaking the alarm timer over reset
  target-alpha: Turn CPU definitions into subclasses
  target-alpha: Add support for -cpu ?
  cpu: Introduce CPUListState struct
  cpu: Move kvm_fd into CPUState
  kvm: Pass CPUState to kvm_arch_*
  kvm: Pass CPUState to kvm_vcpu_ioctl()
  ppc: Pass PowerPCCPU to ppc_set_irq()
  ppc: Pass PowerPCCPU to [h]decr callbacks
  ppc: Pass PowerPCCPU to [h]decr timer callbacks
  ppc_booke: Pass PowerPCCPU to {decr,fit,wdt} timer callbacks
  ppc4xx_devs: Return PowerPCCPU from ppc4xx_init()
  ppc_booke: Pass PowerPCCPU to ppc_booke_timers_init()
  cpu: Move kvm_state field into CPUState
  cpu: Move kvm_run into CPUState
  MAINTAINERS: Include X86CPU in CPU maintenance area

Eduardo Habkost (2):
  qdev: Coding style fixes
  qdev-properties.c: Separate core from the code used only by qemu-system-*

 MAINTAINERS |1 +
 cpu-common.h|   12 ++
 cpu-defs.h  |8 +-
 hw/Makefile.objs|1 +
 hw/alpha_dp264.c|   18 +--
 hw/alpha_sys.h  |2 +-
 hw/alpha_typhoon.c  |   30 ++--
 hw/kvm/apic.c   |   10 +-
 hw/kvm/clock.c  |2 +-
 hw/ppc.c|  128 +---
 hw/ppc.h|4 +-
 hw/ppc/e500.c   |2 +-
 hw/ppc405_uc.c  |   10 +-
 hw/ppc440_bamboo.c  |2 +-
 hw/ppc4xx.h |6 +-
 hw/ppc4xx_devs.c|8 +-
 hw/ppc_booke.c  |   44 +++---
 hw/qdev-properties-system.c |  357 +++
 hw/qdev-properties.c|  356 +++---
 hw/qdev-properties.h|1 +
 hw/qdev.c   |   13 --
 hw/s390-virtio-bus.c|   12 +-
 hw/spapr.c  |2 +-
 hw/virtex_ml507.c   |2 +-
 include/qemu/cpu.h  |   11 ++
 kvm-all.c   |  127 ---
 kvm.h   |   32 ++--
 target-alpha/cpu-qom.h  |3 +
 target-alpha/cpu.c  |  214 +-
 target-alpha/cpu.h  |   18 ++-
 target-alpha/sys_helper.c   |6 +-
 target-alpha/translate.c|   58 +--
 target-arm/helper.c |9 +-
 target-i386/cpu.c   |7 +-
 target-i386/kvm.c   |  240 +
 target-m68k/helper.c|9 +-
 target-ppc/kvm.c|  124 +--
 target-ppc/kvm_ppc.h|8 +-
 target-s390x/cpu.h  |   12 +-
 target-s390x/interrupt.c|3 +-
 target-s390x/kvm.c  |  176 +++--
 target-s390x/misc_helper.c  |2 +-
 42 Dateien geändert, 1223 Zeilen hinzugefügt(+), 867 Zeilen entfernt(-)
 create mode 100644 hw/qdev-properties-system.c



Re: [Qemu-devel] [PATCH v2 1/2] sheepdog: don't update inode when create_and_write fails

2012-12-19 Thread Stefan Hajnoczi
On Mon, Dec 17, 2012 at 02:17:26PM +0800, Liu Yuan wrote:
 From: Liu Yuan tailai...@taobao.com
 
 For the error case such as SD_RES_NO_SPACE, we shouldn't update the inode 
 bitmap
 to avoid the scenario that the object is allocated but wasn't created at the
 server side. This will result in VM's IO error on the failed object.
 
 Cc: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp
 Cc: Kevin Wolf kw...@redhat.com
 Signed-off-by: Liu Yuan tailai...@taobao.com
 ---
  block/sheepdog.c |9 +
  1 file changed, 5 insertions(+), 4 deletions(-)

Thanks, applied to the block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



[Qemu-devel] [PATCH 32/34] ram: refactor ram_save_block() return value

2012-12-19 Thread Juan Quintela
It could only return 0 if we only found dirty xbzrle pages that hadn't
changed (i.e. they were written with the same content).  We don't care
about that case, it is the same than nothing dirty.

So now the return of the function is how much have it written, nothing
else. Adjust callers.

And we also made ram_save_iterate() return the number of transferred
bytes, not the number of transferred pages.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 43a5b9e..588561b 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -422,9 +422,8 @@ static void migration_bitmap_sync(void)
 /*
  * ram_save_block: Writes a page of memory to the stream f
  *
- * Returns:  0: if the page hasn't changed
- *  -1: if there are no more dirty pages
- *   n: the amount of bytes written in other case
+ * Returns:  The number of bytes written.
+ *   0 means no dirty pages
  */

 static int ram_save_block(QEMUFile *f, bool last_stage)
@@ -432,7 +431,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 RAMBlock *block = last_seen_block;
 ram_addr_t offset = last_offset;
 bool complete_round = false;
-int bytes_sent = -1;
+int bytes_sent = 0;
 MemoryRegion *mr;
 ram_addr_t current_addr;

@@ -460,6 +459,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)

 p = memory_region_get_ram_ptr(mr) + offset;

+/* In doubt sent page as normal */
+bytes_sent = -1;
 if (is_dup_page(p)) {
 acct_info.dup_pages++;
 bytes_sent = save_block_hdr(f, block, offset, cont,
@@ -475,7 +476,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 }
 }

-/* either we didn't send yet (we may have had XBZRLE overflow) */
+/* XBZRLE overflow or normal page */
 if (bytes_sent == -1) {
 bytes_sent = save_block_hdr(f, block, offset, cont, 
RAM_SAVE_FLAG_PAGE);
 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
@@ -484,7 +485,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 }

 /* if page is unmodified, continue to the next */
-if (bytes_sent != 0) {
+if (bytes_sent  0) {
 last_sent_block = block;
 break;
 }
@@ -605,6 +606,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 int ret;
 int i;
 int64_t t0;
+int total_sent = 0;

 qemu_mutex_lock_ramlist();

@@ -619,10 +621,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)

 bytes_sent = ram_save_block(f, false);
 /* no more blocks to sent */
-if (bytes_sent  0) {
+if (bytes_sent == 0) {
 break;
 }
-bytes_transferred += bytes_sent;
+total_sent += bytes_sent;
 acct_info.iterations++;
 /* we want to check in the 1st loop, just in case it was the 1st time
and we had to sync the dirty bitmap.
@@ -641,13 +643,16 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 }

 if (ret  0) {
+bytes_transferred += total_sent;
 return ret;
 }

 qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+total_sent += 8;
+bytes_transferred += total_sent;

-return i;
+return total_sent;
 }

 static int ram_save_complete(QEMUFile *f, void *opaque)
@@ -664,7 +669,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)

 bytes_sent = ram_save_block(f, true);
 /* no more blocks to sent */
-if (bytes_sent  0) {
+if (bytes_sent == 0) {
 break;
 }
 bytes_transferred += bytes_sent;
-- 
1.7.11.7




[Qemu-devel] [PATCH 12/20] ppc: Pass PowerPCCPU to ppc_set_irq()

2012-12-19 Thread Andreas Färber
Adapt static caller functions.

This cleans up after passing PowerPCCPU to kvmppc_set_interrupt().

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/ppc.c   |   66 ++--
 hw/ppc.h   |2 +-
 hw/ppc_booke.c |   28 
 3 Dateien geändert, 60 Zeilen hinzugefügt(+), 36 Zeilen entfernt(-)

diff --git a/hw/ppc.c b/hw/ppc.c
index e99a93d..6db595f 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -50,8 +50,9 @@
 static void cpu_ppc_tb_stop (CPUPPCState *env);
 static void cpu_ppc_tb_start (CPUPPCState *env);
 
-void ppc_set_irq(CPUPPCState *env, int n_IRQ, int level)
+void ppc_set_irq(PowerPCCPU *cpu, int n_IRQ, int level)
 {
+CPUPPCState *env = cpu-env;
 unsigned int old_pending = env-pending_interrupts;
 
 if (level) {
@@ -65,7 +66,7 @@ void ppc_set_irq(CPUPPCState *env, int n_IRQ, int level)
 
 if (old_pending != env-pending_interrupts) {
 #ifdef CONFIG_KVM
-kvmppc_set_interrupt(ppc_env_get_cpu(env), n_IRQ, level);
+kvmppc_set_interrupt(cpu, n_IRQ, level);
 #endif
 }
 
@@ -100,13 +101,13 @@ static void ppc6xx_set_irq(void *opaque, int pin, int 
level)
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the external IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_EXT, level);
 break;
 case PPC6xx_INPUT_SMI:
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the SMI IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_SMI, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_SMI, level);
 break;
 case PPC6xx_INPUT_MCP:
 /* Negative edge sensitive */
@@ -116,7 +117,7 @@ static void ppc6xx_set_irq(void *opaque, int pin, int level)
 if (cur_level == 1  level == 0) {
 LOG_IRQ(%s: raise machine check state\n,
 __func__);
-ppc_set_irq(env, PPC_INTERRUPT_MCK, 1);
+ppc_set_irq(cpu, PPC_INTERRUPT_MCK, 1);
 }
 break;
 case PPC6xx_INPUT_CKSTP_IN:
@@ -138,7 +139,7 @@ static void ppc6xx_set_irq(void *opaque, int pin, int level)
 case PPC6xx_INPUT_SRESET:
 LOG_IRQ(%s: set the RESET IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_RESET, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_RESET, level);
 break;
 default:
 /* Unknown pin - do nothing */
@@ -178,13 +179,13 @@ static void ppc970_set_irq(void *opaque, int pin, int 
level)
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the external IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_EXT, level);
 break;
 case PPC970_INPUT_THINT:
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the SMI IRQ state to %d\n, __func__,
 level);
-ppc_set_irq(env, PPC_INTERRUPT_THERM, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_THERM, level);
 break;
 case PPC970_INPUT_MCP:
 /* Negative edge sensitive */
@@ -194,7 +195,7 @@ static void ppc970_set_irq(void *opaque, int pin, int level)
 if (cur_level == 1  level == 0) {
 LOG_IRQ(%s: raise machine check state\n,
 __func__);
-ppc_set_irq(env, PPC_INTERRUPT_MCK, 1);
+ppc_set_irq(cpu, PPC_INTERRUPT_MCK, 1);
 }
 break;
 case PPC970_INPUT_CKSTP:
@@ -218,7 +219,7 @@ static void ppc970_set_irq(void *opaque, int pin, int level)
 case PPC970_INPUT_SRESET:
 LOG_IRQ(%s: set the RESET IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_RESET, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_RESET, level);
 break;
 case PPC970_INPUT_TBEN:
 LOG_IRQ(%s: set the TBEN state to %d\n, __func__,
@@ -259,7 +260,7 @@ static void power7_set_irq(void *opaque, int pin, int level)
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the external IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
+ppc_set_irq(cpu, PPC_INTERRUPT_EXT, level);
 break;
 default:
 /* Unknown pin - do nothing */
@@ -319,13 +320,13 @@ static void ppc40x_set_irq(void *opaque, int pin, int 
level)
 /* Level sensitive - active high */
 LOG_IRQ(%s: set the critical IRQ state to %d\n,
 __func__, level);
-ppc_set_irq(env, PPC_INTERRUPT_CEXT, level);

[Qemu-devel] [PATCH 33/34] migration: fix qemu_get_fd for BufferedFile

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Not really used, but nice to have it correct. :)

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration.c b/migration.c
index cabf17b..ca39564 100644
--- a/migration.c
+++ b/migration.c
@@ -625,7 +625,7 @@ static int buffered_get_fd(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-return qemu_get_fd(s-file);
+return s-migration_state-fd;
 }

 /*
-- 
1.7.11.7




[Qemu-devel] [PATCH 03/34] migration: remove double call to migrate_fd_close

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

The call in buffered_close is enough, because buffered_close is called
already by migrate_fd_cleanup.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration.c b/migration.c
index 73ce170..bde4956 100644
--- a/migration.c
+++ b/migration.c
@@ -272,7 +272,7 @@ static int migrate_fd_cleanup(MigrationState *s)
 s-file = NULL;
 }

-migrate_fd_close(s);
+assert(s-fd == -1);
 return ret;
 }

-- 
1.7.11.7




[Qemu-devel] [PATCH 29/34] ram: Use memory_region_test_and_clear_dirty

2012-12-19 Thread Juan Quintela
This avoids having to do two walks over the dirty bitmap, once reading
the dirty bits, and anthoer cleaning them.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index af57cdb..562f721 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -390,13 +390,12 @@ static void migration_bitmap_sync(void)

 QTAILQ_FOREACH(block, ram_list.blocks, next) {
 for (addr = 0; addr  block-length; addr += TARGET_PAGE_SIZE) {
-if (memory_region_get_dirty(block-mr, addr, TARGET_PAGE_SIZE,
-DIRTY_MEMORY_MIGRATION)) {
+if (memory_region_test_and_clear_dirty(block-mr,
+   addr, TARGET_PAGE_SIZE,
+   DIRTY_MEMORY_MIGRATION)) {
 migration_bitmap_set_dirty(block-mr, addr);
 }
 }
-memory_region_reset_dirty(block-mr, 0, block-length,
-  DIRTY_MEMORY_MIGRATION);
 }
 trace_migration_bitmap_sync_end(migration_dirty_pages
 - num_dirty_pages_init);
-- 
1.7.11.7




[Qemu-devel] [PATCH 09/34] add a version number to ram_list

2012-12-19 Thread Juan Quintela
From: Umesh Deshpande udesh...@redhat.com

This will be used to detect if last_block might have become invalid
across different calls to ram_save_live.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Umesh Deshpande udesh...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Orit Wasserman owass...@redhat.com
---
 arch_init.c | 7 ++-
 cpu-all.h   | 1 +
 exec.c  | 4 
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch_init.c b/arch_init.c
index 8b5980f..136d0e8 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -336,6 +336,7 @@ static RAMBlock *last_block;
 static ram_addr_t last_offset;
 static unsigned long *migration_bitmap;
 static uint64_t migration_dirty_pages;
+static uint32_t last_version;

 static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
  ram_addr_t offset)
@@ -406,7 +407,6 @@ static void migration_bitmap_sync(void)
 }
 }

-
 /*
  * ram_save_block: Writes a page of memory to the stream f
  *
@@ -533,6 +533,7 @@ static void reset_ram_globals(void)
 {
 last_block = NULL;
 last_offset = 0;
+last_version = ram_list.version;
 }

 #define MAX_WAIT 50 /* ms, half buffered_file limit */
@@ -587,6 +588,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 uint64_t expected_downtime;
 MigrationState *s = migrate_get_current();

+if (ram_list.version != last_version) {
+reset_ram_globals();
+}
+
 bytes_transferred_last = bytes_transferred;
 bwidth = qemu_get_clock_ns(rt_clock);

diff --git a/cpu-all.h b/cpu-all.h
index cd61320..c69d602 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -497,6 +497,7 @@ typedef struct RAMList {
 uint8_t *phys_dirty;
 RAMBlock *mru_block;
 QTAILQ_HEAD(, RAMBlock) blocks;
+uint32_t version;
 } RAMList;
 extern RAMList ram_list;

diff --git a/exec.c b/exec.c
index 5f501d4..4474d60 100644
--- a/exec.c
+++ b/exec.c
@@ -1055,6 +1055,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 }
 ram_list.mru_block = NULL;

+ram_list.version++;
+
 ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
last_ram_offset()  TARGET_PAGE_BITS);
 memset(ram_list.phys_dirty + (new_block-offset  TARGET_PAGE_BITS),
@@ -1083,6 +1085,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr)
 if (addr == block-offset) {
 QTAILQ_REMOVE(ram_list.blocks, block, next);
 ram_list.mru_block = NULL;
+ram_list.version++;
 g_free(block);
 return;
 }
@@ -1097,6 +1100,7 @@ void qemu_ram_free(ram_addr_t addr)
 if (addr == block-offset) {
 QTAILQ_REMOVE(ram_list.blocks, block, next);
 ram_list.mru_block = NULL;
+ram_list.version++;
 if (block-flags  RAM_PREALLOC_MASK) {
 ;
 } else if (mem_path) {
-- 
1.7.11.7




[Qemu-devel] [PATCH 34/34] migration: merge QEMUFileBuffered into MigrationState

2012-12-19 Thread Juan Quintela
Avoid splitting the state of outgoing migration, more or less arbitrarily,
between two data structures.  QEMUFileBuffered anyway is used only during
migration.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c | 63 -
 migration.h |  8 
 2 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/migration.c b/migration.c
index ca39564..1d7ffb2 100644
--- a/migration.c
+++ b/migration.c
@@ -521,18 +521,8 @@ int64_t migrate_xbzrle_cache_size(void)

 /* migration thread support */

-typedef struct QEMUFileBuffered {
-MigrationState *migration_state;
-QEMUFile *file;
-size_t bytes_xfer;
-size_t xfer_limit;
-uint8_t *buffer;
-size_t buffer_size;
-size_t buffer_capacity;
-QemuThread thread;
-} QEMUFileBuffered;
-
-static ssize_t buffered_flush(QEMUFileBuffered *s)
+
+static ssize_t buffered_flush(MigrationState *s)
 {
 size_t offset = 0;
 ssize_t ret = 0;
@@ -541,8 +531,7 @@ static ssize_t buffered_flush(QEMUFileBuffered *s)

 while (s-bytes_xfer  s-xfer_limit  offset  s-buffer_size) {
 size_t to_send = MIN(s-buffer_size - offset, s-xfer_limit - 
s-bytes_xfer);
-ret = migrate_fd_put_buffer(s-migration_state, s-buffer + offset,
-to_send);
+ret = migrate_fd_put_buffer(s, s-buffer + offset, to_send);
 if (ret = 0) {
 DPRINTF(error flushing data, %zd\n, ret);
 break;
@@ -566,7 +555,7 @@ static ssize_t buffered_flush(QEMUFileBuffered *s)
 static int buffered_put_buffer(void *opaque, const uint8_t *buf,
int64_t pos, int size)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;
 ssize_t error;

 DPRINTF(putting %d bytes at % PRId64 \n, size, pos);
@@ -598,7 +587,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf,

 static int buffered_close(void *opaque)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;
 ssize_t ret = 0;
 int ret2;

@@ -612,20 +601,20 @@ static int buffered_close(void *opaque)
 }
 }

-ret2 = migrate_fd_close(s-migration_state);
+ret2 = migrate_fd_close(s);
 if (ret = 0) {
 ret = ret2;
 }
-ret = migrate_fd_close(s-migration_state);
-s-migration_state-complete = true;
+ret = migrate_fd_close(s);
+s-complete = true;
 return ret;
 }

 static int buffered_get_fd(void *opaque)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;

-return s-migration_state-fd;
+return s-fd;
 }

 /*
@@ -636,7 +625,7 @@ static int buffered_get_fd(void *opaque)
  */
 static int buffered_rate_limit(void *opaque)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;
 int ret;

 ret = qemu_file_get_error(s-file);
@@ -653,7 +642,7 @@ static int buffered_rate_limit(void *opaque)

 static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;
 if (qemu_file_get_error(s-file)) {
 goto out;
 }
@@ -669,7 +658,7 @@ out:

 static int64_t buffered_get_rate_limit(void *opaque)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;

 return s-xfer_limit;
 }
@@ -741,7 +730,7 @@ static bool migrate_fd_put_ready(MigrationState *s, 
uint64_t max_size)

 static void *buffered_file_thread(void *opaque)
 {
-QEMUFileBuffered *s = opaque;
+MigrationState *s = opaque;
 int64_t initial_time = qemu_get_clock_ms(rt_clock);
 int64_t max_size = 0;
 bool last_round = false;
@@ -749,7 +738,7 @@ static void *buffered_file_thread(void *opaque)
 while (true) {
 int64_t current_time = qemu_get_clock_ms(rt_clock);

-if (s-migration_state-complete) {
+if (s-complete) {
 break;
 }
 if (current_time = initial_time + BUFFER_DELAY) {
@@ -776,12 +765,11 @@ static void *buffered_file_thread(void *opaque)
 DPRINTF(file is ready\n);
 if (s-bytes_xfer  s-xfer_limit) {
 DPRINTF(notifying client\n);
-last_round = migrate_fd_put_ready(s-migration_state, max_size);
+last_round = migrate_fd_put_ready(s, max_size);
 }
 }

 g_free(s-buffer);
-g_free(s);
 return NULL;
 }

@@ -794,22 +782,21 @@ static const QEMUFileOps buffered_file_ops = {
 .set_rate_limit = buffered_set_rate_limit,
 };

-void migrate_fd_connect(MigrationState *migration_state)
+void migrate_fd_connect(MigrationState *s)
 {
-QEMUFileBuffered *s;
+s-state = MIG_STATE_ACTIVE;
+s-bytes_xfer = 0;
+s-buffer = NULL;
+s-buffer_size = 0;
+s-buffer_capacity = 0;

-migration_state-state = MIG_STATE_ACTIVE;
-migration_state-first_time = true;
-s = g_malloc0(sizeof(*s));
+s-first_time = true;

-s-migration_state = migration_state;
-

[Qemu-devel] [PATCH 18/20] cpu: Move kvm_state field into CPUState

2012-12-19 Thread Andreas Färber
Adapt some functions to take CPUState / {PowerPC,S390}CPU argument.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-defs.h |2 --
 include/qemu/cpu.h |3 +++
 kvm-all.c  |   28 ++--
 kvm.h  |4 ++--
 target-i386/cpu.c  |7 +--
 target-i386/kvm.c  |   22 +++---
 target-ppc/kvm.c   |   33 -
 target-s390x/kvm.c |5 ++---
 8 Dateien geändert, 57 Zeilen hinzugefügt(+), 47 Zeilen entfernt(-)

diff --git a/cpu-defs.h b/cpu-defs.h
index a382e35..9ed54cf 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -135,7 +135,6 @@ typedef struct icount_decr_u16 {
 #endif
 
 struct kvm_run;
-struct KVMState;
 struct qemu_work_item;
 
 typedef struct CPUBreakpoint {
@@ -205,7 +204,6 @@ typedef struct CPUWatchpoint {
 void *opaque;   \
 \
 const char *cpu_model_str;  \
-struct KVMState *kvm_state; \
 struct kvm_run *kvm_run;
 
 #endif
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index b8f8dd1..03962ef 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -52,6 +52,8 @@ typedef struct CPUClass {
 void (*reset)(CPUState *cpu);
 } CPUClass;
 
+struct KVMState;
+
 /**
  * CPUState:
  * @created: Indicates whether the CPU thread has been successfully created.
@@ -82,6 +84,7 @@ struct CPUState {
 int kvm_fd;
 bool kvm_vcpu_dirty;
 #endif
+struct KVMState *kvm_state;
 
 /* TODO Move common fields from CPUArchState here. */
 };
diff --git a/kvm-all.c b/kvm-all.c
index 5f1d1fe..ba139ab 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -230,7 +230,7 @@ int kvm_init_vcpu(CPUArchState *env)
 }
 
 cpu-kvm_fd = ret;
-env-kvm_state = s;
+cpu-kvm_state = s;
 cpu-kvm_vcpu_dirty = true;
 
 mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
@@ -1763,12 +1763,12 @@ void kvm_setup_guest_memory(void *start, size_t size)
 }
 
 #ifdef KVM_CAP_SET_GUEST_DEBUG
-struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUArchState *env,
+struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu,
  target_ulong pc)
 {
 struct kvm_sw_breakpoint *bp;
 
-QTAILQ_FOREACH(bp, env-kvm_state-kvm_sw_breakpoints, entry) {
+QTAILQ_FOREACH(bp, cpu-kvm_state-kvm_sw_breakpoints, entry) {
 if (bp-pc == pc) {
 return bp;
 }
@@ -1776,23 +1776,23 @@ struct kvm_sw_breakpoint 
*kvm_find_sw_breakpoint(CPUArchState *env,
 return NULL;
 }
 
-int kvm_sw_breakpoints_active(CPUArchState *env)
+int kvm_sw_breakpoints_active(CPUState *cpu)
 {
-return !QTAILQ_EMPTY(env-kvm_state-kvm_sw_breakpoints);
+return !QTAILQ_EMPTY(cpu-kvm_state-kvm_sw_breakpoints);
 }
 
 struct kvm_set_guest_debug_data {
 struct kvm_guest_debug dbg;
-CPUArchState *env;
+CPUState *cpu;
 int err;
 };
 
 static void kvm_invoke_set_guest_debug(void *data)
 {
 struct kvm_set_guest_debug_data *dbg_data = data;
-CPUState *cpu = ENV_GET_CPU(dbg_data-env);
 
-dbg_data-err = kvm_vcpu_ioctl(cpu, KVM_SET_GUEST_DEBUG, dbg_data-dbg);
+dbg_data-err = kvm_vcpu_ioctl(dbg_data-cpu, KVM_SET_GUEST_DEBUG,
+   dbg_data-dbg);
 }
 
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap)
@@ -1806,7 +1806,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
 }
 kvm_arch_update_guest_debug(cpu, data.dbg);
-data.env = env;
+data.cpu = cpu;
 
 run_on_cpu(cpu, kvm_invoke_set_guest_debug, data);
 return data.err;
@@ -1821,7 +1821,7 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_env, addr);
+bp = kvm_find_sw_breakpoint(current_cpu, addr);
 if (bp) {
 bp-use_count++;
 return 0;
@@ -1840,7 +1840,7 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return err;
 }
 
-QTAILQ_INSERT_HEAD(current_env-kvm_state-kvm_sw_breakpoints,
+QTAILQ_INSERT_HEAD(current_cpu-kvm_state-kvm_sw_breakpoints,
   bp, entry);
 } else {
 err = kvm_arch_insert_hw_breakpoint(addr, len, type);
@@ -1867,7 +1867,7 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_env, addr);
+bp = kvm_find_sw_breakpoint(current_cpu, addr);
 if (!bp) {
 return -ENOENT;
 }
@@ -1882,7 +1882,7 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 

[Qemu-devel] [PATCH 19/34] buffered_file: unfold buffered_append in buffered_put_buffer

2012-12-19 Thread Juan Quintela
It was the only user, and now buffered_put_buffer just do the append

Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
---
 buffered_file.c | 33 ++---
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 2c3820c..11efd8f 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -42,22 +42,6 @@ typedef struct QEMUFileBuffered
 do { } while (0)
 #endif

-static void buffered_append(QEMUFileBuffered *s,
-const uint8_t *buf, size_t size)
-{
-if (size  (s-buffer_capacity - s-buffer_size)) {
-DPRINTF(increasing buffer capacity from %zu by %zu\n,
-s-buffer_capacity, size + 1024);
-
-s-buffer_capacity += size + 1024;
-
-s-buffer = g_realloc(s-buffer, s-buffer_capacity);
-}
-
-memcpy(s-buffer + s-buffer_size, buf, size);
-s-buffer_size += size;
-}
-
 static ssize_t buffered_flush(QEMUFileBuffered *s)
 {
 size_t offset = 0;
@@ -102,11 +86,22 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in
 return error;
 }

-if (size  0) {
-DPRINTF(buffering %d bytes\n, size - offset);
-buffered_append(s, buf, size);
+if (size = 0) {
+return size;
 }

+if (size  (s-buffer_capacity - s-buffer_size)) {
+DPRINTF(increasing buffer capacity from %zu by %zu\n,
+s-buffer_capacity, size + 1024);
+
+s-buffer_capacity += size + 1024;
+
+s-buffer = g_realloc(s-buffer, s-buffer_capacity);
+}
+
+memcpy(s-buffer + s-buffer_size, buf, size);
+s-buffer_size += size;
+
 return size;
 }

-- 
1.7.11.7




[Qemu-devel] [PATCH 18/34] buffered_file: don't flush on put buffer

2012-12-19 Thread Juan Quintela
We call buffered_put_buffer with iothread held, and buffered_flush() does
synchronous writes.  We only want to do the synchronous writes outside.

Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
---
 buffered_file.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index f4f5110..2c3820c 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -107,12 +107,6 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in
 buffered_append(s, buf, size);
 }

-error = buffered_flush(s);
-if (error  0) {
-DPRINTF(buffered flush error. bailing: %s\n, strerror(-error));
-return error;
-}
-
 return size;
 }

-- 
1.7.11.7




[Qemu-devel] [PATCH 19/20] cpu: Move kvm_run into CPUState

2012-12-19 Thread Andreas Färber
Pass CPUState / {X86,S390}CPU to helper functions.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-defs.h |4 +--
 include/qemu/cpu.h |2 ++
 kvm-all.c  |8 +++---
 target-i386/kvm.c  |9 +++---
 target-s390x/kvm.c |   77 
 5 Dateien geändert, 53 Zeilen hinzugefügt(+), 47 Zeilen entfernt(-)

diff --git a/cpu-defs.h b/cpu-defs.h
index 9ed54cf..caea72b 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -134,7 +134,6 @@ typedef struct icount_decr_u16 {
 } icount_decr_u16;
 #endif
 
-struct kvm_run;
 struct qemu_work_item;
 
 typedef struct CPUBreakpoint {
@@ -203,7 +202,6 @@ typedef struct CPUWatchpoint {
 /* user data */ \
 void *opaque;   \
 \
-const char *cpu_model_str;  \
-struct kvm_run *kvm_run;
+const char *cpu_model_str;
 
 #endif
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 03962ef..fa3ffdb 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -53,6 +53,7 @@ typedef struct CPUClass {
 } CPUClass;
 
 struct KVMState;
+struct kvm_run;
 
 /**
  * CPUState:
@@ -85,6 +86,7 @@ struct CPUState {
 bool kvm_vcpu_dirty;
 #endif
 struct KVMState *kvm_state;
+struct kvm_run *kvm_run;
 
 /* TODO Move common fields from CPUArchState here. */
 };
diff --git a/kvm-all.c b/kvm-all.c
index ba139ab..f687229 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -240,9 +240,9 @@ int kvm_init_vcpu(CPUArchState *env)
 goto err;
 }
 
-env-kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
+cpu-kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
 cpu-kvm_fd, 0);
-if (env-kvm_run == MAP_FAILED) {
+if (cpu-kvm_run == MAP_FAILED) {
 ret = -errno;
 DPRINTF(mmap'ing vcpu state failed\n);
 goto err;
@@ -250,7 +250,7 @@ int kvm_init_vcpu(CPUArchState *env)
 
 if (s-coalesced_mmio  !s-coalesced_mmio_ring) {
 s-coalesced_mmio_ring =
-(void *)env-kvm_run + s-coalesced_mmio * PAGE_SIZE;
+(void *)cpu-kvm_run + s-coalesced_mmio * PAGE_SIZE;
 }
 
 ret = kvm_arch_init_vcpu(cpu);
@@ -1529,7 +1529,7 @@ void kvm_cpu_synchronize_post_init(CPUArchState *env)
 int kvm_cpu_exec(CPUArchState *env)
 {
 CPUState *cpu = ENV_GET_CPU(env);
-struct kvm_run *run = env-kvm_run;
+struct kvm_run *run = cpu-kvm_run;
 int ret, run_ret;
 
 DPRINTF(kvm_cpu_exec()\n);
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index ff5c9cd..53096c9 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1859,9 +1859,11 @@ static int kvm_handle_halt(X86CPU *cpu)
 return 0;
 }
 
-static int kvm_handle_tpr_access(CPUX86State *env)
+static int kvm_handle_tpr_access(X86CPU *cpu)
 {
-struct kvm_run *run = env-kvm_run;
+CPUX86State *env = cpu-env;
+CPUState *cs = CPU(cpu);
+struct kvm_run *run = cs-kvm_run;
 
 apic_handle_tpr_access_report(env-apic_state, run-tpr_access.rip,
   run-tpr_access.is_write ? TPR_ACCESS_WRITE
@@ -2067,7 +2069,6 @@ static bool host_supports_vmx(void)
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
 X86CPU *cpu = X86_CPU(cs);
-CPUX86State *env = cpu-env;
 uint64_t code;
 int ret;
 
@@ -2080,7 +2081,7 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run 
*run)
 ret = 0;
 break;
 case KVM_EXIT_TPR_ACCESS:
-ret = kvm_handle_tpr_access(env);
+ret = kvm_handle_tpr_access(cpu);
 break;
 case KVM_EXIT_FAIL_ENTRY:
 code = run-fail_entry.hardware_entry_failure_reason;
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 4e34304..0b64092 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -98,13 +98,13 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 int i;
 
 /* always save the PSW  and the GPRS*/
-env-kvm_run-psw_addr = env-psw.addr;
-env-kvm_run-psw_mask = env-psw.mask;
+cs-kvm_run-psw_addr = env-psw.addr;
+cs-kvm_run-psw_mask = env-psw.mask;
 
-if (cap_sync_regs  env-kvm_run-kvm_valid_regs  KVM_SYNC_GPRS) {
+if (cap_sync_regs  cs-kvm_run-kvm_valid_regs  KVM_SYNC_GPRS) {
 for (i = 0; i  16; i++) {
-env-kvm_run-s.regs.gprs[i] = env-regs[i];
-env-kvm_run-kvm_dirty_regs |= KVM_SYNC_GPRS;
+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++) {
@@ -122,14 +122,14 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 }
 
 if (cap_sync_regs 
-env-kvm_run-kvm_valid_regs  KVM_SYNC_ACRS 
-env-kvm_run-kvm_valid_regs  KVM_SYNC_CRS) {
+cs-kvm_run-kvm_valid_regs  KVM_SYNC_ACRS 
+

[Qemu-devel] [PATCH 04/20] target-alpha: Turn CPU definitions into subclasses

2012-12-19 Thread Andreas Färber
Make TYPE_ALPHA_CPU abstract and add types name-alpha-cpu.
Use type inheritence, and turn 2* models into aliases.

Move cpu_alpha_init() to cpu.c and split out CPU realization.
Default to creating type ev67-alpha-cpu as before.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Richard Henderson r...@twiddle.net
---
 target-alpha/cpu.c   |  178 +-
 target-alpha/cpu.h   |2 +
 target-alpha/translate.c |   58 +--
 3 Dateien geändert, 180 Zeilen hinzugefügt(+), 58 Zeilen entfernt(-)

diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
index 11a19eb..a5a98d0 100644
--- a/target-alpha/cpu.c
+++ b/target-alpha/cpu.c
@@ -21,8 +21,175 @@
 
 #include cpu.h
 #include qemu-common.h
+#include error.h
 
 
+static void alpha_cpu_realize(Object *obj, Error **errp)
+{
+#ifndef CONFIG_USER_ONLY
+AlphaCPU *cpu = ALPHA_CPU(obj);
+
+qemu_init_vcpu(cpu-env);
+#endif
+}
+
+/* Models */
+
+#define TYPE(model) model - TYPE_ALPHA_CPU
+
+typedef struct AlphaCPUAlias {
+const char *alias;
+const char *typename;
+} AlphaCPUAlias;
+
+static const AlphaCPUAlias alpha_cpu_aliases[] = {
+{ 21064,   TYPE(ev4) },
+{ 21164,   TYPE(ev5) },
+{ 21164a,  TYPE(ev56) },
+{ 21164pc, TYPE(pca56) },
+{ 21264,   TYPE(ev6) },
+{ 21264a,  TYPE(ev67) },
+};
+
+static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
+{
+ObjectClass *oc = NULL;
+char *typename;
+int i;
+
+if (cpu_model == NULL) {
+return NULL;
+}
+
+oc = object_class_by_name(cpu_model);
+if (oc != NULL) {
+return oc;
+}
+
+for (i = 0; i  ARRAY_SIZE(alpha_cpu_aliases); i++) {
+if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) {
+oc = object_class_by_name(alpha_cpu_aliases[i].typename);
+assert(oc != NULL);
+return oc;
+}
+}
+
+typename = g_strdup_printf(%s- TYPE_ALPHA_CPU, cpu_model);
+oc = object_class_by_name(typename);
+g_free(typename);
+return oc;
+}
+
+AlphaCPU *cpu_alpha_init(const char *cpu_model)
+{
+AlphaCPU *cpu;
+CPUAlphaState *env;
+ObjectClass *cpu_class;
+
+cpu_class = alpha_cpu_class_by_name(cpu_model);
+if (cpu_class == NULL) {
+/* Default to ev67; no reason not to emulate insns by default.  */
+cpu_class = object_class_by_name(TYPE(ev67));
+}
+cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
+env = cpu-env;
+
+env-cpu_model_str = cpu_model;
+
+alpha_cpu_realize(OBJECT(cpu), NULL);
+return cpu;
+}
+
+static void ev4_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-implver = IMPLVER_2106x;
+}
+
+static const TypeInfo ev4_cpu_type_info = {
+.name = TYPE(ev4),
+.parent = TYPE_ALPHA_CPU,
+.instance_init = ev4_cpu_initfn,
+};
+
+static void ev5_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-implver = IMPLVER_21164;
+}
+
+static const TypeInfo ev5_cpu_type_info = {
+.name = TYPE(ev5),
+.parent = TYPE_ALPHA_CPU,
+.instance_init = ev5_cpu_initfn,
+};
+
+static void ev56_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-amask |= AMASK_BWX;
+}
+
+static const TypeInfo ev56_cpu_type_info = {
+.name = TYPE(ev56),
+.parent = TYPE(ev5),
+.instance_init = ev56_cpu_initfn,
+};
+
+static void pca56_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-amask |= AMASK_MVI;
+}
+
+static const TypeInfo pca56_cpu_type_info = {
+.name = TYPE(pca56),
+.parent = TYPE(ev56),
+.instance_init = pca56_cpu_initfn,
+};
+
+static void ev6_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-implver = IMPLVER_21264;
+env-amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
+}
+
+static const TypeInfo ev6_cpu_type_info = {
+.name = TYPE(ev6),
+.parent = TYPE_ALPHA_CPU,
+.instance_init = ev6_cpu_initfn,
+};
+
+static void ev67_cpu_initfn(Object *obj)
+{
+AlphaCPU *cpu = ALPHA_CPU(obj);
+CPUAlphaState *env = cpu-env;
+
+env-amask |= AMASK_CIX | AMASK_PREFETCH;
+}
+
+static const TypeInfo ev67_cpu_type_info = {
+.name = TYPE(ev67),
+.parent = TYPE(ev6),
+.instance_init = ev67_cpu_initfn,
+};
+
+static const TypeInfo ev68_cpu_type_info = {
+.name = TYPE(ev68),
+.parent = TYPE(ev67),
+};
+
 static void alpha_cpu_initfn(Object *obj)
 {
 AlphaCPU *cpu = ALPHA_CPU(obj);
@@ -31,6 +198,8 @@ static void alpha_cpu_initfn(Object *obj)
 cpu_exec_init(env);
 tlb_flush(env, 1);
 
+alpha_translate_init();
+
 #if defined(CONFIG_USER_ONLY)
 env-ps = PS_USER_MODE;
 cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
@@ -46,13 +215,20 @@ static const TypeInfo alpha_cpu_type_info = 

[Qemu-devel] [PATCH 02/20] alpha: Pass AlphaCPU array to Typhoon

2012-12-19 Thread Andreas Färber
Also store it in TyphoonCchip.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Richard Henderson r...@twiddle.net
---
 hw/alpha_dp264.c   |   18 +-
 hw/alpha_sys.h |2 +-
 hw/alpha_typhoon.c |   29 -
 3 Dateien geändert, 26 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)

diff --git a/hw/alpha_dp264.c b/hw/alpha_dp264.c
index 76d8ae8..af24d1e 100644
--- a/hw/alpha_dp264.c
+++ b/hw/alpha_dp264.c
@@ -50,7 +50,7 @@ static void clipper_init(QEMUMachineInitArgs *args)
 const char *kernel_filename = args-kernel_filename;
 const char *kernel_cmdline = args-kernel_cmdline;
 const char *initrd_filename = args-initrd_filename;
-CPUAlphaState *cpus[4];
+AlphaCPU *cpus[4];
 PCIBus *pci_bus;
 ISABus *isa_bus;
 qemu_irq rtc_irq;
@@ -62,12 +62,12 @@ static void clipper_init(QEMUMachineInitArgs *args)
 /* Create up to 4 cpus.  */
 memset(cpus, 0, sizeof(cpus));
 for (i = 0; i  smp_cpus; ++i) {
-cpus[i] = cpu_init(cpu_model ? cpu_model : ev67);
+cpus[i] = cpu_alpha_init(cpu_model ? cpu_model : ev67);
 }
 
-cpus[0]-trap_arg0 = ram_size;
-cpus[0]-trap_arg1 = 0;
-cpus[0]-trap_arg2 = smp_cpus;
+cpus[0]-env.trap_arg0 = ram_size;
+cpus[0]-env.trap_arg1 = 0;
+cpus[0]-env.trap_arg2 = smp_cpus;
 
 /* Init the chipset.  */
 pci_bus = typhoon_init(ram_size, isa_bus, rtc_irq, cpus,
@@ -119,9 +119,9 @@ static void clipper_init(QEMUMachineInitArgs *args)
 
 /* Start all cpus at the PALcode RESET entry point.  */
 for (i = 0; i  smp_cpus; ++i) {
-cpus[i]-pal_mode = 1;
-cpus[i]-pc = palcode_entry;
-cpus[i]-palbr = palcode_entry;
+cpus[i]-env.pal_mode = 1;
+cpus[i]-env.pc = palcode_entry;
+cpus[i]-env.palbr = palcode_entry;
 }
 
 /* Load a kernel.  */
@@ -136,7 +136,7 @@ static void clipper_init(QEMUMachineInitArgs *args)
 exit(1);
 }
 
-cpus[0]-trap_arg1 = kernel_entry;
+cpus[0]-env.trap_arg1 = kernel_entry;
 
 param_offset = kernel_low - 0x6000;
 
diff --git a/hw/alpha_sys.h b/hw/alpha_sys.h
index 7604d09..69929ea 100644
--- a/hw/alpha_sys.h
+++ b/hw/alpha_sys.h
@@ -11,7 +11,7 @@
 #include irq.h
 
 
-PCIBus *typhoon_init(ram_addr_t, ISABus **, qemu_irq *, CPUAlphaState *[4],
+PCIBus *typhoon_init(ram_addr_t, ISABus **, qemu_irq *, AlphaCPU *[4],
  pci_map_irq_fn);
 
 /* alpha_pci.c.  */
diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index 9b16d96..4cc810f 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -23,7 +23,7 @@ typedef struct TyphoonCchip {
 uint64_t drir;
 uint64_t dim[4];
 uint32_t iic[4];
-CPUAlphaState *cpu[4];
+AlphaCPU *cpu[4];
 } TyphoonCchip;
 
 typedef struct TyphoonWindow {
@@ -58,10 +58,11 @@ typedef struct TyphoonState {
 } TyphoonState;
 
 /* Called when one of DRIR or DIM changes.  */
-static void cpu_irq_change(CPUAlphaState *env, uint64_t req)
+static void cpu_irq_change(AlphaCPU *cpu, uint64_t req)
 {
 /* If there are any non-masked interrupts, tell the cpu.  */
-if (env) {
+if (cpu != NULL) {
+CPUAlphaState *env = cpu-env;
 if (req) {
 cpu_interrupt(env, CPU_INTERRUPT_HARD);
 } else {
@@ -353,8 +354,9 @@ static void cchip_write(void *opaque, hwaddr addr,
 if ((newval ^ oldval)  0xff0) {
 int i;
 for (i = 0; i  4; ++i) {
-CPUAlphaState *env = s-cchip.cpu[i];
-if (env) {
+AlphaCPU *cpu = s-cchip.cpu[i];
+if (cpu != NULL) {
+CPUAlphaState *env = cpu-env;
 /* IPI can be either cleared or set by the write.  */
 if (newval  (1  (i + 8))) {
 cpu_interrupt(env, CPU_INTERRUPT_SMP);
@@ -661,8 +663,8 @@ static void typhoon_set_timer_irq(void *opaque, int irq, 
int level)
 
 /* Deliver the interrupt to each CPU, considering each CPU's IIC.  */
 for (i = 0; i  4; ++i) {
-CPUAlphaState *env = s-cchip.cpu[i];
-if (env) {
+AlphaCPU *cpu = s-cchip.cpu[i];
+if (cpu != NULL) {
 uint32_t iic = s-cchip.iic[i];
 
 /* ??? The verbage in Section 10.2.2.10 isn't 100% clear.
@@ -681,7 +683,7 @@ static void typhoon_set_timer_irq(void *opaque, int irq, 
int level)
 /* Set the ITI bit for this cpu.  */
 s-cchip.misc |= 1  (i + 4);
 /* And signal the interrupt.  */
-cpu_interrupt(env, CPU_INTERRUPT_TIMER);
+cpu_interrupt(cpu-env, CPU_INTERRUPT_TIMER);
 }
 }
 }
@@ -694,12 +696,12 @@ static void typhoon_alarm_timer(void *opaque)
 
 /* Set the ITI bit for this cpu.  */
 s-cchip.misc |= 1  (cpu + 4);
-cpu_interrupt(s-cchip.cpu[cpu], CPU_INTERRUPT_TIMER);
+cpu_interrupt(s-cchip.cpu[cpu]-env, CPU_INTERRUPT_TIMER);
 }
 
 PCIBus 

[Qemu-devel] [PATCH 04/34] migration: include qemu-file.h

2012-12-19 Thread Juan Quintela
They don't use/know anything about buffered-file.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-exec.c | 2 +-
 migration-fd.c   | 2 +-
 migration-tcp.c  | 2 +-
 migration-unix.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 2b6fcb4..f449a22 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -19,7 +19,7 @@
 #include qemu_socket.h
 #include migration.h
 #include qemu-char.h
-#include buffered_file.h
+#include qemu-file.h
 #include block.h
 #include sys/types.h
 #include sys/wait.h
diff --git a/migration-fd.c b/migration-fd.c
index 5fe28e0..c501c4b 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -18,7 +18,7 @@
 #include migration.h
 #include monitor.h
 #include qemu-char.h
-#include buffered_file.h
+#include qemu-file.h
 #include block.h
 #include qemu_socket.h

diff --git a/migration-tcp.c b/migration-tcp.c
index 5e855fe..1683158 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -17,7 +17,7 @@
 #include qemu_socket.h
 #include migration.h
 #include qemu-char.h
-#include buffered_file.h
+#include qemu-file.h
 #include block.h

 //#define DEBUG_MIGRATION_TCP
diff --git a/migration-unix.c b/migration-unix.c
index dba72b4..da00f2f 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -17,7 +17,7 @@
 #include qemu_socket.h
 #include migration.h
 #include qemu-char.h
-#include buffered_file.h
+#include qemu-file.h
 #include block.h

 //#define DEBUG_MIGRATION_UNIX
-- 
1.7.11.7




[Qemu-devel] [PATCH 16/20] ppc4xx_devs: Return PowerPCCPU from ppc4xx_init()

2012-12-19 Thread Andreas Färber
Prepares for passing PowerPCCPU to ppc_booke_timers_init().

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/ppc405_uc.c   |8 ++--
 hw/ppc4xx.h  |6 +++---
 hw/ppc4xx_devs.c |8 
 3 Dateien geändert, 13 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)

diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
index 0f458ef..373b8f3 100644
--- a/hw/ppc405_uc.c
+++ b/hw/ppc405_uc.c
@@ -2111,12 +2111,14 @@ CPUPPCState *ppc405cr_init(MemoryRegion 
*address_space_mem,
 {
 clk_setup_t clk_setup[PPC405CR_CLK_NB];
 qemu_irq dma_irqs[4];
+PowerPCCPU *cpu;
 CPUPPCState *env;
 qemu_irq *pic, *irqs;
 
 memset(clk_setup, 0, sizeof(clk_setup));
-env = ppc4xx_init(405cr, clk_setup[PPC405CR_CPU_CLK],
+cpu = ppc4xx_init(405cr, clk_setup[PPC405CR_CPU_CLK],
   clk_setup[PPC405CR_TMR_CLK], sysclk);
+env = cpu-env;
 /* Memory mapped devices registers */
 /* PLB arbitrer */
 ppc4xx_plb_init(env);
@@ -2460,13 +2462,15 @@ CPUPPCState *ppc405ep_init(MemoryRegion 
*address_space_mem,
 {
 clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup;
 qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4];
+PowerPCCPU *cpu;
 CPUPPCState *env;
 qemu_irq *pic, *irqs;
 
 memset(clk_setup, 0, sizeof(clk_setup));
 /* init CPUs */
-env = ppc4xx_init(405ep, clk_setup[PPC405EP_CPU_CLK],
+cpu = ppc4xx_init(405ep, clk_setup[PPC405EP_CPU_CLK],
   tlb_clk_setup, sysclk);
+env = cpu-env;
 clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb;
 clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque;
 /* Internal devices init */
diff --git a/hw/ppc4xx.h b/hw/ppc4xx.h
index d795ced..5d891ae 100644
--- a/hw/ppc4xx.h
+++ b/hw/ppc4xx.h
@@ -28,9 +28,9 @@
 #include pci.h
 
 /* PowerPC 4xx core initialization */
-CPUPPCState *ppc4xx_init (const char *cpu_model,
-   clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
-   uint32_t sysclk);
+PowerPCCPU *ppc4xx_init(const char *cpu_model,
+clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
+uint32_t sysclk);
 
 /* PowerPC 4xx universal interrupt controller */
 enum {
diff --git a/hw/ppc4xx_devs.c b/hw/ppc4xx_devs.c
index bac8d87..761cb59 100644
--- a/hw/ppc4xx_devs.c
+++ b/hw/ppc4xx_devs.c
@@ -47,9 +47,9 @@ static void ppc4xx_reset(void *opaque)
 
 /*/
 /* Generic PowerPC 4xx processor instantiation */
-CPUPPCState *ppc4xx_init (const char *cpu_model,
-   clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
-   uint32_t sysclk)
+PowerPCCPU *ppc4xx_init(const char *cpu_model,
+clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
+uint32_t sysclk)
 {
 PowerPCCPU *cpu;
 CPUPPCState *env;
@@ -72,7 +72,7 @@ CPUPPCState *ppc4xx_init (const char *cpu_model,
 /* Register qemu callbacks */
 qemu_register_reset(ppc4xx_reset, cpu);
 
-return env;
+return cpu;
 }
 
 /*/
-- 
1.7.10.4




[Qemu-devel] [PATCH 01/34] migration: fix migration_bitmap leak

2012-12-19 Thread Juan Quintela
From: Paolo Bonzini pbonz...@redhat.com

Cc: qemu-sta...@nongnu.org
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 83dcc53..0d7844c 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -535,9 +535,13 @@ static void sort_ram_list(void)

 static void migration_end(void)
 {
-memory_global_dirty_log_stop();
+if (migration_bitmap) {
+memory_global_dirty_log_stop();
+g_free(migration_bitmap);
+migration_bitmap = NULL;
+}

-if (migrate_use_xbzrle()) {
+if (XBZRLE.cache) {
 cache_fini(XBZRLE.cache);
 g_free(XBZRLE.cache);
 g_free(XBZRLE.encoded_buf);
@@ -689,13 +693,10 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 }
 bytes_transferred += bytes_sent;
 }
-memory_global_dirty_log_stop();
+migration_end();

 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);

-g_free(migration_bitmap);
-migration_bitmap = NULL;
-
 return 0;
 }

-- 
1.7.11.7




[Qemu-devel] [PATCH 01/20] target-alpha: Let cpu_alpha_init() return AlphaCPU

2012-12-19 Thread Andreas Färber
Replace cpu_init() macro with inline function for backwards
compatibility.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Richard Henderson r...@twiddle.net
---
 target-alpha/cpu.h   |   13 +++--
 target-alpha/translate.c |4 ++--
 2 Dateien geändert, 13 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 9939d61..32e3777 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -290,7 +290,6 @@ struct CPUAlphaState {
 int implver;
 };
 
-#define cpu_init cpu_alpha_init
 #define cpu_exec cpu_alpha_exec
 #define cpu_gen_code cpu_alpha_gen_code
 #define cpu_signal_handler cpu_alpha_signal_handler
@@ -427,7 +426,17 @@ enum {
 IR_ZERO = 31,
 };
 
-CPUAlphaState * cpu_alpha_init (const char *cpu_model);
+AlphaCPU *cpu_alpha_init(const char *cpu_model);
+
+static inline CPUAlphaState *cpu_init(const char *cpu_model)
+{
+AlphaCPU *cpu = cpu_alpha_init(cpu_model);
+if (cpu == NULL) {
+return NULL;
+}
+return cpu-env;
+}
+
 int cpu_alpha_exec(CPUAlphaState *s);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
signal handlers to inform the virtual CPU of exceptions. non zero
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index 71fe1a1..6f41ef7 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -3517,7 +3517,7 @@ static const struct cpu_def_t cpu_defs[] = {
| AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), }
 };
 
-CPUAlphaState * cpu_alpha_init (const char *cpu_model)
+AlphaCPU *cpu_alpha_init(const char *cpu_model)
 {
 AlphaCPU *cpu;
 CPUAlphaState *env;
@@ -3546,7 +3546,7 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
 env-cpu_model_str = cpu_model;
 
 qemu_init_vcpu(env);
-return env;
+return cpu;
 }
 
 void restore_state_to_opc(CPUAlphaState *env, TranslationBlock *tb, int pc_pos)
-- 
1.7.10.4




[Qemu-devel] [PATCH 10/34] protect the ramlist with a separate mutex

2012-12-19 Thread Juan Quintela
From: Umesh Deshpande udesh...@redhat.com

Add the new mutex that protects shared state between ram_save_live
and the iothread.  If the iothread mutex has to be taken together
with the ramlist mutex, the iothread shall always be _outside_.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Umesh Deshpande udesh...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com

Reviewed-by: Orit Wasserman owass...@redhat.com
---
 arch_init.c |  9 -
 cpu-all.h   |  9 +
 exec.c  | 29 +++--
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 136d0e8..9cee58a 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -528,7 +528,6 @@ static void ram_migration_cancel(void *opaque)
 migration_end();
 }

-
 static void reset_ram_globals(void)
 {
 last_block = NULL;
@@ -547,6 +546,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 bitmap_set(migration_bitmap, 0, ram_pages);
 migration_dirty_pages = ram_pages;

+qemu_mutex_lock_ramlist();
 bytes_transferred = 0;
 reset_ram_globals();

@@ -574,6 +574,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 qemu_put_be64(f, block-length);
 }

+qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);

 return 0;
@@ -588,6 +589,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 uint64_t expected_downtime;
 MigrationState *s = migrate_get_current();

+qemu_mutex_lock_ramlist();
+
 if (ram_list.version != last_version) {
 reset_ram_globals();
 }
@@ -636,6 +639,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 bwidth = 0.01;
 }

+qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);

 expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
@@ -656,6 +660,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 {
 migration_bitmap_sync();

+qemu_mutex_lock_ramlist();
+
 /* try transferring iterative blocks of memory */

 /* flush all remaining blocks regardless of rate limiting */
@@ -671,6 +677,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 }
 migration_end();

+qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);

 return 0;
diff --git a/cpu-all.h b/cpu-all.h
index c69d602..db79894 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -22,6 +22,7 @@
 #include qemu-common.h
 #include qemu-tls.h
 #include cpu-common.h
+#include qemu-thread.h

 /* some important defines:
  *
@@ -487,6 +488,9 @@ typedef struct RAMBlock {
 ram_addr_t length;
 uint32_t flags;
 char idstr[256];
+/* Reads can take either the iothread or the ramlist lock.
+ * Writes must take both locks.
+ */
 QTAILQ_ENTRY(RAMBlock) next;
 #if defined(__linux__)  !defined(TARGET_S390X)
 int fd;
@@ -494,8 +498,11 @@ typedef struct RAMBlock {
 } RAMBlock;

 typedef struct RAMList {
+QemuMutex mutex;
+/* Protected by the iothread lock.  */
 uint8_t *phys_dirty;
 RAMBlock *mru_block;
+/* Protected by the ramlist lock.  */
 QTAILQ_HEAD(, RAMBlock) blocks;
 uint32_t version;
 } RAMList;
@@ -516,6 +523,8 @@ extern int mem_prealloc;

 void dump_exec_info(FILE *f, fprintf_function cpu_fprintf);
 ram_addr_t last_ram_offset(void);
+void qemu_mutex_lock_ramlist(void);
+void qemu_mutex_unlock_ramlist(void);
 #endif /* !CONFIG_USER_ONLY */

 int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
diff --git a/exec.c b/exec.c
index 4474d60..a43659b 100644
--- a/exec.c
+++ b/exec.c
@@ -212,6 +212,7 @@ bool memory_region_is_unassigned(MemoryRegion *mr)
 void cpu_exec_init_all(void)
 {
 #if !defined(CONFIG_USER_ONLY)
+qemu_mutex_init(ram_list.mutex);
 memory_map_init();
 io_mem_init();
 #endif
@@ -800,6 +801,16 @@ void qemu_flush_coalesced_mmio_buffer(void)
 kvm_flush_coalesced_mmio_buffer();
 }

+void qemu_mutex_lock_ramlist(void)
+{
+qemu_mutex_lock(ram_list.mutex);
+}
+
+void qemu_mutex_unlock_ramlist(void)
+{
+qemu_mutex_unlock(ram_list.mutex);
+}
+
 #if defined(__linux__)  !defined(TARGET_S390X)

 #include sys/vfs.h
@@ -981,6 +992,8 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, 
DeviceState *dev)
 }
 pstrcat(new_block-idstr, sizeof(new_block-idstr), name);

+/* This assumes the iothread lock is taken here too.  */
+qemu_mutex_lock_ramlist();
 QTAILQ_FOREACH(block, ram_list.blocks, next) {
 if (block != new_block  !strcmp(block-idstr, new_block-idstr)) {
 fprintf(stderr, RAMBlock \%s\ already registered, abort!\n,
@@ -988,6 +1001,7 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, 
DeviceState *dev)
 abort();
 }
 }
+qemu_mutex_unlock_ramlist();
 }

 static int memory_try_enable_merging(void *addr, size_t len)
@@ -1011,6 +1025,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 size = 

[Qemu-devel] [PATCH 03/20] target-alpha: Avoid leaking the alarm timer over reset

2012-12-19 Thread Andreas Färber
Move the timer from CPUAlphaState to AlphaCPU to avoid the pointer being
zero'ed once we implement reset. Would cause a segfault in
sys_helper.c:helper_set_alarm().

This also simplifies timer initialization in Typhoon.

Signed-off-by: Andreas Färber afaer...@suse.de
Acked-by: Richard Henderson r...@twiddle.net
---
 hw/alpha_typhoon.c|3 +--
 target-alpha/cpu-qom.h|3 +++
 target-alpha/cpu.h|1 -
 target-alpha/sys_helper.c |6 --
 4 Dateien geändert, 8 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index 4cc810f..40b3a47 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -724,8 +724,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
 AlphaCPU *cpu = cpus[i];
 s-cchip.cpu[i] = cpu;
 if (cpu != NULL) {
-CPUAlphaState *env = cpu-env;
-env-alarm_timer = qemu_new_timer_ns(rtc_clock,
+cpu-alarm_timer = qemu_new_timer_ns(rtc_clock,
  typhoon_alarm_timer,
  (void *)((uintptr_t)s + i));
 }
diff --git a/target-alpha/cpu-qom.h b/target-alpha/cpu-qom.h
index 6b4ca6d..98585d5 100644
--- a/target-alpha/cpu-qom.h
+++ b/target-alpha/cpu-qom.h
@@ -58,6 +58,9 @@ typedef struct AlphaCPU {
 /* public */
 
 CPUAlphaState env;
+
+/* This alarm doesn't exist in real hardware; we wish it did.  */
+struct QEMUTimer *alarm_timer;
 } AlphaCPU;
 
 static inline AlphaCPU *alpha_env_get_cpu(CPUAlphaState *env)
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 32e3777..e1d7715 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -277,7 +277,6 @@ struct CPUAlphaState {
 #endif
 
 /* This alarm doesn't exist in real hardware; we wish it did.  */
-struct QEMUTimer *alarm_timer;
 uint64_t alarm_expire;
 
 /* Those resources are used only in QEMU core */
diff --git a/target-alpha/sys_helper.c b/target-alpha/sys_helper.c
index 40ca49c..d4f14ef 100644
--- a/target-alpha/sys_helper.c
+++ b/target-alpha/sys_helper.c
@@ -77,11 +77,13 @@ uint64_t helper_get_time(void)
 
 void helper_set_alarm(CPUAlphaState *env, uint64_t expire)
 {
+AlphaCPU *cpu = alpha_env_get_cpu(env);
+
 if (expire) {
 env-alarm_expire = expire;
-qemu_mod_timer(env-alarm_timer, expire);
+qemu_mod_timer(cpu-alarm_timer, expire);
 } else {
-qemu_del_timer(env-alarm_timer);
+qemu_del_timer(cpu-alarm_timer);
 }
 }
 #endif /* CONFIG_USER_ONLY */
-- 
1.7.10.4




[Qemu-devel] [PATCH 14/34] migration: make writes blocking

2012-12-19 Thread Juan Quintela
Move all the writes to the migration_thread, and make writings
blocking.  Notice that are still using the iothread for everything
that we do.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-exec.c |  1 -
 migration-fd.c   |  1 -
 migration-tcp.c  |  1 +
 migration-unix.c |  1 +
 migration.c  | 17 -
 qemu-file.h  |  5 -
 savevm.c |  5 -
 7 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index f449a22..0997a24 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -70,7 +70,6 @@ void exec_start_outgoing_migration(MigrationState *s, const 
char *command, Error

 s-fd = fileno(f);
 assert(s-fd != -1);
-socket_set_nonblock(s-fd);

 s-opaque = qemu_popen(f, w);

diff --git a/migration-fd.c b/migration-fd.c
index b8d16ad..77aef6d 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -76,7 +76,6 @@ void fd_start_outgoing_migration(MigrationState *s, const 
char *fdname, Error **
 return;
 }

-fcntl(s-fd, F_SETFL, O_NONBLOCK);
 s-get_error = fd_errno;
 s-write = fd_write;
 s-close = fd_close;
diff --git a/migration-tcp.c b/migration-tcp.c
index 1683158..5808857 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -61,6 +61,7 @@ static void tcp_wait_for_connect(int fd, void *opaque)
 } else {
 DPRINTF(migrate connect success\n);
 s-fd = fd;
+socket_set_block(s-fd);
 migrate_fd_connect(s);
 }
 }
diff --git a/migration-unix.c b/migration-unix.c
index da00f2f..81a8176 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -61,6 +61,7 @@ static void unix_wait_for_connect(int fd, void *opaque)
 } else {
 DPRINTF(migrate connect success\n);
 s-fd = fd;
+socket_set_block(s-fd);
 migrate_fd_connect(s);
 }
 }
diff --git a/migration.c b/migration.c
index 90dbe8e..5aa3bca 100644
--- a/migration.c
+++ b/migration.c
@@ -297,18 +297,6 @@ static void migrate_fd_completed(MigrationState *s)
 notifier_list_notify(migration_state_notifiers, s);
 }

-static void migrate_fd_put_notify(void *opaque)
-{
-MigrationState *s = opaque;
-int ret;
-
-qemu_set_fd_handler2(s-fd, NULL, NULL, NULL, NULL);
-ret = qemu_file_put_notify(s-file);
-if (ret) {
-migrate_fd_error(s);
-}
-}
-
 ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
   size_t size)
 {
@@ -325,10 +313,6 @@ ssize_t migrate_fd_put_buffer(MigrationState *s, const 
void *data,
 if (ret == -1)
 ret = -(s-get_error(s));

-if (ret == -EAGAIN) {
-qemu_set_fd_handler2(s-fd, NULL, NULL, migrate_fd_put_notify, s);
-}
-
 return ret;
 }

@@ -425,7 +409,6 @@ int migrate_fd_close(MigrationState *s)
 {
 int rc = 0;
 if (s-fd != -1) {
-qemu_set_fd_handler2(s-fd, NULL, NULL, NULL, NULL);
 rc = s-close(s);
 s-fd = -1;
 }
diff --git a/qemu-file.h b/qemu-file.h
index d64bdbb..68deefb 100644
--- a/qemu-file.h
+++ b/qemu-file.h
@@ -113,11 +113,6 @@ int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t 
new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_get_error(QEMUFile *f);

-/* Try to send any outstanding data.  This function is useful when output is
- * halted due to rate limiting or EAGAIN errors occur as it can be used to
- * resume output. */
-int qemu_file_put_notify(QEMUFile *f);
-
 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
 {
 qemu_put_be64(f, *pv);
diff --git a/savevm.c b/savevm.c
index 5d04d59..c4ee899 100644
--- a/savevm.c
+++ b/savevm.c
@@ -556,11 +556,6 @@ int qemu_fclose(QEMUFile *f)
 return ret;
 }

-int qemu_file_put_notify(QEMUFile *f)
-{
-return f-ops-put_buffer(f-opaque, NULL, 0, 0);
-}
-
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size)
 {
 int l;
-- 
1.7.11.7




[Qemu-devel] [PATCH 26/34] ram: rename last_block to last_seen_block

2012-12-19 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index f092ea2..34a2f4b 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -332,7 +332,10 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t 
*current_data,
 return bytes_sent;
 }

-static RAMBlock *last_block;
+
+/* This is the last block that we have visited serching for dirty pages
+ */
+static RAMBlock *last_seen_block;
 static ram_addr_t last_offset;
 static unsigned long *migration_bitmap;
 static uint64_t migration_dirty_pages;
@@ -417,7 +420,7 @@ static void migration_bitmap_sync(void)

 static int ram_save_block(QEMUFile *f, bool last_stage)
 {
-RAMBlock *block = last_block;
+RAMBlock *block = last_seen_block;
 ram_addr_t offset = last_offset;
 int bytes_sent = -1;
 MemoryRegion *mr;
@@ -430,7 +433,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 mr = block-mr;
 if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
 uint8_t *p;
-int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
+int cont = (block == last_seen_block) ?
+RAM_SAVE_FLAG_CONTINUE : 0;

 p = memory_region_get_ram_ptr(mr) + offset;

@@ -469,9 +473,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 if (!block)
 block = QTAILQ_FIRST(ram_list.blocks);
 }
-} while (block != last_block || offset != last_offset);
+} while (block != last_seen_block || offset != last_offset);

-last_block = block;
+last_seen_block = block;
 last_offset = offset;

 return bytes_sent;
@@ -530,7 +534,7 @@ static void ram_migration_cancel(void *opaque)

 static void reset_ram_globals(void)
 {
-last_block = NULL;
+last_seen_block = NULL;
 last_offset = 0;
 last_version = ram_list.version;
 }
-- 
1.7.11.7




  1   2   3   >