Re: [Qemu-devel] [PATCH v2] net/net: Change the default mac address of nic

2013-10-15 Thread Stefan Weil
Am 15.10.2013 07:57, schrieb mike:
 On 10/15/2013 01:07 PM, Stefan Weil wrote:
 Am 15.10.2013 06:17, schrieb Mike Qiu:
 Changelog to v1:
 Find remainder of macaddr-a[5] by modulo 256,
 otherwise it may be overflow by add index++.

 The default mac address is 52:54:00:12:34:56 + index, this will
 cause problem that when we boot up more than one guest with all
 mac addresses unset by default, assume that each guest has one
 nic. In this situation, all the guest's nic has the same mac address.

 This patch is to solve this bug.

 Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
 ---
   net/net.c | 9 ++---
   1 file changed, 6 insertions(+), 3 deletions(-)

 diff --git a/net/net.c b/net/net.c
 index c330c9a..9e72764 100644
 --- a/net/net.c
 +++ b/net/net.c
 @@ -21,6 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN
* THE SOFTWARE.
*/
 +#include time.h
 +
   #include config-host.h
 #include net/net.h
 @@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr
 *macaddr)
 if (memcmp(macaddr, zero, sizeof(zero)) != 0)
   return;
 +srand((unsigned)time(NULL));
   macaddr-a[0] = 0x52;
   macaddr-a[1] = 0x54;
   macaddr-a[2] = 0x00;
 -macaddr-a[3] = 0x12;
 -macaddr-a[4] = 0x34;
 -macaddr-a[5] = 0x56 + index++;
 +macaddr-a[3] = rand() % 256;
 +macaddr-a[4] = rand() % 256;
 +macaddr-a[5] = (rand() % 256 + index++) % 256;
   }
 /**
 There is no overflow which must be handled because a[5] is an uint8_t
 value, so the assignment automatically limits the range to 0...255.
 OK, you are right, but I think we'd better to ensure this,
 even though a[5] is an uint8_t.
 Is it reasonable to get a random mac address in your guest? I don't
 think so. It would no longer be possible to connect to a guest using
 ssh, restart that guest and connect again with ssh.
 Why not? I have do the experiment, after reboot, the mac is not changed.
 and the ip address always the same.

 And can be login to the guest after reboot.

restart means terminate QEMU and start it again.




Re: [Qemu-devel] [PATCH 2/2] virtio: refresh registers at reset time

2013-10-15 Thread Rusty Russell
Greg Kurz gk...@linux.vnet.ibm.com writes:
 We need to support the guest endianness as soon as a virtio device shows
 up. Alex suggested this can achieved by calling cpu_synchronize_state().

 To have it working on PowerPC, we need to add LPCR in the sync register
 functions.

 Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com

Excellent!  Alex, if you take this, I'll be happy to rebase and re-test
the virtio endianness patches on top.

Cheers,
Rusty.



[Qemu-devel] [PULL v2 00/39] pci, pc, acpi fixes, enhancements

2013-10-15 Thread Michael S. Tsirkin
This is resend of pull request from oct 14.
Changes from v1:
- removed reviewed-by tags from compiled file changes.
  only tested-by makes sense
- dropped pci bridge hotplug support for now
  Anthony feels it needs more review.

In absense of bridge hotplug the main point of the series is to pass
correct ACPI tables to alternative firmwares, in particular coreboot.
coreboot support was already written and tested by Gerd.

The following changes since commit e26d3e734650640fabd7d95ace4f3a6f88725e0b:

  smbios: Factor out smbios_maybe_add_str() (2013-09-28 23:49:39 +0300)

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_anthony

for you to fetch changes up to 742f5d2ed578bb53b2130b6da2c66de9929f4821:

  ssdt-proc: update generated file (2013-10-14 17:48:57 +0300)


pci, pc, acpi fixes, enhancements

This includes some pretty big changes:
- pci master abort support by Marcel
- pci IRQ API rework by Marcel
- acpi generation support by myself

Everything has gone through several revisions, latest versions have been on
list for a while without any more comments, tested by several
people.

Please pull for 1.7.

Signed-off-by: Michael S. Tsirkin m...@redhat.com


Igor Mammedov (1):
  cleanup object.h: include error.h directly

Marcel Apfelbaum (11):
  memory: Change MemoryRegion priorities from unsigned to signed
  docs/memory: Explictly state that MemoryRegion priority is signed
  hw/pci: partially handle pci master abort
  hw/core: Add interface to allocate and free a single IRQ
  hw/pci: add pci wrappers for allocating and asserting irqs
  hw/pci-bridge: set PCI_INTERRUPT_PIN register before shpc init
  hw/vmxnet3: set interrupts using pci irq wrappers
  hw/vfio: set interrupts using pci irq wrappers
  hw: set interrupts using pci irq wrappers
  hw/pcie: AER and hot-plug events must use device's interrupt
  hw/pci: removed irq field from PCIDevice

Michael S. Tsirkin (27):
  qom: cleanup struct Error references
  qom: add pointer to int property helpers
  pci: fix up w64 size calculation helper
  fw_cfg: interface to trigger callback on read
  loader: support for unmapped ROM blobs
  pcie_host: expose UNMAPPED macro
  pcie_host: expose address format
  q35: use macro for MCFG property name
  q35: expose mmcfg size as a property
  i386: add ACPI table files from seabios
  acpi: add rules to compile ASL source
  acpi: pre-compiled ASL files
  acpi: ssdt pcihp: updat generated file
  loader: use file path size from fw_cfg.h
  i386: add bios linker/loader
  loader: allow adding ROMs in done callbacks
  i386: define pc guest info
  acpi/piix: add macros for acpi property names
  piix: APIs for pc guest info
  ich9: APIs for pc guest info
  pvpanic: add API to access io port
  hpet: add API to find it
  acpi: add interface to access user-installed tables
  pc: use new api to add builtin tables
  i386: ACPI table generation code from seabios
  ssdt: fix PBLK length
  ssdt-proc: update generated file

 configure   |9 +-
 hw/i386/acpi-build.h|9 +
 hw/i386/acpi-defs.h |  331 ++
 hw/i386/bios-linker-loader.h|   27 +
 hw/lm32/lm32_hwsetup.h  |2 +-
 include/exec/memory.h   |4 +-
 include/hw/acpi/acpi.h  |4 +
 include/hw/acpi/ich9.h  |2 +
 include/hw/acpi/piix4.h |8 +
 include/hw/i386/ich9.h  |2 +
 include/hw/i386/pc.h|   22 +
 include/hw/irq.h|7 +
 include/hw/loader.h |8 +-
 include/hw/nvram/fw_cfg.h   |8 +-
 include/hw/pci-host/q35.h   |2 +
 include/hw/pci/pci.h|   26 +-
 include/hw/pci/pci_bus.h|1 +
 include/hw/pci/pcie.h   |   18 -
 include/hw/pci/pcie_host.h  |   27 +
 include/hw/sysbus.h |2 +-
 include/hw/timer/hpet.h |2 +
 include/qom/object.h|   73 +-
 hw/acpi/core.c  |   40 +
 hw/acpi/ich9.c  |   24 +
 hw/acpi/piix4.c |   50 +-
 hw/audio/ac97.c |4 +-
 hw/audio/es1370.c   |4 +-
 hw/audio/intel-hda.c|2 +-
 hw/block/nvme.c |2 +-
 hw/char/serial-pci.c|5 +-
 hw/char/tpci200.c   |8 +-
 hw/core/irq.c   |   16 +
 hw/core/loader.c|   31 +-
 hw/core/sysbus.c|4 +-
 hw/display/qxl.c|2 +-
 hw/i386/acpi-build.c| 1214 ++
 

[Qemu-devel] [PULL v2 03/39] hw/pci: partially handle pci master abort

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

A MemoryRegion with negative priority was created and
it spans over all the pci address space.
It intercepts the accesses to unassigned pci
address space and will follow the pci spec:
 1. returns -1 on read
 2. does nothing on write

Note: setting the RECEIVED MASTER ABORT bit in the STATUS register
  of the device that initiated the transaction will be
  implemented in another series

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Acked-by: Michael S. Tsirkin m...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pci_bus.h |  1 +
 hw/pci/pci.c | 26 ++
 2 files changed, 27 insertions(+)

diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
index 9df1788..2ad5edb 100644
--- a/include/hw/pci/pci_bus.h
+++ b/include/hw/pci/pci_bus.h
@@ -23,6 +23,7 @@ struct PCIBus {
 PCIDevice *parent_dev;
 MemoryRegion *address_space_mem;
 MemoryRegion *address_space_io;
+MemoryRegion master_abort_mem;
 
 QLIST_HEAD(, PCIBus) child; /* this will be replaced by qdev later */
 QLIST_ENTRY(PCIBus) sibling;/* this will be replaced by qdev later */
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 00554a0..25626b8 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -283,6 +283,24 @@ const char *pci_root_bus_path(PCIDevice *dev)
 return rootbus-qbus.name;
 }
 
+static uint64_t master_abort_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+   return -1ULL;
+}
+
+static void master_abort_mem_write(void *opaque, hwaddr addr, uint64_t val,
+   unsigned size)
+{
+}
+
+static const MemoryRegionOps master_abort_mem_ops = {
+.read = master_abort_mem_read,
+.write = master_abort_mem_write,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+#define MASTER_ABORT_MEM_PRIORITY INT_MIN
+
 static void pci_bus_init(PCIBus *bus, DeviceState *parent,
  const char *name,
  MemoryRegion *address_space_mem,
@@ -294,6 +312,14 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 bus-address_space_mem = address_space_mem;
 bus-address_space_io = address_space_io;
 
+
+memory_region_init_io(bus-master_abort_mem, OBJECT(bus),
+  master_abort_mem_ops, bus, pci-master-abort,
+  memory_region_size(bus-address_space_mem));
+memory_region_add_subregion_overlap(bus-address_space_mem,
+0, bus-master_abort_mem,
+MASTER_ABORT_MEM_PRIORITY);
+
 /* host bridge */
 QLIST_INIT(bus-child);
 
-- 
MST




[Qemu-devel] [PULL v2 01/39] memory: Change MemoryRegion priorities from unsigned to signed

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

When memory regions overlap, priority can be used to specify
which of them takes priority. By making the priority values signed
rather than unsigned, we make it more convenient to implement
a situation where one background region should appear only
where no other region exists: rather than having to explicitly
specify a high priority for all the other regions, we can let them take
the default (zero) priority and specify a negative priority for the
background region.

Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Acked-by: Michael S. Tsirkin m...@redhat.com
Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/exec/memory.h | 4 ++--
 include/hw/sysbus.h   | 2 +-
 hw/core/sysbus.c  | 4 ++--
 memory.c  | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index ebe0d24..480dfbf 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -153,7 +153,7 @@ struct MemoryRegion {
 bool flush_coalesced_mmio;
 MemoryRegion *alias;
 hwaddr alias_offset;
-unsigned priority;
+int priority;
 bool may_overlap;
 QTAILQ_HEAD(subregions, MemoryRegion) subregions;
 QTAILQ_ENTRY(MemoryRegion) subregions_link;
@@ -779,7 +779,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
  hwaddr offset,
  MemoryRegion *subregion,
- unsigned priority);
+ int priority);
 
 /**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index bb50a87..f5aaa05 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -68,7 +68,7 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t 
ioport, pio_addr_t size);
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
- unsigned priority);
+ int priority);
 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
MemoryRegion *mem);
 void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index b84cd4a..146f50a 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -49,7 +49,7 @@ void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq 
irq)
 }
 
 static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
-   bool may_overlap, unsigned priority)
+   bool may_overlap, int priority)
 {
 assert(n = 0  n  dev-num_mmio);
 
@@ -81,7 +81,7 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
 }
 
 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
- unsigned priority)
+ int priority)
 {
 sysbus_mmio_map_common(dev, n, addr, true, priority);
 }
diff --git a/memory.c b/memory.c
index 5a10fd0..f49d31a 100644
--- a/memory.c
+++ b/memory.c
@@ -1473,7 +1473,7 @@ void memory_region_add_subregion(MemoryRegion *mr,
 void memory_region_add_subregion_overlap(MemoryRegion *mr,
  hwaddr offset,
  MemoryRegion *subregion,
- unsigned priority)
+ int priority)
 {
 subregion-may_overlap = true;
 subregion-priority = priority;
@@ -1506,7 +1506,7 @@ void memory_region_set_enabled(MemoryRegion *mr, bool 
enabled)
 void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
 {
 MemoryRegion *parent = mr-parent;
-unsigned priority = mr-priority;
+int priority = mr-priority;
 bool may_overlap = mr-may_overlap;
 
 if (addr == mr-addr || !parent) {
-- 
MST




[Qemu-devel] [PULL v2 02/39] docs/memory: Explictly state that MemoryRegion priority is signed

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

When memory regions overlap, priority can be used to specify
which of them takes priority. By making the priority values signed
rather than unsigned, we make it more convenient to implement
a situation where one background region should appear only
where no other region exists: rather than having to explicitly
specify a high priority for all the other regions, we can let them take
the default (zero) priority and specify a negative priority for the
background region.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Acked-by: Michael S. Tsirkin m...@redhat.com
Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 docs/memory.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/docs/memory.txt b/docs/memory.txt
index feb9fe9..174c0d7 100644
--- a/docs/memory.txt
+++ b/docs/memory.txt
@@ -80,6 +80,10 @@ guest.  This is done with 
memory_region_add_subregion_overlap(), which
 allows the region to overlap any other region in the same container, and
 specifies a priority that allows the core to decide which of two regions at
 the same address are visible (highest wins).
+Priority values are signed, and the default value is zero. This means that
+you can use memory_region_add_subregion_overlap() both to specify a region
+that must sit 'above' any others (with a positive priority) and also a
+background region that sits 'below' others (with a negative priority).
 
 Visibility
 --
-- 
MST




[Qemu-devel] [PULL v2 05/39] hw/pci: add pci wrappers for allocating and asserting irqs

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

Interrupt pin is selected and saved into PCI_INTERRUPT_PIN
register during device initialization. Devices should not call
directly qemu_set_irq and specify the INTx pin on each call.

Added pci_* wrappers to replace qemu_set_irq, qemu_irq_raise,
qemu_irq_lower and qemu_irq_pulse, setting the irq
based on PCI_INTERRUPT_PIN.

Added pci_allocate_irq wrapper to be used by devices that
still need PCIDevice infrastructure to assert irqs.

Renamed a static method which was named already pci_set_irq.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pci.h | 23 +++
 hw/pci/pci.c | 26 ++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 4b90e5d..990342c 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -632,6 +632,29 @@ PCIDevice *pci_create_simple_multifunction(PCIBus *bus, 
int devfn,
 PCIDevice *pci_create(PCIBus *bus, int devfn, const char *name);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
+qemu_irq pci_allocate_irq(PCIDevice *pci_dev);
+void pci_set_irq(PCIDevice *pci_dev, int level);
+
+static inline void pci_irq_assert(PCIDevice *pci_dev)
+{
+pci_set_irq(pci_dev, 1);
+}
+
+static inline void pci_irq_deassert(PCIDevice *pci_dev)
+{
+pci_set_irq(pci_dev, 0);
+}
+
+/*
+ * FIXME: PCI does not work this way.
+ * All the callers to this method should be fixed.
+ */
+static inline void pci_irq_pulse(PCIDevice *pci_dev)
+{
+pci_irq_assert(pci_dev);
+pci_irq_deassert(pci_dev);
+}
+
 static inline int pci_is_express(const PCIDevice *d)
 {
 return d-cap_present  QEMU_PCI_CAP_EXPRESS;
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 25626b8..ff4b697 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -83,7 +83,7 @@ static const TypeInfo pcie_bus_info = {
 
 static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
 static void pci_update_mappings(PCIDevice *d);
-static void pci_set_irq(void *opaque, int irq_num, int level);
+static void pci_irq_handler(void *opaque, int irq_num, int level);
 static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom);
 static void pci_del_option_rom(PCIDevice *pdev);
 
@@ -161,7 +161,7 @@ void pci_device_deassert_intx(PCIDevice *dev)
 {
 int i;
 for (i = 0; i  PCI_NUM_PINS; ++i) {
-qemu_set_irq(dev-irq[i], 0);
+pci_irq_handler(dev, i, 0);
 }
 }
 
@@ -889,7 +889,7 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 pci_dev-config_read = config_read;
 pci_dev-config_write = config_write;
 bus-devices[devfn] = pci_dev;
-pci_dev-irq = qemu_allocate_irqs(pci_set_irq, pci_dev, PCI_NUM_PINS);
+pci_dev-irq = qemu_allocate_irqs(pci_irq_handler, pci_dev, PCI_NUM_PINS);
 pci_dev-version_id = 2; /* Current pci device vmstate version */
 return pci_dev;
 }
@@ -1201,7 +1201,7 @@ void pci_default_write_config(PCIDevice *d, uint32_t 
addr, uint32_t val, int l)
 /* generic PCI irq support */
 
 /* 0 = irq_num = 3. level must be 0 or 1 */
-static void pci_set_irq(void *opaque, int irq_num, int level)
+static void pci_irq_handler(void *opaque, int irq_num, int level)
 {
 PCIDevice *pci_dev = opaque;
 int change;
@@ -1217,6 +1217,24 @@ static void pci_set_irq(void *opaque, int irq_num, int 
level)
 pci_change_irq_level(pci_dev, irq_num, change);
 }
 
+static inline int pci_intx(PCIDevice *pci_dev)
+{
+return pci_get_byte(pci_dev-config + PCI_INTERRUPT_PIN) - 1;
+}
+
+qemu_irq pci_allocate_irq(PCIDevice *pci_dev)
+{
+int intx = pci_intx(pci_dev);
+
+return qemu_allocate_irq(pci_irq_handler, pci_dev, intx);
+}
+
+void pci_set_irq(PCIDevice *pci_dev, int level)
+{
+int intx = pci_intx(pci_dev);
+pci_irq_handler(pci_dev, intx, level);
+}
+
 /* Special hooks used by device assignment */
 void pci_bus_set_route_irq_fn(PCIBus *bus, pci_route_irq_fn route_intx_to_irq)
 {
-- 
MST




[Qemu-devel] [PULL v2 04/39] hw/core: Add interface to allocate and free a single IRQ

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

qemu_allocate_irq returns a single qemu_irq.
The interface allows to specify an interrupt number.

qemu_free_irq frees it.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/irq.h |  7 +++
 hw/core/irq.c| 16 
 2 files changed, 23 insertions(+)

diff --git a/include/hw/irq.h b/include/hw/irq.h
index 610e6b7..d08bc02 100644
--- a/include/hw/irq.h
+++ b/include/hw/irq.h
@@ -30,6 +30,12 @@ static inline void qemu_irq_pulse(qemu_irq irq)
  */
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
 
+/*
+ * Allocates a single IRQ. The irq is assigned with a handler, an opaque
+ * data and the interrupt number.
+ */
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n);
+
 /* Extends an Array of IRQs. Old IRQs have their handlers and opaque data
  * preserved. New IRQs are assigned the argument handler and opaque data.
  */
@@ -37,6 +43,7 @@ qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, 
qemu_irq_handler handler,
 void *opaque, int n);
 
 void qemu_free_irqs(qemu_irq *s);
+void qemu_free_irq(qemu_irq irq);
 
 /* Returns a new IRQ with opposite polarity.  */
 qemu_irq qemu_irq_invert(qemu_irq irq);
diff --git a/hw/core/irq.c b/hw/core/irq.c
index 2078542..03c8cb3 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -68,6 +68,17 @@ qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void 
*opaque, int n)
 return qemu_extend_irqs(NULL, 0, handler, opaque, n);
 }
 
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)
+{
+struct IRQState *irq;
+
+irq = g_new(struct IRQState, 1);
+irq-handler = handler;
+irq-opaque = opaque;
+irq-n = n;
+
+return irq;
+}
 
 void qemu_free_irqs(qemu_irq *s)
 {
@@ -75,6 +86,11 @@ void qemu_free_irqs(qemu_irq *s)
 g_free(s);
 }
 
+void qemu_free_irq(qemu_irq irq)
+{
+g_free(irq);
+}
+
 static void qemu_notirq(void *opaque, int line, int level)
 {
 struct IRQState *irq = opaque;
-- 
MST




[Qemu-devel] [PULL v2 06/39] hw/pci-bridge: set PCI_INTERRUPT_PIN register before shpc init

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

The PCI_INTERRUPT_PIN will be used by shpc init, so
was moved before the call to shpc_init.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/pci-bridge/pci_bridge_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index a9392c7..440e187 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -53,6 +53,7 @@ static int pci_bridge_dev_initfn(PCIDevice *dev)
 if (err) {
 goto bridge_error;
 }
+dev-config[PCI_INTERRUPT_PIN] = 0x1;
 memory_region_init(bridge_dev-bar, OBJECT(dev), shpc-bar, 
shpc_bar_size(dev));
 err = shpc_init(dev, br-sec_bus, bridge_dev-bar, 0);
 if (err) {
@@ -73,7 +74,6 @@ static int pci_bridge_dev_initfn(PCIDevice *dev)
  * Check whether that works well. */
 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY |
 PCI_BASE_ADDRESS_MEM_TYPE_64, bridge_dev-bar);
-dev-config[PCI_INTERRUPT_PIN] = 0x1;
 return 0;
 msi_error:
 slotid_cap_cleanup(dev);
-- 
MST




[Qemu-devel] [PULL v2 11/39] hw/pci: removed irq field from PCIDevice

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

Instead of exposing the the irq field,
pci wrappers to qemu_set_irq or qemu_irq_*
can be used.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pci.h | 3 ---
 hw/pci/pci.c | 2 --
 2 files changed, 5 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 990342c..37ffa53 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -247,9 +247,6 @@ struct PCIDevice {
 PCIConfigReadFunc *config_read;
 PCIConfigWriteFunc *config_write;
 
-/* IRQ objects for the INTA-INTD pins.  */
-qemu_irq *irq;
-
 /* Legacy PCI VGA regions */
 MemoryRegion *vga_regions[QEMU_PCI_VGA_NUM_REGIONS];
 bool has_vga;
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index ff4b697..ae23c58 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -889,14 +889,12 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 pci_dev-config_read = config_read;
 pci_dev-config_write = config_write;
 bus-devices[devfn] = pci_dev;
-pci_dev-irq = qemu_allocate_irqs(pci_irq_handler, pci_dev, PCI_NUM_PINS);
 pci_dev-version_id = 2; /* Current pci device vmstate version */
 return pci_dev;
 }
 
 static void do_pci_unregister_device(PCIDevice *pci_dev)
 {
-qemu_free_irqs(pci_dev-irq);
 pci_dev-bus-devices[pci_dev-devfn] = NULL;
 pci_config_free(pci_dev);
 
-- 
MST




[Qemu-devel] [PULL v2 07/39] hw/vmxnet3: set interrupts using pci irq wrappers

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

pci_set_irq uses PCI_INTERRUPT_PIN config register
to compute device INTx pin to assert/deassert.

An assert is used to ensure that intx received
from the quest OS corresponds to PCI_INTERRUPT_PIN.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/net/vmxnet3.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 49c2466..19687aa 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -336,7 +336,7 @@ static bool _vmxnet3_assert_interrupt_line(VMXNET3State *s, 
uint32_t int_idx)
 }
 
 VMW_IRPRN(Asserting line for interrupt %u, int_idx);
-qemu_set_irq(d-irq[int_idx], 1);
+pci_irq_assert(d);
 return true;
 }
 
@@ -356,7 +356,7 @@ static void _vmxnet3_deassert_interrupt_line(VMXNET3State 
*s, int lidx)
 assert(!s-msi_used || !msi_enabled(d));
 
 VMW_IRPRN(Deasserting line for interrupt %u, lidx);
-qemu_set_irq(d-irq[lidx], 0);
+pci_irq_deassert(d);
 }
 
 static void vmxnet3_update_interrupt_line_state(VMXNET3State *s, int lidx)
@@ -1299,6 +1299,12 @@ static void vmxnet3_update_features(VMXNET3State *s)
 }
 }
 
+static bool vmxnet3_verify_intx(VMXNET3State *s, int intx)
+{
+return s-msix_used || s-msi_used || (intx ==
+   (pci_get_byte(s-parent_obj.config + PCI_INTERRUPT_PIN) - 1));
+}
+
 static void vmxnet3_activate_device(VMXNET3State *s)
 {
 int i;
@@ -1332,6 +1338,7 @@ static void vmxnet3_activate_device(VMXNET3State *s)
 
 s-event_int_idx =
 VMXNET3_READ_DRV_SHARED8(s-drv_shmem, devRead.intrConf.eventIntrIdx);
+assert(vmxnet3_verify_intx(s, s-event_int_idx));
 VMW_CFPRN(Events interrupt line is %u, s-event_int_idx);
 
 s-auto_int_masking =
@@ -1364,6 +1371,7 @@ static void vmxnet3_activate_device(VMXNET3State *s)
 /* Read interrupt number for this TX queue */
 s-txq_descr[i].intr_idx =
 VMXNET3_READ_TX_QUEUE_DESCR8(qdescr_pa, conf.intrIdx);
+assert(vmxnet3_verify_intx(s, s-txq_descr[i].intr_idx));
 
 VMW_CFPRN(TX Queue %d interrupt: %d, i, s-txq_descr[i].intr_idx);
 
@@ -1411,6 +1419,7 @@ static void vmxnet3_activate_device(VMXNET3State *s)
 /* Read interrupt number for this RX queue */
 s-rxq_descr[i].intr_idx =
 VMXNET3_READ_TX_QUEUE_DESCR8(qd_pa, conf.intrIdx);
+assert(vmxnet3_verify_intx(s, s-rxq_descr[i].intr_idx));
 
 VMW_CFPRN(RX Queue %d interrupt: %d, i, s-rxq_descr[i].intr_idx);
 
-- 
MST




[Qemu-devel] [PULL v2 21/39] q35: expose mmcfg size as a property

2013-10-15 Thread Michael S. Tsirkin
Address is already exposed, expose size for symmetry.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pcie_host.h |  1 +
 hw/pci-host/q35.c  | 14 ++
 2 files changed, 15 insertions(+)

diff --git a/include/hw/pci/pcie_host.h b/include/hw/pci/pcie_host.h
index 33d75bd..acca45e 100644
--- a/include/hw/pci/pcie_host.h
+++ b/include/hw/pci/pcie_host.h
@@ -29,6 +29,7 @@
 OBJECT_CHECK(PCIExpressHost, (obj), TYPE_PCIE_HOST_BRIDGE)
 
 #define PCIE_HOST_MCFG_BASE MCFG
+#define PCIE_HOST_MCFG_SIZE mcfg_size
 
 /* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */
 #define PCIE_BASE_ADDR_UNMAPPED  ((hwaddr)-1ULL)
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index e46f286..a051b58 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -109,6 +109,16 @@ static void q35_host_get_pci_hole64_end(Object *obj, 
Visitor *v,
 visit_type_uint64(v, w64.end, name, errp);
 }
 
+static void q35_host_get_mmcfg_size(Object *obj, Visitor *v,
+void *opaque, const char *name,
+Error **errp)
+{
+PCIExpressHost *e = PCIE_HOST_BRIDGE(obj);
+uint32_t value = e-size;
+
+visit_type_uint32(v, value, name, errp);
+}
+
 static Property mch_props[] = {
 DEFINE_PROP_UINT64(PCIE_HOST_MCFG_BASE, Q35PCIHost, parent_obj.base_addr,
 MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
@@ -160,6 +170,10 @@ static void q35_host_initfn(Object *obj)
 q35_host_get_pci_hole64_end,
 NULL, NULL, NULL, NULL);
 
+object_property_add(obj, PCIE_HOST_MCFG_SIZE, int,
+q35_host_get_mmcfg_size,
+NULL, NULL, NULL, NULL);
+
 /* Leave enough space for the biggest MCFG BAR */
 /* TODO: this matches current bios behaviour, but
  * it's not a power of two, which means an MTRR
-- 
MST




[Qemu-devel] [PULL v2 09/39] hw: set interrupts using pci irq wrappers

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

pci_set_irq and the other pci irq wrappers use
PCI_INTERRUPT_PIN config register to compute device
INTx pin to assert/deassert.

An irq is allocated using pci_allocate_irq wrapper
only if is needed by non pci devices.

Removed irq related fields from state if not used anymore.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/audio/ac97.c| 4 ++--
 hw/audio/es1370.c  | 4 ++--
 hw/audio/intel-hda.c   | 2 +-
 hw/block/nvme.c| 2 +-
 hw/char/serial-pci.c   | 5 +++--
 hw/char/tpci200.c  | 8 
 hw/display/qxl.c   | 2 +-
 hw/ide/cmd646.c| 2 +-
 hw/ide/ich.c   | 3 ++-
 hw/isa/vt82c686.c  | 2 +-
 hw/misc/ivshmem.c  | 2 +-
 hw/net/e1000.c | 2 +-
 hw/net/eepro100.c  | 4 ++--
 hw/net/ne2000.c| 3 ++-
 hw/net/pcnet-pci.c | 3 ++-
 hw/net/rtl8139.c   | 2 +-
 hw/pci/shpc.c  | 2 +-
 hw/scsi/esp-pci.c  | 3 ++-
 hw/scsi/lsi53c895a.c   | 2 +-
 hw/scsi/megasas.c  | 6 +++---
 hw/scsi/vmw_pvscsi.c   | 2 +-
 hw/usb/hcd-ehci-pci.c  | 2 +-
 hw/usb/hcd-ohci.c  | 2 +-
 hw/usb/hcd-uhci.c  | 6 ++
 hw/usb/hcd-xhci.c  | 7 ++-
 hw/virtio/virtio-pci.c | 4 ++--
 26 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 01b4dfb..03f4846 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -280,12 +280,12 @@ static void update_sr (AC97LinkState *s, 
AC97BusMasterRegs *r, uint32_t new_sr)
 if (level) {
 s-glob_sta |= masks[r - s-bm_regs];
 dolog (set irq level=1\n);
-qemu_set_irq (s-dev.irq[0], 1);
+pci_irq_assert(s-dev);
 }
 else {
 s-glob_sta = ~masks[r - s-bm_regs];
 dolog (set irq level=0\n);
-qemu_set_irq (s-dev.irq[0], 0);
+pci_irq_deassert(s-dev);
 }
 }
 
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index adb66ce..1ec7ace 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -323,7 +323,7 @@ static void es1370_update_status (ES1370State *s, uint32_t 
new_status)
 else {
 s-status = new_status  ~STAT_INTR;
 }
-qemu_set_irq (s-dev.irq[0], !!level);
+pci_set_irq(s-dev, !!level);
 }
 
 static void es1370_reset (ES1370State *s)
@@ -349,7 +349,7 @@ static void es1370_reset (ES1370State *s)
 s-dac_voice[i] = NULL;
 }
 }
-qemu_irq_lower (s-dev.irq[0]);
+pci_irq_deassert(s-dev);
 }
 
 static void es1370_maybe_lower_irq (ES1370State *s, uint32_t sctl)
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index ac6..4327264 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -269,7 +269,7 @@ static void intel_hda_update_irq(IntelHDAState *d)
 msi_notify(d-pci, 0);
 }
 } else {
-qemu_set_irq(d-pci.irq[0], level);
+pci_set_irq(d-pci, level);
 }
 }
 
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 5dee229..2882ffe 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -69,7 +69,7 @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq)
 if (msix_enabled((n-parent_obj))) {
 msix_notify((n-parent_obj), cq-vector);
 } else {
-qemu_irq_pulse(n-parent_obj.irq[0]);
+pci_irq_pulse(n-parent_obj);
 }
 }
 }
diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c
index aec6705..991c99f 100644
--- a/hw/char/serial-pci.c
+++ b/hw/char/serial-pci.c
@@ -61,7 +61,7 @@ static int serial_pci_init(PCIDevice *dev)
 }
 
 pci-dev.config[PCI_INTERRUPT_PIN] = 0x01;
-s-irq = pci-dev.irq[0];
+s-irq = pci_allocate_irq(pci-dev);
 
 memory_region_init_io(s-io, OBJECT(pci), serial_io_ops, s, serial, 8);
 pci_register_bar(pci-dev, 0, PCI_BASE_ADDRESS_SPACE_IO, s-io);
@@ -79,7 +79,7 @@ static void multi_serial_irq_mux(void *opaque, int n, int 
level)
 pending = 1;
 }
 }
-qemu_set_irq(pci-dev.irq[0], pending);
+pci_set_irq(pci-dev, pending);
 }
 
 static int multi_serial_pci_init(PCIDevice *dev)
@@ -132,6 +132,7 @@ static void serial_pci_exit(PCIDevice *dev)
 
 serial_exit_core(s);
 memory_region_destroy(s-io);
+qemu_free_irq(s-irq);
 }
 
 static void multi_serial_pci_exit(PCIDevice *dev)
diff --git a/hw/char/tpci200.c b/hw/char/tpci200.c
index e04ff26..a49d2ed 100644
--- a/hw/char/tpci200.c
+++ b/hw/char/tpci200.c
@@ -134,8 +134,8 @@ static void tpci200_set_irq(void *opaque, int intno, int 
level)
 /* Check if the interrupt is edge sensitive */
 if (dev-ctrl[ip_n]  CTRL_INT_EDGE(intno)) {
 if (level) {
-qemu_set_irq(dev-dev.irq[0], !dev-int_set);
-qemu_set_irq(dev-dev.irq[0],  dev-int_set);
+pci_set_irq(dev-dev, !dev-int_set);
+pci_set_irq(dev-dev,  dev-int_set);
 }
 } else {
 unsigned i, j;
@@ -153,10 +153,10 @@ static void tpci200_set_irq(void *opaque, int intno, int 
level)
 

[Qemu-devel] [PULL v2 10/39] hw/pcie: AER and hot-plug events must use device's interrupt

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

The fields hpev_intx and aer_intx were removed because
both AER and hot-plug events must use device's interrupt.
Assert/deassert interrupts using pci irq wrappers instead.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pcie.h | 18 --
 hw/pci/pcie.c |  4 ++--
 hw/pci/pcie_aer.c |  4 ++--
 3 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index c010007..1966169 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -64,15 +64,6 @@ struct PCIExpressDevice {
 uint8_t exp_cap;
 
 /* SLOT */
-unsigned int hpev_intx; /* INTx for hot plug event (0-3:INT[A-D]#)
- * default is 0 = INTA#
- * If the chip wants to use other interrupt
- * line, initialize this member with the
- * desired number.
- * If the chip dynamically changes this member,
- * also initialize it when loaded as
- * appropreately.
- */
 bool hpev_notified; /* Logical AND of conditions for hot plug event.
  Following 6.7.3.4:
  Software Notification of Hot-Plug Events, an interrupt
@@ -82,15 +73,6 @@ struct PCIExpressDevice {
 /* AER */
 uint16_t aer_cap;
 PCIEAERLog aer_log;
-unsigned int aer_intx;  /* INTx for error reporting
- * default is 0 = INTA#
- * If the chip wants to use other interrupt
- * line, initialize this member with the
- * desired number.
- * If the chip dynamically changes this member,
- * also initialize it when loaded as
- * appropreately.
- */
 };
 
 /* PCI express capability helper functions */
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 50af3c1..268a696 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -187,7 +187,7 @@ static void hotplug_event_notify(PCIDevice *dev)
 } else if (msi_enabled(dev)) {
 msi_notify(dev, pcie_cap_flags_get_vector(dev));
 } else {
-qemu_set_irq(dev-irq[dev-exp.hpev_intx], dev-exp.hpev_notified);
+pci_set_irq(dev, dev-exp.hpev_notified);
 }
 }
 
@@ -195,7 +195,7 @@ static void hotplug_event_clear(PCIDevice *dev)
 {
 hotplug_event_update_event_status(dev);
 if (!msix_enabled(dev)  !msi_enabled(dev)  !dev-exp.hpev_notified) {
-qemu_set_irq(dev-irq[dev-exp.hpev_intx], 0);
+pci_irq_deassert(dev);
 }
 }
 
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index ca762ab..32aa0c6 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -285,7 +285,7 @@ static void pcie_aer_root_notify(PCIDevice *dev)
 } else if (msi_enabled(dev)) {
 msi_notify(dev, pcie_aer_root_get_vector(dev));
 } else {
-qemu_set_irq(dev-irq[dev-exp.aer_intx], 1);
+pci_irq_assert(dev);
 }
 }
 
@@ -768,7 +768,7 @@ void pcie_aer_root_write_config(PCIDevice *dev,
 uint32_t root_cmd = pci_get_long(aer_cap + PCI_ERR_ROOT_COMMAND);
 /* 6.2.4.1.2 Interrupt Generation */
 if (!msix_enabled(dev)  !msi_enabled(dev)) {
-qemu_set_irq(dev-irq[dev-exp.aer_intx], !!(root_cmd  enabled_cmd));
+pci_set_irq(dev, !!(root_cmd  enabled_cmd));
 return;
 }
 
-- 
MST




[Qemu-devel] [PULL v2 25/39] acpi: ssdt pcihp: updat generated file

2013-10-15 Thread Michael S. Tsirkin
update generated file, not sure what changed

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/i386/ssdt-pcihp.hex.generated | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
index 0d32a27..b3c2cd5 100644
--- a/hw/i386/ssdt-pcihp.hex.generated
+++ b/hw/i386/ssdt-pcihp.hex.generated
@@ -17,7 +17,7 @@ static unsigned char ssdp_pcihp_aml[] = {
 0x0,
 0x0,
 0x1,
-0x77,
+0x76,
 0x42,
 0x58,
 0x50,
@@ -40,9 +40,9 @@ static unsigned char ssdp_pcihp_aml[] = {
 0x4e,
 0x54,
 0x4c,
-0x28,
-0x5,
-0x10,
+0x23,
+0x8,
+0x13,
 0x20,
 0x10,
 0x33,
-- 
MST




[Qemu-devel] [PULL v2 12/39] cleanup object.h: include error.h directly

2013-10-15 Thread Michael S. Tsirkin
From: Igor Mammedov imamm...@redhat.com

qapi/error.h is simple enough to be included in qom/object.h
direcly and prepares qom/object.h to use Error typedef.

Signed-off-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/qom/object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 1a7b71a..d9a0063 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -18,9 +18,9 @@
 #include stdint.h
 #include stdbool.h
 #include qemu/queue.h
+#include qapi/error.h
 
 struct Visitor;
-struct Error;
 
 struct TypeImpl;
 typedef struct TypeImpl *Type;
-- 
MST




[Qemu-devel] [PULL v2 08/39] hw/vfio: set interrupts using pci irq wrappers

2013-10-15 Thread Michael S. Tsirkin
From: Marcel Apfelbaum marce...@redhat.com

pci_set_irq and the other pci irq wrappers use
PCI_INTERRUPT_PIN config register to compute device
INTx pin to assert/deassert.

save INTX pin into the config register before calling
pci_set_irq

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/misc/vfio.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index a1c08fb..9d02e49 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -297,7 +297,7 @@ static void vfio_intx_interrupt(void *opaque)
 'A' + vdev-intx.pin);
 
 vdev-intx.pending = true;
-qemu_set_irq(vdev-pdev.irq[vdev-intx.pin], 1);
+pci_irq_assert(vdev-pdev);
 vfio_mmap_set_enabled(vdev, false);
 if (vdev-intx.mmap_timeout) {
 timer_mod(vdev-intx.mmap_timer,
@@ -315,7 +315,7 @@ static void vfio_eoi(VFIODevice *vdev)
 vdev-host.bus, vdev-host.slot, vdev-host.function);
 
 vdev-intx.pending = false;
-qemu_set_irq(vdev-pdev.irq[vdev-intx.pin], 0);
+pci_irq_deassert(vdev-pdev);
 vfio_unmask_intx(vdev);
 }
 
@@ -341,7 +341,7 @@ static void vfio_enable_intx_kvm(VFIODevice *vdev)
 qemu_set_fd_handler(irqfd.fd, NULL, NULL, vdev);
 vfio_mask_intx(vdev);
 vdev-intx.pending = false;
-qemu_set_irq(vdev-pdev.irq[vdev-intx.pin], 0);
+pci_irq_deassert(vdev-pdev);
 
 /* Get an eventfd for resample/unmask */
 if (event_notifier_init(vdev-intx.unmask, 0)) {
@@ -417,7 +417,7 @@ static void vfio_disable_intx_kvm(VFIODevice *vdev)
  */
 vfio_mask_intx(vdev);
 vdev-intx.pending = false;
-qemu_set_irq(vdev-pdev.irq[vdev-intx.pin], 0);
+pci_irq_deassert(vdev-pdev);
 
 /* Tell KVM to stop listening for an INTx irqfd */
 if (kvm_vm_ioctl(kvm_state, KVM_IRQFD, irqfd)) {
@@ -488,6 +488,7 @@ static int vfio_enable_intx(VFIODevice *vdev)
 vfio_disable_interrupts(vdev);
 
 vdev-intx.pin = pin - 1; /* Pin A (1) - irq[0] */
+pci_config_set_interrupt_pin(vdev-pdev.config, pin);
 
 #ifdef CONFIG_KVM
 /*
@@ -547,7 +548,7 @@ static void vfio_disable_intx(VFIODevice *vdev)
 vfio_disable_intx_kvm(vdev);
 vfio_disable_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
 vdev-intx.pending = false;
-qemu_set_irq(vdev-pdev.irq[vdev-intx.pin], 0);
+pci_irq_deassert(vdev-pdev);
 vfio_mmap_set_enabled(vdev, true);
 
 fd = event_notifier_get_fd(vdev-intx.interrupt);
-- 
MST




[Qemu-devel] [PULL v2 15/39] pci: fix up w64 size calculation helper

2013-10-15 Thread Michael S. Tsirkin
BAR base was calculated incorrectly.
Use existing pci_bar_address to get it right.

Tested-by: Igor Mammedov imamm...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/pci/pci.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index ae23c58..a98c8a0 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2306,7 +2306,7 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, 
void *opaque)
 Range *range = opaque;
 PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
 uint16_t cmd = pci_get_word(dev-config + PCI_COMMAND);
-int r;
+int i;
 
 if (!(cmd  PCI_COMMAND_MEMORY)) {
 return;
@@ -2325,17 +2325,21 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, 
void *opaque)
 range_extend(range, pref_range);
 }
 }
-for (r = 0; r  PCI_NUM_REGIONS; ++r) {
-PCIIORegion *region = dev-io_regions[r];
+for (i = 0; i  PCI_NUM_REGIONS; ++i) {
+PCIIORegion *r = dev-io_regions[i];
 Range region_range;
 
-if (!region-size ||
-(region-type  PCI_BASE_ADDRESS_SPACE_IO) ||
-!(region-type  PCI_BASE_ADDRESS_MEM_TYPE_64)) {
+if (!r-size ||
+(r-type  PCI_BASE_ADDRESS_SPACE_IO) ||
+!(r-type  PCI_BASE_ADDRESS_MEM_TYPE_64)) {
+continue;
+}
+region_range.begin = pci_bar_address(dev, i, r-type, r-size);
+region_range.end = region_range.begin + r-size;
+
+if (region_range.begin == PCI_BAR_UNMAPPED) {
 continue;
 }
-region_range.begin = pci_get_quad(dev-config + pci_bar(dev, r));
-region_range.end = region_range.begin + region-size;
 
 region_range.begin = MAX(region_range.begin, 0x1ULL  32);
 
-- 
MST




[Qemu-devel] [PULL v2 13/39] qom: cleanup struct Error references

2013-10-15 Thread Michael S. Tsirkin
now that a typedef for struct Error is available,
use it in qom/object.h to match coding style rules.

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/qom/object.h | 50 +-
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index d9a0063..6c1e7d3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -301,7 +301,7 @@ typedef void (ObjectPropertyAccessor)(Object *obj,
   struct Visitor *v,
   void *opaque,
   const char *name,
-  struct Error **errp);
+  Error **errp);
 
 /**
  * ObjectPropertyRelease:
@@ -790,9 +790,9 @@ void object_property_add(Object *obj, const char *name, 
const char *type,
  ObjectPropertyAccessor *get,
  ObjectPropertyAccessor *set,
  ObjectPropertyRelease *release,
- void *opaque, struct Error **errp);
+ void *opaque, Error **errp);
 
-void object_property_del(Object *obj, const char *name, struct Error **errp);
+void object_property_del(Object *obj, const char *name, Error **errp);
 
 /**
  * object_property_find:
@@ -803,7 +803,7 @@ void object_property_del(Object *obj, const char *name, 
struct Error **errp);
  * Look up a property for an object and return its #ObjectProperty if found.
  */
 ObjectProperty *object_property_find(Object *obj, const char *name,
- struct Error **errp);
+ Error **errp);
 
 void object_unparent(Object *obj);
 
@@ -818,7 +818,7 @@ void object_unparent(Object *obj);
  * Reads a property from a object.
  */
 void object_property_get(Object *obj, struct Visitor *v, const char *name,
- struct Error **errp);
+ Error **errp);
 
 /**
  * object_property_set_str:
@@ -829,7 +829,7 @@ void object_property_get(Object *obj, struct Visitor *v, 
const char *name,
  * Writes a string value to a property.
  */
 void object_property_set_str(Object *obj, const char *value,
- const char *name, struct Error **errp);
+ const char *name, Error **errp);
 
 /**
  * object_property_get_str:
@@ -842,7 +842,7 @@ void object_property_set_str(Object *obj, const char *value,
  * The caller should free the string.
  */
 char *object_property_get_str(Object *obj, const char *name,
-  struct Error **errp);
+  Error **errp);
 
 /**
  * object_property_set_link:
@@ -853,7 +853,7 @@ char *object_property_get_str(Object *obj, const char *name,
  * Writes an object's canonical path to a property.
  */
 void object_property_set_link(Object *obj, Object *value,
-  const char *name, struct Error **errp);
+  const char *name, Error **errp);
 
 /**
  * object_property_get_link:
@@ -866,7 +866,7 @@ void object_property_set_link(Object *obj, Object *value,
  * string or not a valid object path).
  */
 Object *object_property_get_link(Object *obj, const char *name,
- struct Error **errp);
+ Error **errp);
 
 /**
  * object_property_set_bool:
@@ -877,7 +877,7 @@ Object *object_property_get_link(Object *obj, const char 
*name,
  * Writes a bool value to a property.
  */
 void object_property_set_bool(Object *obj, bool value,
-  const char *name, struct Error **errp);
+  const char *name, Error **errp);
 
 /**
  * object_property_get_bool:
@@ -889,7 +889,7 @@ void object_property_set_bool(Object *obj, bool value,
  * an error occurs (including when the property value is not a bool).
  */
 bool object_property_get_bool(Object *obj, const char *name,
-  struct Error **errp);
+  Error **errp);
 
 /**
  * object_property_set_int:
@@ -900,7 +900,7 @@ bool object_property_get_bool(Object *obj, const char *name,
  * Writes an integer value to a property.
  */
 void object_property_set_int(Object *obj, int64_t value,
- const char *name, struct Error **errp);
+ const char *name, Error **errp);
 
 /**
  * object_property_get_int:
@@ -912,7 +912,7 @@ void object_property_set_int(Object *obj, int64_t value,
  * an error occurs (including when the property value is not an integer).
  */
 int64_t object_property_get_int(Object *obj, const char *name,
-  

[Qemu-devel] [PULL v2 26/39] loader: use file path size from fw_cfg.h

2013-10-15 Thread Michael S. Tsirkin
Avoid a bit of code duplication, make
max file path constant reusable.

Suggested-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/nvram/fw_cfg.h | 4 +++-
 hw/core/loader.c  | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 2ab0fc2..72b1549 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -46,12 +46,14 @@
 
 #define FW_CFG_INVALID  0x
 
+#define FW_CFG_MAX_FILE_PATH56
+
 #ifndef NO_QEMU_PROTOS
 typedef struct FWCfgFile {
 uint32_t  size;/* file size */
 uint16_t  select;  /* write this to 0x510 to read it */
 uint16_t  reserved;
-char  name[56];
+char  name[FW_CFG_MAX_FILE_PATH];
 } FWCfgFile;
 
 typedef struct FWCfgFiles {
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 449bd4c..060729f 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -663,7 +663,7 @@ int rom_add_file(const char *file, const char *fw_dir,
 rom_insert(rom);
 if (rom-fw_file  fw_cfg) {
 const char *basename;
-char fw_file_name[56];
+char fw_file_name[FW_CFG_MAX_FILE_PATH];
 void *data;
 
 basename = strrchr(rom-fw_file, '/');
-- 
MST




[Qemu-devel] [PULL v2 14/39] qom: add pointer to int property helpers

2013-10-15 Thread Michael S. Tsirkin
Make it easy to add read-only helpers for simple
integer properties in memory.

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/qom/object.h | 21 ++
 qom/object.c | 60 
 2 files changed, 81 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 6c1e7d3..d02172a 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -795,6 +795,27 @@ void object_property_add(Object *obj, const char *name, 
const char *type,
 void object_property_del(Object *obj, const char *name, Error **errp);
 
 /**
+ * object_property_add_uint8_ptr:
+ * object_property_add_uint16_ptr:
+ * object_property_add_uint32_ptr:
+ * object_property_add_uint64_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ *
+ * Add an integer property in memory.  This function will add a
+ * property of the appropriate type.
+ */
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+   const uint8_t *v, Error **errp);
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+const uint16_t *v, Error **errp);
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+const uint32_t *v, Error **errp);
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+const uint64_t *v, Error **Errp);
+
+/**
  * object_property_find:
  * @obj: the object
  * @name: the name of the property
diff --git a/qom/object.c b/qom/object.c
index e90e382..b617f26 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1344,6 +1344,66 @@ static char *qdev_get_type(Object *obj, Error **errp)
 return g_strdup(object_get_typename(obj));
 }
 
+static void property_get_uint8_ptr(Object *obj, Visitor *v,
+   void *opaque, const char *name,
+   Error **errp)
+{
+uint8_t value = *(uint8_t *)opaque;
+visit_type_uint8(v, value, name, errp);
+}
+
+static void property_get_uint16_ptr(Object *obj, Visitor *v,
+   void *opaque, const char *name,
+   Error **errp)
+{
+uint16_t value = *(uint16_t *)opaque;
+visit_type_uint16(v, value, name, errp);
+}
+
+static void property_get_uint32_ptr(Object *obj, Visitor *v,
+   void *opaque, const char *name,
+   Error **errp)
+{
+uint32_t value = *(uint32_t *)opaque;
+visit_type_uint32(v, value, name, errp);
+}
+
+static void property_get_uint64_ptr(Object *obj, Visitor *v,
+   void *opaque, const char *name,
+   Error **errp)
+{
+uint64_t value = *(uint64_t *)opaque;
+visit_type_uint64(v, value, name, errp);
+}
+
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+   const uint8_t *v, Error **errp)
+{
+object_property_add(obj, name, uint8, property_get_uint8_ptr,
+NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+const uint16_t *v, Error **errp)
+{
+object_property_add(obj, name, uint16, property_get_uint16_ptr,
+NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+const uint32_t *v, Error **errp)
+{
+object_property_add(obj, name, uint32, property_get_uint32_ptr,
+NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+const uint64_t *v, Error **errp)
+{
+object_property_add(obj, name, uint64, property_get_uint64_ptr,
+NULL, NULL, (void *)v, errp);
+}
+
 static void object_instance_init(Object *obj)
 {
 object_property_add_str(obj, type, qdev_get_type, NULL, NULL);
-- 
MST




[Qemu-devel] [PULL v2 28/39] loader: allow adding ROMs in done callbacks

2013-10-15 Thread Michael S. Tsirkin
Don't abort if machine done callbacks add ROMs.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/loader.h | 1 +
 hw/core/loader.c| 6 +-
 vl.c| 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/hw/loader.h b/include/hw/loader.h
index e0c576b..58eca98 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -46,6 +46,7 @@ void *rom_add_blob(const char *name, const void *blob, size_t 
len,
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
 size_t romsize, hwaddr addr);
 int rom_load_all(void);
+void rom_load_done(void);
 void rom_set_fw(FWCfgState *f);
 int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
 void *rom_ptr(hwaddr addr);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 060729f..60d2ebd 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -812,10 +812,14 @@ int rom_load_all(void)
 memory_region_unref(section.mr);
 }
 qemu_register_reset(rom_reset, NULL);
-roms_loaded = 1;
 return 0;
 }
 
+void rom_load_done(void)
+{
+roms_loaded = 1;
+}
+
 void rom_set_fw(FWCfgState *f)
 {
 fw_cfg = f;
diff --git a/vl.c b/vl.c
index fb8006e..46c29c4 100644
--- a/vl.c
+++ b/vl.c
@@ -4339,6 +4339,9 @@ int main(int argc, char **argv, char **envp)
 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
 qemu_run_machine_init_done_notifiers();
 
+/* Done notifiers can load ROMs */
+rom_load_done();
+
 qemu_system_reset(VMRESET_SILENT);
 if (loadvm) {
 if (load_vmstate(loadvm)  0) {
-- 
MST




[Qemu-devel] [PULL v2 17/39] loader: support for unmapped ROM blobs

2013-10-15 Thread Michael S. Tsirkin
Support ROM blobs not mapped into guest memory:
same as ROM files really but use caller's buffer.

Support invoking callback on access and
return memory pointer making it easier
for caller to update memory if necessary.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/lm32/lm32_hwsetup.h |  2 +-
 include/hw/loader.h|  7 ---
 hw/core/loader.c   | 23 ---
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
index 3449bd8..9fd5e69 100644
--- a/hw/lm32/lm32_hwsetup.h
+++ b/hw/lm32/lm32_hwsetup.h
@@ -73,7 +73,7 @@ static inline void hwsetup_free(HWSetup *hw)
 static inline void hwsetup_create_rom(HWSetup *hw,
 hwaddr base)
 {
-rom_add_blob(hwsetup, hw-data, TARGET_PAGE_SIZE, base);
+rom_add_blob(hwsetup, hw-data, TARGET_PAGE_SIZE, base, NULL, NULL, 
NULL);
 }
 
 static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 6145736..e0c576b 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -40,8 +40,9 @@ extern bool rom_file_in_ram;
 
 int rom_add_file(const char *file, const char *fw_dir,
  hwaddr addr, int32_t bootindex);
-int rom_add_blob(const char *name, const void *blob, size_t len,
- hwaddr addr);
+void *rom_add_blob(const char *name, const void *blob, size_t len,
+   hwaddr addr, const char *fw_file_name,
+   FWCfgReadCallback fw_callback, void *callback_opaque);
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
 size_t romsize, hwaddr addr);
 int rom_load_all(void);
@@ -53,7 +54,7 @@ void do_info_roms(Monitor *mon, const QDict *qdict);
 #define rom_add_file_fixed(_f, _a, _i)  \
 rom_add_file(_f, NULL, _a, _i)
 #define rom_add_blob_fixed(_f, _b, _l, _a)  \
-rom_add_blob(_f, _b, _l, _a)
+(rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL) ? 0 : -1)
 
 #define PC_ROM_MIN_VGA 0xc
 #define PC_ROM_MIN_OPTION  0xc8000
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 7b3d3ee..449bd4c 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -700,10 +700,12 @@ err:
 return -1;
 }
 
-int rom_add_blob(const char *name, const void *blob, size_t len,
- hwaddr addr)
+void *rom_add_blob(const char *name, const void *blob, size_t len,
+   hwaddr addr, const char *fw_file_name,
+   FWCfgReadCallback fw_callback, void *callback_opaque)
 {
 Rom *rom;
+void *data = NULL;
 
 rom   = g_malloc0(sizeof(*rom));
 rom-name = g_strdup(name);
@@ -713,7 +715,22 @@ int rom_add_blob(const char *name, const void *blob, 
size_t len,
 rom-data = g_malloc0(rom-datasize);
 memcpy(rom-data, blob, len);
 rom_insert(rom);
-return 0;
+if (fw_file_name  fw_cfg) {
+char devpath[100];
+
+snprintf(devpath, sizeof(devpath), /rom@%s, fw_file_name);
+
+if (rom_file_in_ram) {
+data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
+} else {
+data = rom-data;
+}
+
+fw_cfg_add_file_callback(fw_cfg, fw_file_name,
+ fw_callback, callback_opaque,
+ data, rom-romsize);
+}
+return data;
 }
 
 /* This function is specific for elf program because we don't need to allocate
-- 
MST




[Qemu-devel] [PULL v2 30/39] acpi/piix: add macros for acpi property names

2013-10-15 Thread Michael S. Tsirkin
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/i386/pc.h | 10 ++
 hw/acpi/piix4.c  |  6 +++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 085a621..5aefc5b 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -20,6 +20,16 @@ typedef struct PcPciInfo {
 Range w64;
 } PcPciInfo;
 
+#define ACPI_PM_PROP_S3_DISABLED disable_s3
+#define ACPI_PM_PROP_S4_DISABLED disable_s4
+#define ACPI_PM_PROP_S4_VAL s4_val
+#define ACPI_PM_PROP_SCI_INT sci_int
+#define ACPI_PM_PROP_ACPI_ENABLE_CMD acpi_enable_cmd
+#define ACPI_PM_PROP_ACPI_DISABLE_CMD acpi_disable_cmd
+#define ACPI_PM_PROP_PM_IO_BASE pm_io_base
+#define ACPI_PM_PROP_GPE0_BLK gpe0_blk
+#define ACPI_PM_PROP_GPE0_BLK_LEN gpe0_blk_len
+
 struct PcGuestInfo {
 bool has_pci_info;
 bool isapc_ram_fw;
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b46bd5e..4b8c1da 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -489,9 +489,9 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t 
smb_io_base,
 
 static Property piix4_pm_properties[] = {
 DEFINE_PROP_UINT32(smb_io_base, PIIX4PMState, smb_io_base, 0),
-DEFINE_PROP_UINT8(disable_s3, PIIX4PMState, disable_s3, 0),
-DEFINE_PROP_UINT8(disable_s4, PIIX4PMState, disable_s4, 0),
-DEFINE_PROP_UINT8(s4_val, PIIX4PMState, s4_val, 2),
+DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED, PIIX4PMState, disable_s3, 0),
+DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_DISABLED, PIIX4PMState, disable_s4, 0),
+DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL, PIIX4PMState, s4_val, 2),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
MST




[Qemu-devel] [PULL v2 20/39] q35: use macro for MCFG property name

2013-10-15 Thread Michael S. Tsirkin
Useful to make it accessible through QOM.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pcie_host.h | 2 ++
 hw/pci-host/q35.c  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/hw/pci/pcie_host.h b/include/hw/pci/pcie_host.h
index da0f275..33d75bd 100644
--- a/include/hw/pci/pcie_host.h
+++ b/include/hw/pci/pcie_host.h
@@ -28,6 +28,8 @@
 #define PCIE_HOST_BRIDGE(obj) \
 OBJECT_CHECK(PCIExpressHost, (obj), TYPE_PCIE_HOST_BRIDGE)
 
+#define PCIE_HOST_MCFG_BASE MCFG
+
 /* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */
 #define PCIE_BASE_ADDR_UNMAPPED  ((hwaddr)-1ULL)
 
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index 23dbeea..e46f286 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -110,7 +110,7 @@ static void q35_host_get_pci_hole64_end(Object *obj, 
Visitor *v,
 }
 
 static Property mch_props[] = {
-DEFINE_PROP_UINT64(MCFG, Q35PCIHost, parent_obj.base_addr,
+DEFINE_PROP_UINT64(PCIE_HOST_MCFG_BASE, Q35PCIHost, parent_obj.base_addr,
 MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT),
 DEFINE_PROP_SIZE(PCI_HOST_PROP_PCI_HOLE64_SIZE, Q35PCIHost,
  mch.pci_hole64_size, DEFAULT_PCI_HOLE64_SIZE),
-- 
MST




[Qemu-devel] [PULL v2 27/39] i386: add bios linker/loader

2013-10-15 Thread Michael S. Tsirkin
This adds a dynamic bios linker/loader.
This will be used by acpi table generation
code to:
- load each table in the appropriate memory segment
- link tables to each other
- fix up checksums after said linking

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/i386/bios-linker-loader.h |  27 
 hw/i386/bios-linker-loader.c | 158 +++
 hw/i386/Makefile.objs|   1 +
 3 files changed, 186 insertions(+)
 create mode 100644 hw/i386/bios-linker-loader.h
 create mode 100644 hw/i386/bios-linker-loader.c

diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
new file mode 100644
index 000..498c0af
--- /dev/null
+++ b/hw/i386/bios-linker-loader.h
@@ -0,0 +1,27 @@
+#ifndef BIOS_LINKER_LOADER_H
+#define BIOS_LINKER_LOADER_H
+
+#include glib.h
+#include stdbool.h
+#include inttypes.h
+
+GArray *bios_linker_loader_init(void);
+
+void bios_linker_loader_alloc(GArray *linker,
+  const char *file,
+  uint32_t alloc_align,
+  bool alloc_fseg);
+
+void bios_linker_loader_add_checksum(GArray *linker, const char *file,
+ void *table,
+ void *start, unsigned size,
+ uint8_t *checksum);
+
+void bios_linker_loader_add_pointer(GArray *linker,
+const char *dest_file,
+const char *src_file,
+GArray *table, void *pointer,
+uint8_t pointer_size);
+
+void *bios_linker_loader_cleanup(GArray *linker);
+#endif
diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
new file mode 100644
index 000..0833853
--- /dev/null
+++ b/hw/i386/bios-linker-loader.c
@@ -0,0 +1,158 @@
+/* Dynamic linker/loader of ACPI tables
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Author: Michael S. Tsirkin m...@redhat.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 bios-linker-loader.h
+#include hw/nvram/fw_cfg.h
+
+#include string.h
+#include assert.h
+#include qemu/bswap.h
+
+#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
+
+struct BiosLinkerLoaderEntry {
+uint32_t command;
+union {
+/*
+ * COMMAND_ALLOCATE - allocate a table from @alloc.file
+ * subject to @alloc.align alignment (must be power of 2)
+ * and @alloc.zone (can be HIGH or FSEG) requirements.
+ *
+ * Must appear exactly once for each file, and before
+ * this file is referenced by any other command.
+ */
+struct {
+char file[BIOS_LINKER_LOADER_FILESZ];
+uint32_t align;
+uint8_t zone;
+} alloc;
+
+/*
+ * COMMAND_ADD_POINTER - patch the table (originating from
+ * @dest_file) at @pointer.offset, by adding a pointer to the table
+ * originating from @src_file. 1,2,4 or 8 byte unsigned
+ * addition is used depending on @pointer.size.
+ */
+struct {
+char dest_file[BIOS_LINKER_LOADER_FILESZ];
+char src_file[BIOS_LINKER_LOADER_FILESZ];
+uint32_t offset;
+uint8_t size;
+} pointer;
+
+/*
+ * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
+ * @cksum_start and @cksum_length fields,
+ * and then add the value at @cksum.offset.
+ * Checksum simply sums -X for each byte X in the range
+ * using 8-bit math.
+ */
+struct {
+char file[BIOS_LINKER_LOADER_FILESZ];
+uint32_t offset;
+uint32_t start;
+uint32_t length;
+} cksum;
+
+/* padding */
+char pad[124];
+};
+} QEMU_PACKED;
+typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
+
+enum {
+BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1,
+BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
+BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
+};
+
+enum {
+BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
+

[Qemu-devel] [PULL v2 32/39] ich9: APIs for pc guest info

2013-10-15 Thread Michael S. Tsirkin
This adds APIs that will be used to fill in
acpi tables, implemented using QOM,
to various ich9 components.
Some information is still missing in QOM,
so we fall back on lookups by type instead.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/acpi/ich9.h|  2 ++
 include/hw/i386/ich9.h|  2 ++
 include/hw/pci-host/q35.h |  2 ++
 hw/acpi/ich9.c| 24 
 hw/isa/lpc_ich9.c | 40 
 hw/pci-host/q35.c | 10 ++
 6 files changed, 80 insertions(+)

diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index b1fe71f..82fcf9f 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -49,4 +49,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base);
 extern const VMStateDescription vmstate_ich9_pm;
 
+void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
+
 #endif /* HW_ACPI_ICH9_H */
diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h
index c5f637b..4a68b35 100644
--- a/include/hw/i386/ich9.h
+++ b/include/hw/i386/ich9.h
@@ -66,6 +66,8 @@ typedef struct ICH9LPCState {
 qemu_irq *ioapic;
 } ICH9LPCState;
 
+Object *ich9_lpc_find(void);
+
 #define Q35_MASK(bit, ms_bit, ls_bit) \
 ((uint##bit##_t)(((1ULL  ((ms_bit) + 1)) - 1)  ~((1ULL  ls_bit) - 1)))
 
diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h
index 6eb7ab6..f9db770 100644
--- a/include/hw/pci-host/q35.h
+++ b/include/hw/pci-host/q35.h
@@ -156,4 +156,6 @@ typedef struct Q35PCIHost {
 #define MCH_PCIE_DEV   1
 #define MCH_PCIE_FUNC  0
 
+uint64_t mch_mcfg_base(void);
+
 #endif /* HW_Q35_H */
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 3fb443d..7e0429e 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -24,6 +24,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include hw/hw.h
+#include qapi/visitor.h
 #include hw/i386/pc.h
 #include hw/pci/pci.h
 #include qemu/timer.h
@@ -228,3 +229,26 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 }
+
+static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ICH9LPCPMRegs *pm = opaque;
+uint32_t value = pm-pm_io_base + ICH9_PMIO_GPE0_STS;
+
+visit_type_uint32(v, value, name, errp);
+}
+
+void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
+{
+static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
+
+object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE,
+   pm-pm_io_base, errp);
+object_property_add(obj, ACPI_PM_PROP_GPE0_BLK, uint32,
+ich9_pm_get_gpe0_blk,
+NULL, NULL, pm, NULL);
+object_property_add_uint32_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
+   gpe0_len, errp);
+}
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 5633d08..19b2198 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -29,6 +29,7 @@
  */
 #include qemu-common.h
 #include hw/hw.h
+#include qapi/visitor.h
 #include qemu/range.h
 #include hw/isa/isa.h
 #include hw/sysbus.h
@@ -525,6 +526,43 @@ static const MemoryRegionOps ich9_rst_cnt_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN
 };
 
+Object *ich9_lpc_find(void)
+{
+bool ambig;
+Object *o = object_resolve_path_type(, TYPE_ICH9_LPC_DEVICE, ambig);
+
+if (ambig) {
+return NULL;
+}
+return o;
+}
+
+static void ich9_lpc_get_sci_int(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(obj);
+uint32_t value = ich9_lpc_sci_irq(lpc);
+
+visit_type_uint32(v, value, name, errp);
+}
+
+static void ich9_lpc_add_properties(ICH9LPCState *lpc)
+{
+static const uint8_t acpi_enable_cmd = ICH9_APM_ACPI_ENABLE;
+static const uint8_t acpi_disable_cmd = ICH9_APM_ACPI_DISABLE;
+
+object_property_add(OBJECT(lpc), ACPI_PM_PROP_SCI_INT, uint32,
+ich9_lpc_get_sci_int,
+NULL, NULL, NULL, NULL);
+object_property_add_uint8_ptr(OBJECT(lpc), ACPI_PM_PROP_ACPI_ENABLE_CMD,
+  acpi_enable_cmd, NULL);
+object_property_add_uint8_ptr(OBJECT(lpc), ACPI_PM_PROP_ACPI_DISABLE_CMD,
+  acpi_disable_cmd, NULL);
+
+ich9_pm_add_properties(OBJECT(lpc), lpc-pm, NULL);
+}
+
 static int ich9_lpc_initfn(PCIDevice *d)
 {
 

[Qemu-devel] [PULL v2 38/39] ssdt: fix PBLK length

2013-10-15 Thread Michael S. Tsirkin
We don't really support CPU throttling, so supply 0 PBLK length.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/i386/ssdt-proc.dsl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/ssdt-proc.dsl b/hw/i386/ssdt-proc.dsl
index 58333c7..8229bfd 100644
--- a/hw/i386/ssdt-proc.dsl
+++ b/hw/i386/ssdt-proc.dsl
@@ -37,7 +37,7 @@ DefinitionBlock (ssdt-proc.aml, SSDT, 0x01, BXPC, 
BXSSDT, 0x1)
 ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
 ACPI_EXTRACT_PROCESSOR_END ssdt_proc_end
 ACPI_EXTRACT_PROCESSOR_STRING ssdt_proc_name
-Processor(CPAA, 0xAA, 0xb010, 0x06) {
+Processor(CPAA, 0xAA, 0x, 0x0) {
 ACPI_EXTRACT_NAME_BYTE_CONST ssdt_proc_id
 Name(ID, 0xAA)
 /*
-- 
MST




[Qemu-devel] [PULL v2 39/39] ssdt-proc: update generated file

2013-10-15 Thread Michael S. Tsirkin
Update generated ssdt proc hex file (used for systems
lacking IASL) after P_BLK length change.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/i386/ssdt-proc.hex.generated | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/i386/ssdt-proc.hex.generated b/hw/i386/ssdt-proc.hex.generated
index a28172e..bb9920d 100644
--- a/hw/i386/ssdt-proc.hex.generated
+++ b/hw/i386/ssdt-proc.hex.generated
@@ -11,7 +11,7 @@ static unsigned char ssdp_proc_aml[] = {
 0x0,
 0x0,
 0x1,
-0xb3,
+0xb8,
 0x42,
 0x58,
 0x50,
@@ -34,9 +34,9 @@ static unsigned char ssdp_proc_aml[] = {
 0x4e,
 0x54,
 0x4c,
-0x28,
-0x5,
-0x10,
+0x23,
+0x8,
+0x13,
 0x20,
 0x5b,
 0x83,
@@ -51,7 +51,7 @@ static unsigned char ssdp_proc_aml[] = {
 0xb0,
 0x0,
 0x0,
-0x6,
+0x0,
 0x8,
 0x49,
 0x44,
-- 
MST




[Qemu-devel] [PULL v2 29/39] i386: define pc guest info

2013-10-15 Thread Michael S. Tsirkin
This defines a structure that will be used to fill in acpi tables
where relevant properties are not yet available using QOM.

Reviewed-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/i386/pc.h |  9 +
 hw/i386/pc.c | 21 +
 2 files changed, 30 insertions(+)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 9b2ddc4..085a621 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -9,6 +9,9 @@
 #include hw/i386/ioapic.h
 
 #include qemu/range.h
+#include qemu/bitmap.h
+#include sysemu/sysemu.h
+#include hw/pci/pci.h
 
 /* PC-style peripherals (also used by other machines).  */
 
@@ -20,6 +23,12 @@ typedef struct PcPciInfo {
 struct PcGuestInfo {
 bool has_pci_info;
 bool isapc_ram_fw;
+hwaddr ram_size;
+unsigned apic_id_limit;
+bool apic_xrupt_override;
+uint64_t numa_nodes;
+uint64_t *node_mem;
+uint64_t *node_cpu;
 FWCfgState *fw_cfg;
 };
 
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 0c313fe..d17d1d9 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1047,6 +1047,27 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t 
below_4g_mem_size,
 {
 PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
 PcGuestInfo *guest_info = guest_info_state-info;
+int i, j;
+
+guest_info-ram_size = below_4g_mem_size + above_4g_mem_size;
+guest_info-apic_id_limit = pc_apic_id_limit(max_cpus);
+guest_info-apic_xrupt_override = kvm_allows_irq0_override();
+guest_info-numa_nodes = nb_numa_nodes;
+guest_info-node_mem = g_memdup(node_mem, guest_info-numa_nodes *
+sizeof *guest_info-node_mem);
+guest_info-node_cpu = g_malloc0(guest_info-apic_id_limit *
+ sizeof *guest_info-node_cpu);
+
+for (i = 0; i  max_cpus; i++) {
+unsigned int apic_id = x86_cpu_apic_id_from_index(i);
+assert(apic_id  guest_info-apic_id_limit);
+for (j = 0; j  nb_numa_nodes; j++) {
+if (test_bit(i, node_cpumask[j])) {
+guest_info-node_cpu[apic_id] = j;
+break;
+}
+}
+}
 
 guest_info_state-machine_done.notify = pc_guest_info_machine_done;
 qemu_add_machine_init_done_notifier(guest_info_state-machine_done);
-- 
MST




[Qemu-devel] [PULL v2 33/39] pvpanic: add API to access io port

2013-10-15 Thread Michael S. Tsirkin
Add API to find pvpanic device and get its io port.
Will be used to fill in guest info structure.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/i386/pc.h |  1 +
 hw/misc/pvpanic.c| 13 -
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 95857be..e3ee0a8 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -235,6 +235,7 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
 
 /* pvpanic.c */
 void pvpanic_init(ISABus *bus);
+uint16_t pvpanic_port(void);
 
 /* e820 types */
 #define E820_RAM1
diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c
index b64e3bb..226e298 100644
--- a/hw/misc/pvpanic.c
+++ b/hw/misc/pvpanic.c
@@ -117,8 +117,19 @@ void pvpanic_init(ISABus *bus)
 isa_create_simple(bus, TYPE_ISA_PVPANIC_DEVICE);
 }
 
+#define PVPANIC_IOPORT_PROP ioport
+
+uint16_t pvpanic_port(void)
+{
+Object *o = object_resolve_path_type(, TYPE_ISA_PVPANIC_DEVICE, NULL);
+if (!o) {
+return 0;
+}
+return object_property_get_int(o, PVPANIC_IOPORT_PROP, NULL);
+}
+
 static Property pvpanic_isa_properties[] = {
-DEFINE_PROP_UINT16(ioport, PVPanicState, ioport, 0x505),
+DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicState, ioport, 0x505),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
MST




[Qemu-devel] [PULL v2 31/39] piix: APIs for pc guest info

2013-10-15 Thread Michael S. Tsirkin
This adds APIs that will be used to fill in guest acpi tables.
Some required information is still lacking in QOM, so we
fall back on lookups by type and returning explicit types.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/acpi/piix4.h |  8 
 include/hw/i386/pc.h|  1 +
 hw/acpi/piix4.c | 44 
 hw/pci-host/piix.c  |  8 
 4 files changed, 57 insertions(+), 4 deletions(-)
 create mode 100644 include/hw/acpi/piix4.h

diff --git a/include/hw/acpi/piix4.h b/include/hw/acpi/piix4.h
new file mode 100644
index 000..65e6fd7
--- /dev/null
+++ b/include/hw/acpi/piix4.h
@@ -0,0 +1,8 @@
+#ifndef HW_ACPI_PIIX4_H
+#define HW_ACPI_PIIX4_H
+
+#include qemu/typedefs.h
+
+Object *piix4_pm_find(void);
+
+#endif
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 5aefc5b..95857be 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -192,6 +192,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int 
*piix_devfn,
 MemoryRegion *pci_memory,
 MemoryRegion *ram_memory);
 
+PCIBus *find_i440fx(void);
 /* piix4.c */
 extern PCIDevice *piix4_dev;
 int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn);
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 4b8c1da..3bcd890 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -29,6 +29,7 @@
 #include exec/ioport.h
 #include hw/nvram/fw_cfg.h
 #include exec/address-spaces.h
+#include hw/acpi/piix4.h
 
 //#define DEBUG
 
@@ -69,6 +70,8 @@ typedef struct PIIX4PMState {
 /* public */
 
 MemoryRegion io;
+uint32_t io_base;
+
 MemoryRegion io_gpe;
 MemoryRegion io_pci;
 MemoryRegion io_cpu;
@@ -152,14 +155,13 @@ static void apm_ctrl_changed(uint32_t val, void *arg)
 static void pm_io_space_update(PIIX4PMState *s)
 {
 PCIDevice *d = PCI_DEVICE(s);
-uint32_t pm_io_base;
 
-pm_io_base = le32_to_cpu(*(uint32_t *)(d-config + 0x40));
-pm_io_base = 0xffc0;
+s-io_base = le32_to_cpu(*(uint32_t *)(d-config + 0x40));
+s-io_base = 0xffc0;
 
 memory_region_transaction_begin();
 memory_region_set_enabled(s-io, d-config[0x80]  1);
-memory_region_set_address(s-io, pm_io_base);
+memory_region_set_address(s-io, s-io_base);
 memory_region_transaction_commit();
 }
 
@@ -407,6 +409,28 @@ static void piix4_pm_machine_ready(Notifier *n, void 
*opaque)
 (memory_region_present(io_as, 0x2f8) ? 0x90 : 0);
 }
 
+static void piix4_pm_add_propeties(PIIX4PMState *s)
+{
+static const uint8_t acpi_enable_cmd = ACPI_ENABLE;
+static const uint8_t acpi_disable_cmd = ACPI_DISABLE;
+static const uint32_t gpe0_blk = GPE_BASE;
+static const uint32_t gpe0_blk_len = GPE_LEN;
+static const uint16_t sci_int = 9;
+
+object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD,
+  acpi_enable_cmd, NULL);
+object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD,
+  acpi_disable_cmd, NULL);
+object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK,
+  gpe0_blk, NULL);
+object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN,
+  gpe0_blk_len, NULL);
+object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT,
+  sci_int, NULL);
+object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE,
+  s-io_base, NULL);
+}
+
 static int piix4_pm_initfn(PCIDevice *dev)
 {
 PIIX4PMState *s = PIIX4_PM(dev);
@@ -456,9 +480,21 @@ static int piix4_pm_initfn(PCIDevice *dev)
 
 piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev-bus, s);
 
+piix4_pm_add_propeties(s);
 return 0;
 }
 
+Object *piix4_pm_find(void)
+{
+bool ambig;
+Object *o = object_resolve_path_type(, TYPE_PIIX4_PM, ambig);
+
+if (ambig || !o) {
+return NULL;
+}
+return o;
+}
+
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
qemu_irq sci_irq, qemu_irq smi_irq,
int kvm_enabled, FWCfgState *fw_cfg)
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index c041149..bad3953 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -416,6 +416,14 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
 return b;
 }
 
+PCIBus *find_i440fx(void)
+{
+PCIHostState *s = OBJECT_CHECK(PCIHostState,
+   object_resolve_path(/machine/i440fx, 
NULL),
+   TYPE_PCI_HOST_BRIDGE);
+return s ? s-bus : NULL;
+}
+
 /* PIIX3 PCI to ISA bridge */
 static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
 {
-- 

[Qemu-devel] [PULL v2 34/39] hpet: add API to find it

2013-10-15 Thread Michael S. Tsirkin
Add API to find HPET using QOM.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/timer/hpet.h | 2 ++
 hw/timer/hpet.c | 5 +
 2 files changed, 7 insertions(+)

diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
index 757f79f..ab44bd3 100644
--- a/include/hw/timer/hpet.h
+++ b/include/hw/timer/hpet.h
@@ -71,4 +71,6 @@ struct hpet_fw_config
 } QEMU_PACKED;
 
 extern struct hpet_fw_config hpet_cfg;
+
+bool hpet_find(void);
 #endif
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index fcd22ae..2eb75ea 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -757,6 +757,11 @@ static void hpet_device_class_init(ObjectClass *klass, 
void *data)
 dc-props = hpet_device_properties;
 }
 
+bool hpet_find(void)
+{
+return object_resolve_path_type(, TYPE_HPET, NULL);
+}
+
 static const TypeInfo hpet_device_info = {
 .name  = TYPE_HPET,
 .parent= TYPE_SYS_BUS_DEVICE,
-- 
MST




[Qemu-devel] [PULL v2 35/39] acpi: add interface to access user-installed tables

2013-10-15 Thread Michael S. Tsirkin
Also add a new API to install builtin tables, so
that we can distinguish between the two.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/acpi/acpi.h |  4 
 hw/acpi/core.c | 40 
 2 files changed, 44 insertions(+)

diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
index 51733d3..6bbcb17 100644
--- a/include/hw/acpi/acpi.h
+++ b/include/hw/acpi/acpi.h
@@ -165,6 +165,10 @@ extern int acpi_enabled;
 extern char unsigned *acpi_tables;
 extern size_t acpi_tables_len;
 
+uint8_t *acpi_table_first(void);
+uint8_t *acpi_table_next(uint8_t *current);
+unsigned acpi_table_len(void *current);
 void acpi_table_add(const QemuOpts *opts, Error **errp);
+void acpi_table_add_builtin(const QemuOpts *opts, Error **errp);
 
 #endif /* !QEMU_HW_ACPI_H */
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 7467b88..4d25d8e 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -309,6 +309,46 @@ out:
 error_propagate(errp, err);
 }
 
+static bool acpi_table_builtin = false;
+
+void acpi_table_add_builtin(const QemuOpts *opts, Error **errp)
+{
+acpi_table_builtin = true;
+acpi_table_add(opts, errp);
+}
+
+unsigned acpi_table_len(void *current)
+{
+struct acpi_table_header *hdr = current - sizeof(hdr-_length);
+return hdr-_length;
+}
+
+static
+void *acpi_table_hdr(void *h)
+{
+struct acpi_table_header *hdr = h;
+return hdr-sig;
+}
+
+uint8_t *acpi_table_first(void)
+{
+if (acpi_table_builtin || !acpi_tables) {
+return NULL;
+}
+return acpi_table_hdr(acpi_tables + ACPI_TABLE_PFX_SIZE);
+}
+
+uint8_t *acpi_table_next(uint8_t *current)
+{
+uint8_t *next = current + acpi_table_len(current);
+
+if (next - acpi_tables = acpi_tables_len) {
+return NULL;
+} else {
+return acpi_table_hdr(next);
+}
+}
+
 static void acpi_notify_wakeup(Notifier *notifier, void *data)
 {
 ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
-- 
MST




[Qemu-devel] [PULL v2 36/39] pc: use new api to add builtin tables

2013-10-15 Thread Michael S. Tsirkin
At this point the only builtin table we have is
the DSDT used for Q35.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 hw/i386/pc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d17d1d9..f8a3f0b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1114,7 +1114,7 @@ void pc_acpi_init(const char *default_dsdt)
 opts = qemu_opts_parse(qemu_find_opts(acpi), arg, 0);
 g_assert(opts != NULL);
 
-acpi_table_add(opts, err);
+acpi_table_add_builtin(opts, err);
 if (err) {
 error_report(WARNING: failed to load %s: %s, filename,
  error_get_pretty(err));
-- 
MST




[Qemu-devel] [PULL v2 19/39] pcie_host: expose address format

2013-10-15 Thread Michael S. Tsirkin
Callers pass in the address so it's helpful for
them to be able to decode it.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pcie_host.h | 21 +
 hw/pci/pcie_host.c | 21 -
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/hw/pci/pcie_host.h b/include/hw/pci/pcie_host.h
index bac3c67..da0f275 100644
--- a/include/hw/pci/pcie_host.h
+++ b/include/hw/pci/pcie_host.h
@@ -54,4 +54,25 @@ void pcie_host_mmcfg_update(PCIExpressHost *e,
 hwaddr addr,
 uint32_t size);
 
+/*
+ * PCI express ECAM (Enhanced Configuration Address Mapping) format.
+ * AKA mmcfg address
+ * bit 20 - 28: bus number
+ * bit 15 - 19: device number
+ * bit 12 - 14: function number
+ * bit  0 - 11: offset in configuration space of a given device
+ */
+#define PCIE_MMCFG_SIZE_MAX (1ULL  28)
+#define PCIE_MMCFG_SIZE_MIN (1ULL  20)
+#define PCIE_MMCFG_BUS_BIT  20
+#define PCIE_MMCFG_BUS_MASK 0x1ff
+#define PCIE_MMCFG_DEVFN_BIT12
+#define PCIE_MMCFG_DEVFN_MASK   0xff
+#define PCIE_MMCFG_CONFOFFSET_MASK  0xfff
+#define PCIE_MMCFG_BUS(addr)(((addr)  PCIE_MMCFG_BUS_BIT)  \
+ PCIE_MMCFG_BUS_MASK)
+#define PCIE_MMCFG_DEVFN(addr)  (((addr)  PCIE_MMCFG_DEVFN_BIT)  \
+ PCIE_MMCFG_DEVFN_MASK)
+#define PCIE_MMCFG_CONFOFFSET(addr) ((addr)  PCIE_MMCFG_CONFOFFSET_MASK)
+
 #endif /* PCIE_HOST_H */
diff --git a/hw/pci/pcie_host.c b/hw/pci/pcie_host.c
index 410ac08..c6e1b57 100644
--- a/hw/pci/pcie_host.c
+++ b/hw/pci/pcie_host.c
@@ -24,27 +24,6 @@
 #include hw/pci/pcie_host.h
 #include exec/address-spaces.h
 
-/*
- * PCI express mmcfig address
- * bit 20 - 28: bus number
- * bit 15 - 19: device number
- * bit 12 - 14: function number
- * bit  0 - 11: offset in configuration space of a given device
- */
-#define PCIE_MMCFG_SIZE_MAX (1ULL  28)
-#define PCIE_MMCFG_SIZE_MIN (1ULL  20)
-#define PCIE_MMCFG_BUS_BIT  20
-#define PCIE_MMCFG_BUS_MASK 0x1ff
-#define PCIE_MMCFG_DEVFN_BIT12
-#define PCIE_MMCFG_DEVFN_MASK   0xff
-#define PCIE_MMCFG_CONFOFFSET_MASK  0xfff
-#define PCIE_MMCFG_BUS(addr)(((addr)  PCIE_MMCFG_BUS_BIT)  \
- PCIE_MMCFG_BUS_MASK)
-#define PCIE_MMCFG_DEVFN(addr)  (((addr)  PCIE_MMCFG_DEVFN_BIT)  \
- PCIE_MMCFG_DEVFN_MASK)
-#define PCIE_MMCFG_CONFOFFSET(addr) ((addr)  PCIE_MMCFG_CONFOFFSET_MASK)
-
-
 /* a helper function to get a PCIDevice for a given mmconfig address */
 static inline PCIDevice *pcie_dev_find_by_mmcfg_addr(PCIBus *s,
  uint32_t mmcfg_addr)
-- 
MST




Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Anup Patel
Hi Andrew,

On Mon, Oct 14, 2013 at 9:29 PM, Andrew Jones drjo...@redhat.com wrote:
 This is a virtio version of hw/misc/debugexit and should evolve into a
 virtio version of pc-testdev. pc-testdev uses the PC's ISA bus, whereas
 this testdev can be plugged into a virtio-mmio transport, which is
 needed for kvm-unit-tests/arm. virtio-testdev uses the virtio device
 config space as a communication channel, and implements an RTAS-like
 protocol through it allowing guests to execute commands. Only three
 commands are currently implemented;
 1) VERSION: for version compatibility checks
 2) CLEAR:   set all the config space back to zero
 3) EXIT:exit() from qemu with a status code

How about adding RESET command to reset the VM?

Regards,
Anup


 Note, the protocol also requires all data passing through the config
 space to be in little-endian.

 See [1] for an example of a driver for this device.

 [1] 
 https://github.com/rhdrjones/kvm-unit-tests/blob/ff8df5378ffccfbdf25fe79241837e61eb2258e1/lib/virtio-testdev.c

 Signed-off-by: Andrew Jones drjo...@redhat.com
 ---
  default-configs/arm-softmmu.mak |   2 +
  hw/virtio/Makefile.objs |   1 +
  hw/virtio/virtio-testdev.c  | 117 
 
  3 files changed, 120 insertions(+)
  create mode 100644 hw/virtio/virtio-testdev.c

 diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
 index ac0815d66310f..56f8086e61974 100644
 --- a/default-configs/arm-softmmu.mak
 +++ b/default-configs/arm-softmmu.mak
 @@ -80,3 +80,5 @@ CONFIG_VERSATILE_PCI=y
  CONFIG_VERSATILE_I2C=y

  CONFIG_SDHCI=y
 +
 +CONFIG_VIRTIO_TESTDEV=y
 diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
 index 1ba53d9cc316c..b3d16d522f54b 100644
 --- a/hw/virtio/Makefile.objs
 +++ b/hw/virtio/Makefile.objs
 @@ -3,6 +3,7 @@ common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
  common-obj-y += virtio-bus.o
  common-obj-y += virtio-mmio.o
  common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += dataplane/
 +common-obj-$(CONFIG_VIRTIO_TESTDEV) += virtio-testdev.o

  obj-y += virtio.o virtio-balloon.o
  obj-$(CONFIG_LINUX) += vhost.o
 diff --git a/hw/virtio/virtio-testdev.c b/hw/virtio/virtio-testdev.c
 new file mode 100644
 index 0..d6852d563702e
 --- /dev/null
 +++ b/hw/virtio/virtio-testdev.c
 @@ -0,0 +1,117 @@
 +#include hw/virtio/virtio-bus.h
 +
 +#define VIRTIO_ID_TESTDEV 0x
 +
 +#define TYPE_VIRTIO_TESTDEV virtio-testdev
 +#define VIRTIO_TESTDEV(obj) \
 +OBJECT_CHECK(VirtIOTestdev, (obj), TYPE_VIRTIO_TESTDEV)
 +
 +#define TESTDEV_MAJOR_VER 1
 +#define TESTDEV_MINOR_VER 1
 +
 +#define CONFIG_SIZE 0x100
 +
 +enum {
 +VERSION = 1,
 +CLEAR,
 +EXIT,
 +};
 +
 +enum { TOKEN, NARGS, NRETS, ARG1, ARG2, ARG3, ARG4, };
 +
 +#define RET1(nargs) (ARG1 + (nargs) + 0)
 +#define RET2(nargs) (ARG1 + (nargs) + 1)
 +#define RET3(nargs) (ARG1 + (nargs) + 2)
 +#define RET4(nargs) (ARG1 + (nargs) + 3)
 +
 +#define calc_len(nargs, nrets) ((3 + (nargs) + (nrets)) * 4)
 +
 +typedef struct VirtIOTestdev {
 +VirtIODevice parent_obj;
 +uint8_t config[CONFIG_SIZE];
 +size_t len; /* currently used bytes */
 +} VirtIOTestdev;
 +
 +static void virtio_testdev_get_config(VirtIODevice *vdev, uint8_t 
 *config_data)
 +{
 +VirtIOTestdev *dev = VIRTIO_TESTDEV(vdev);
 +memcpy(config_data, dev-config[0], dev-len);
 +}
 +
 +static void virtio_testdev_set_config(VirtIODevice *vdev,
 +  const uint8_t *config_data)
 +{
 +VirtIOTestdev *dev = VIRTIO_TESTDEV(vdev);
 +uint32_t *c32 = (uint32_t *)dev-config[0];
 +uint32_t token, nargs, nrets;
 +
 +memcpy(c32, config_data, 32); /* assume write is in first 32 bytes,
 + we can grab more later, if needed */
 +token = le32_to_cpu(c32[TOKEN]);
 +nargs = le32_to_cpu(c32[NARGS]);
 +nrets = le32_to_cpu(c32[NRETS]);
 +
 +if (!token) {
 +return;
 +}
 +
 +switch (token) {
 +case VERSION:
 +c32[RET1(nargs)] =
 +cpu_to_le32((TESTDEV_MAJOR_VER  16) | TESTDEV_MINOR_VER);
 +break;
 +case CLEAR:
 +memset(c32, 0, CONFIG_SIZE);
 +break;
 +case EXIT:
 +exit((le32_to_cpu(c32[ARG1])  1) | 1);
 +default:
 +break;
 +}
 +
 +c32[TOKEN] = 0;
 +dev-len = calc_len(nargs, nrets);
 +}
 +
 +static uint32_t virtio_testdev_get_features(VirtIODevice *vdev, uint32_t f)
 +{
 +return f;
 +}
 +
 +static int virtio_testdev_init(VirtIODevice *vdev)
 +{
 +virtio_init(vdev, virtio-testdev, VIRTIO_ID_TESTDEV, CONFIG_SIZE);
 +return 0;
 +}
 +
 +static int virtio_testdev_exit(DeviceState *qdev)
 +{
 +virtio_cleanup(VIRTIO_DEVICE(qdev));
 +return 0;
 +}
 +
 +static void virtio_testdev_class_init(ObjectClass *klass, void *data)
 +{
 +DeviceClass *dc = DEVICE_CLASS(klass);
 +VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
 +dc-exit = virtio_testdev_exit;
 +

[Qemu-devel] [PULL v2 23/39] acpi: add rules to compile ASL source

2013-10-15 Thread Michael S. Tsirkin
Detect presence of IASL compiler and use it
to process ASL source. If not there, use pre-compiled
files in-tree. Add script to update the in-tree files.

Note: distros are known to silently update iasl
so detect correct iasl flags for the installed version on each run as
opposed to at configure time.

Reviewed-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 configure  |  9 -
 hw/i386/Makefile.objs  | 22 ++
 scripts/update-acpi.sh |  4 
 3 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 scripts/update-acpi.sh

diff --git a/configure b/configure
index 2b83936..15405e1 100755
--- a/configure
+++ b/configure
@@ -119,6 +119,7 @@ path_of() {
 # default parameters
 source_path=`dirname $0`
 cpu=
+iasl=iasl
 interp_prefix=/usr/gnemul/qemu-%M
 static=no
 cross_prefix=
@@ -257,6 +258,8 @@ for opt do
   ;;
   --cxx=*) CXX=$optarg
   ;;
+  --iasl=*) iasl=$optarg
+  ;;
   --source-path=*) source_path=$optarg
   ;;
   --cpu=*) cpu=$optarg
@@ -1055,6 +1058,7 @@ echo Advanced options (experts only):
 echo   --source-path=PATH   path of source code [$source_path]
 echo   --cross-prefix=PREFIXuse PREFIX for compile tools [$cross_prefix]
 echo   --cc=CC  use C compiler CC [$cc]
+echo   --iasl=IASL  use ACPI compiler IASL [$iasl]
 echo   --host-cc=CC use C compiler CC [$host_cc] for code run at
 echobuild time
 echo   --cxx=CXXuse C++ compiler CXX [$cxx]
@@ -4239,6 +4243,9 @@ else
 fi
 echo PYTHON=$python  $config_host_mak
 echo CC=$cc  $config_host_mak
+if $iasl -h  /dev/null 21; then
+  echo IASL=$iasl  $config_host_mak
+fi
 echo CC_I386=$cc_i386  $config_host_mak
 echo HOST_CC=$host_cc  $config_host_mak
 echo CXX=$cxx  $config_host_mak
@@ -4691,7 +4698,7 @@ for rom in seabios vgabios ; do
 echo BCC=bcc  $config_mak
 echo CPP=$cpp  $config_mak
 echo OBJCOPY=objcopy  $config_mak
-echo IASL=iasl  $config_mak
+echo IASL=$iasl  $config_mak
 echo LD=$ld  $config_mak
 done
 
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 45e6165..f950707 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -5,3 +5,25 @@ obj-y += pc_sysfw.o
 obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
 
 obj-y += kvmvapic.o
+
+iasl-option=$(shell if test -z `$(1) $(2) 21  /dev/null` \
+; then echo $(2); else echo $(3); fi ;)
+
+ifdef IASL
+#IASL Present. Generate hex files from .dsl
+hw/i386/%.hex: $(SRC_PATH)/hw/i386/%.dsl 
$(SRC_PATH)/scripts/acpi_extract_preprocess.py 
$(SRC_PATH)/scripts/acpi_extract.py
+   $(call quiet-command, cpp -P $ -o $*.dsl.i.orig,   CPP 
$(TARGET_DIR)$*.dsl.i.orig)
+   $(call quiet-command, $(PYTHON) 
$(SRC_PATH)/scripts/acpi_extract_preprocess.py $*.dsl.i.orig  $*.dsl.i,   
ACPI_PREPROCESS $(TARGET_DIR)$*.dsl.i)
+   $(call quiet-command, $(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l 
-tc -p $* $*.dsl.i $(if $(V), ,  /dev/null) 21 ,  IASL 
$(TARGET_DIR)$*.dsl.i)
+   $(call quiet-command, $(SRC_PATH)/scripts/acpi_extract.py $*.lst  
$*.off,   ACPI_EXTRACT $(TARGET_DIR)$*.off)
+   $(call quiet-command, cat $*.off  $@,   CAT $(TARGET_DIR)$@)
+else
+#IASL Not present. Restore pre-generated hex files.
+hw/i386/%.hex: $(SRC_PATH)/hw/i386/%.hex.generated
+   $(call quiet-command, cp -f $ $@,   CP $(TARGET_DIR)$@)
+endif
+
+.PHONY: cleanhex
+cleanhex:
+   rm -f hw/i386/*hex
+clean: cleanhex
diff --git a/scripts/update-acpi.sh b/scripts/update-acpi.sh
new file mode 100644
index 000..b5f05ff
--- /dev/null
+++ b/scripts/update-acpi.sh
@@ -0,0 +1,4 @@
+cd x86_64-softmmu
+for file in hw/i386/*.hex; do
+cp -f $file ../$file.generated
+done
-- 
MST




[Qemu-devel] [PULL v2 18/39] pcie_host: expose UNMAPPED macro

2013-10-15 Thread Michael S. Tsirkin
Make it possible to test unmapped status through QMP.

Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/pci/pcie_host.h | 3 +++
 hw/pci/pcie_host.c | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/hw/pci/pcie_host.h b/include/hw/pci/pcie_host.h
index 1228e36..bac3c67 100644
--- a/include/hw/pci/pcie_host.h
+++ b/include/hw/pci/pcie_host.h
@@ -28,6 +28,9 @@
 #define PCIE_HOST_BRIDGE(obj) \
 OBJECT_CHECK(PCIExpressHost, (obj), TYPE_PCIE_HOST_BRIDGE)
 
+/* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */
+#define PCIE_BASE_ADDR_UNMAPPED  ((hwaddr)-1ULL)
+
 struct PCIExpressHost {
 PCIHostState pci;
 
diff --git a/hw/pci/pcie_host.c b/hw/pci/pcie_host.c
index b70e5ad..410ac08 100644
--- a/hw/pci/pcie_host.c
+++ b/hw/pci/pcie_host.c
@@ -104,9 +104,6 @@ static const MemoryRegionOps pcie_mmcfg_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-/* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */
-#define PCIE_BASE_ADDR_UNMAPPED  ((hwaddr)-1ULL)
-
 int pcie_host_init(PCIExpressHost *e)
 {
 e-base_addr = PCIE_BASE_ADDR_UNMAPPED;
-- 
MST




[Qemu-devel] [PATCH v2] block: support dropping active in bdrv_drop_intermediate

2013-10-15 Thread Fam Zheng
There is only one failure point: bdrv_change_backing_file in this
function, so we can drop the qlist and try to change the backing file
before deleting anything.

This way bdrv_drop_intermediate is simplified while keeping the
operation transactional. A bonus is dropping an active BDS is supported
too by swapping the base and top. Although no caller uses this yet, the
comment is updated to reflect the change.

Signed-off-by: Fam Zheng f...@redhat.com

---
v2: check for active, top and base being in a backing chain. (Jeff)

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c| 103 -
 block/commit.c |   1 +
 2 files changed, 37 insertions(+), 67 deletions(-)

diff --git a/block.c b/block.c
index fd05a80..9ead554 100644
--- a/block.c
+++ b/block.c
@@ -2130,18 +2130,11 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState 
*active,
 return overlay;
 }
 
-typedef struct BlkIntermediateStates {
-BlockDriverState *bs;
-QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
-} BlkIntermediateStates;
-
-
 /*
- * Drops images above 'base' up to and including 'top', and sets the image
- * above 'top' to have base as its backing file.
- *
- * Requires that the overlay to 'top' is opened r/w, so that the backing file
- * information in 'bs' can be properly updated.
+ * Drops images above 'base' up to and including 'top', and sets new 'base'
+ * as backing_hd of top_overlay (the image orignally has 'top' as backing
+ * file). top_overlay may be NULL if 'top' is active, no such update needed.
+ * Requires that the top_overlay to 'top' is opened r/w.
  *
  * E.g., this will convert the following chain:
  * bottom - base - intermediate - top - active
@@ -2158,86 +2151,62 @@ typedef struct BlkIntermediateStates {
  *
  * base - active
  *
- * Error conditions:
- *  if active == top, that is considered an error
+ * It also allows active==top, in which case it converts:
+ *
+ * base - intermediate - active (also top)
+ *
+ * to
+ *
+ * base == active == top, i.e. only base remains: *top == *base when return.
  *
  */
 int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
BlockDriverState *base)
 {
-BlockDriverState *intermediate;
+BlockDriverState *pbs;
+BlockDriverState *overlay = NULL;
 BlockDriverState *base_bs = NULL;
-BlockDriverState *new_top_bs = NULL;
-BlkIntermediateStates *intermediate_state, *next;
-int ret = -EIO;
-
-QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete;
-QSIMPLEQ_INIT(states_to_delete);
+int ret = -EINVAL;
 
 if (!top-drv || !base-drv) {
 goto exit;
 }
 
-new_top_bs = bdrv_find_overlay(active, top);
-
-if (new_top_bs == NULL) {
-/* we could not find the image above 'top', this is an error */
-goto exit;
-}
-
-/* special case of new_top_bs-backing_hd already pointing to base - 
nothing
- * to do, no intermediate images */
-if (new_top_bs-backing_hd == base) {
-ret = 0;
+if (!bdrv_find_overlay(active, base)) {
 goto exit;
 }
 
-intermediate = top;
-
-/* now we will go down through the list, and add each BDS we find
- * into our deletion queue, until we hit the 'base'
- */
-while (intermediate) {
-intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
-intermediate_state-bs = intermediate;
-QSIMPLEQ_INSERT_TAIL(states_to_delete, intermediate_state, entry);
-
-if (intermediate-backing_hd == base) {
-base_bs = intermediate-backing_hd;
-break;
+if (active != top) {
+/* If there's an overlay, its backing_hd points to top's BDS now,
+ * the top image is dropped but this BDS structure is kept and swapped
+ * with base, this way we keep the pointers valid after dropping top */
+overlay = bdrv_find_overlay(active, top);
+if (!overlay) {
+goto exit;
+}
+ret = bdrv_change_backing_file(overlay, base-filename,
+   base-drv ?
+base-drv-format_name : );
+if (ret) {
+goto exit;
 }
-intermediate = intermediate-backing_hd;
-}
-if (base_bs == NULL) {
-/* something went wrong, we did not end at the base. safely
- * unravel everything, and exit with error */
-goto exit;
 }
 
-/* success - we can delete the intermediate states, and link top-base */
-ret = bdrv_change_backing_file(new_top_bs, base_bs-filename,
-   base_bs-drv ? base_bs-drv-format_name : 
);
-if (ret) {
-goto exit;
+for (pbs = top-backing_hd; pbs != base; pbs = base_bs) {
+assert(pbs);
+base_bs = pbs-backing_hd;
+pbs-backing_hd = NULL;
+bdrv_unref(pbs);
 }
-new_top_bs-backing_hd = base_bs;
-
 
-

[Qemu-devel] [PATCH v3 2/4] Curling: cmdline interface.

2013-10-15 Thread Jules Wang
Add an option '-f' to migration cmdline.
Indicating whether to enable fault tolerant or not.

Signed-off-by: Jules Wang junqing.w...@cs2c.com.cn
---
 hmp-commands.hx   | 10 ++
 hmp.c |  3 ++-
 include/migration/migration.h |  1 +
 migration.c   |  3 ++-
 qapi-schema.json  |  6 +-
 qmp-commands.hx   |  3 ++-
 6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index caae5ad..e6fa3f7 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -877,23 +877,25 @@ ETEXI
 
 {
 .name   = migrate,
-.args_type  = detach:-d,blk:-b,inc:-i,uri:s,
-.params = [-d] [-b] [-i] uri,
+.args_type  = detach:-d,blk:-b,inc:-i,fault-tolerant:-f,uri:s,
+.params = [-d] [-b] [-i] [-f] uri,
 .help   = migrate to URI (using -d to not wait for completion)
  \n\t\t\t -b for migration without shared storage with
   full copy of disk\n\t\t\t -i for migration without 
  shared storage with incremental copy of disk 
- (base image shared between src and destination),
+ (base image shared between src and destination)
+ \n\t\t\t -f for fault tolerant mode,
 .mhandler.cmd = hmp_migrate,
 },
 
 
 STEXI
-@item migrate [-d] [-b] [-i] @var{uri}
+@item migrate [-d] [-b] [-i] [-f] @var{uri}
 @findex migrate
 Migrate to @var{uri} (using -d to not wait for completion).
-b for migration with full copy of disk
-i for migration with incremental copy of disk (base image is shared)
+   -f for fault tolerant mode
 ETEXI
 
 {
diff --git a/hmp.c b/hmp.c
index 5891507..623a3f0 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1265,10 +1265,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
 int detach = qdict_get_try_bool(qdict, detach, 0);
 int blk = qdict_get_try_bool(qdict, blk, 0);
 int inc = qdict_get_try_bool(qdict, inc, 0);
+int ft = qdict_get_try_bool(qdict, fault-tolerant, 0);
 const char *uri = qdict_get_str(qdict, uri);
 Error *err = NULL;
 
-qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, err);
+qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, !!ft, ft, err);
 if (err) {
 monitor_printf(mon, migrate: %s\n, error_get_pretty(err));
 error_free(err);
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 140e6b4..fc2b066 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -25,6 +25,7 @@
 
 struct MigrationParams {
 bool blk;
+bool ft;
 bool shared;
 };
 
diff --git a/migration.c b/migration.c
index 2b1ab20..08dcca0 100644
--- a/migration.c
+++ b/migration.c
@@ -395,7 +395,7 @@ void migrate_del_blocker(Error *reason)
 
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
  bool has_inc, bool inc, bool has_detach, bool detach,
- Error **errp)
+ bool has_ft, bool ft, Error **errp)
 {
 Error *local_err = NULL;
 MigrationState *s = migrate_get_current();
@@ -404,6 +404,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 
 params.blk = has_blk  blk;
 params.shared = has_inc  inc;
+params.ft = has_ft  ft;
 
 if (s-state == MIG_STATE_ACTIVE || s-state == MIG_STATE_SETUP) {
 error_set(errp, QERR_MIGRATION_ACTIVE);
diff --git a/qapi-schema.json b/qapi-schema.json
index 60f3fd1..49dd5ff 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2594,12 +2594,16 @@
 # @detach: this argument exists only for compatibility reasons and
 #  is ignored by QEMU
 #
+# @fault-tolerant: #optional true to enable fault tolerant
+#  (since 1.7)
+#
 # Returns: nothing on success
 #
 # Since: 0.14.0
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool',
+   '*fault-tolerant': 'bool' } }
 
 # @xen-save-devices-state:
 #
diff --git a/qmp-commands.hx b/qmp-commands.hx
index fba15cd..ff13baf 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -611,7 +611,7 @@ EQMP
 
 {
 .name   = migrate,
-.args_type  = detach:-d,blk:-b,inc:-i,uri:s,
+.args_type  = detach:-d,blk:-b,inc:-i,fault-tolerant:-f,uri:s,
 .mhandler.cmd_new = qmp_marshal_input_migrate,
 },
 
@@ -625,6 +625,7 @@ Arguments:
 
 - blk: block migration, full disk copy (json-bool, optional)
 - inc: incremental disk copy (json-bool, optional)
+- fault-tolerant: fault tolerant (json-bool, optional)
 - uri: Destination URI (json-string)
 
 Example:
-- 
1.8.0.1





[Qemu-devel] [PATCH v3 3/4] Curling: the sender

2013-10-15 Thread Jules Wang
By leveraging live migration feature, the sender simply starts a
new migration when the previous migration is completed.

We need to handle the variables related to live migration very
carefully. So the new migration does not restart from the very
begin of the migration, instead, it continues the previous
migration.

Signed-off-by: Jules Wang junqing.w...@cs2c.com.cn
---
 arch_init.c | 25 -
 include/sysemu/sysemu.h |  3 ++-
 migration.c | 25 +++--
 savevm.c| 20 
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 7545d96..f71dfc4 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -107,6 +107,7 @@ const uint32_t arch_type = QEMU_ARCH;
 static bool mig_throttle_on;
 static int dirty_rate_high_cnt;
 static void check_guest_throttling(void);
+static MigrationParams ram_mig_params;
 
 /***/
 /* ram save/restore */
@@ -595,6 +596,11 @@ static void ram_migration_cancel(void *opaque)
 migration_end();
 }
 
+static void ram_set_params(const MigrationParams *params, void *opaque)
+{
+ram_mig_params.ft = params-ft;
+}
+
 static void reset_ram_globals(void)
 {
 last_seen_block = NULL;
@@ -610,10 +616,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
 RAMBlock *block;
 int64_t ram_pages = last_ram_offset()  TARGET_PAGE_BITS;
+bool create = false;
 
-migration_bitmap = bitmap_new(ram_pages);
-bitmap_set(migration_bitmap, 0, ram_pages);
-migration_dirty_pages = ram_pages;
+if (!ram_mig_params.ft || !migration_bitmap)  {
+migration_bitmap = bitmap_new(ram_pages);
+bitmap_set(migration_bitmap, 0, ram_pages);
+migration_dirty_pages = ram_pages;
+create = true;
+}
 mig_throttle_on = false;
 dirty_rate_high_cnt = 0;
 
@@ -633,7 +643,9 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 qemu_mutex_lock_iothread();
 qemu_mutex_lock_ramlist();
 bytes_transferred = 0;
-reset_ram_globals();
+if (!ram_mig_params.ft || create) {
+reset_ram_globals();
+}
 
 memory_global_dirty_log_start();
 migration_bitmap_sync();
@@ -748,7 +760,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 }
 
 ram_control_after_iterate(f, RAM_CONTROL_FINISH);
-migration_end();
+if (!ram_mig_params.ft) {
+migration_end();
+}
 
 qemu_mutex_unlock_ramlist();
 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
@@ -975,6 +989,7 @@ SaveVMHandlers savevm_ram_handlers = {
 .save_live_pending = ram_save_pending,
 .load_state = ram_load,
 .cancel = ram_migration_cancel,
+.set_params = ram_set_params,
 };
 
 struct soundhw {
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index cd5791e..31d5e3f 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -82,7 +82,8 @@ bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_begin(QEMUFile *f,
  const MigrationParams *params);
 int qemu_savevm_state_iterate(QEMUFile *f);
-void qemu_savevm_state_complete(QEMUFile *f);
+void qemu_savevm_state_complete(QEMUFile *f,
+const MigrationParams *params);
 void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 int qemu_loadvm_state(QEMUFile *f);
diff --git a/migration.c b/migration.c
index 08dcca0..28acd05 100644
--- a/migration.c
+++ b/migration.c
@@ -553,6 +553,7 @@ static void *migration_thread(void *opaque)
 int64_t max_size = 0;
 int64_t start_time = initial_time;
 bool old_vm_running = false;
+int  time_window = 100;
 
 DPRINTF(beginning savevm\n);
 qemu_savevm_state_begin(s-file, s-params);
@@ -564,6 +565,8 @@ static void *migration_thread(void *opaque)
 
 while (s-state == MIG_STATE_ACTIVE) {
 int64_t current_time;
+int64_t time_spent;
+int64_t migration_start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
 uint64_t pending_size;
 
 if (!qemu_file_rate_limit(s-file)) {
@@ -585,7 +588,7 @@ static void *migration_thread(void *opaque)
 ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
 if (ret = 0) {
 qemu_file_set_rate_limit(s-file, INT_MAX);
-qemu_savevm_state_complete(s-file);
+qemu_savevm_state_complete(s-file, s-params);
 }
 qemu_mutex_unlock_iothread();
 
@@ -594,10 +597,28 @@ static void *migration_thread(void *opaque)
 break;
 }
 
-if (!qemu_file_get_error(s-file)) {
+if (!qemu_file_get_error(s-file)  !s-params.ft) {
 migrate_set_state(s, MIG_STATE_ACTIVE, 
MIG_STATE_COMPLETED);
 break;
 }
+
+if (s-params.ft) 

[Qemu-devel] [PATCH v3 1/4] Curling: add doc

2013-10-15 Thread Jules Wang
Curling provides fault tolerant mechanism for KVM.
For more info, see 'doc/curling.txt'.

Signed-off-by: Jules Wang junqing.w...@cs2c.com.cn
---
 docs/curling.txt | 51 +++
 1 file changed, 51 insertions(+)
 create mode 100644 docs/curling.txt

diff --git a/docs/curling.txt b/docs/curling.txt
new file mode 100644
index 000..f506a77
--- /dev/null
+++ b/docs/curling.txt
@@ -0,0 +1,51 @@
+KVM Fault Tolerance Specification
+=
+
+
+Contents:
+=
+* Introduction
+* Usage
+* Design  Implement
+* Performance
+
+Introduction
+
+The goal of Curling(sports) is to provide a fault tolerant(ft for short)
+mechanism for KVM, so that in the event of a hardware failure, the virtual
+machine fails over to the backup in a way that is completely transparent
+to the guest operating system.
+
+
+Usage
+=
+The steps of curling are the same as the steps of live migration except the
+following:
+1. Start ft in the qemu monitor of sender vm by following cmdline:
+migrate_set_speed full bandwidth
+migrate -f tcp:address:port
+2. Connect to the receiver vm by vnc or spice. The screen of the vm is 
displayed
+when ft is ready.
+3. Now, the sender vm is protected by ft, When it encounters a failure,
+the failover kicks in.
+
+
+
+Design  Implement
+==
+* By leveraging live migration feature, we do endless live migrations between
+the sender and receiver, so the two virtual machines are synchronized.
+
+* The receiver does not load vm state once the migration begins, instead, it
+perfetches one whole migration data into a buffer, then loads vm state from
+that buffer afterwards. This all or nothing approach prevents the
+broken-in-the-middle problem Kemari has.
+
+* The sender sleeps a little while after each migration, to ease the
+performance penalty entailed by vm_stop and iothread locks. This is a
+tradeoff between performance and accuracy.
+
+
+
+Performance
+===
-- 
1.8.0.1





[Qemu-devel] [PULL v2 16/39] fw_cfg: interface to trigger callback on read

2013-10-15 Thread Michael S. Tsirkin
Reviewed-by: Gerd Hoffmann kra...@redhat.com
Tested-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Igor Mammedov imamm...@redhat.com
Tested-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/nvram/fw_cfg.h |  4 
 hw/nvram/fw_cfg.c | 33 -
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index f60dd67..2ab0fc2 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -60,6 +60,7 @@ typedef struct FWCfgFiles {
 } FWCfgFiles;
 
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
+typedef void (*FWCfgReadCallback)(void *opaque, uint32_t offset);
 
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
@@ -70,6 +71,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, 
FWCfgCallback callback,
  void *callback_opaque, void *data, size_t len);
 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
  size_t len);
+void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
+  FWCfgReadCallback callback, void 
*callback_opaque,
+  void *data, size_t len);
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
 hwaddr crl_addr, hwaddr data_addr);
 
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index d0820e5..f5dc3ea 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -42,6 +42,7 @@ typedef struct FWCfgEntry {
 uint8_t *data;
 void *callback_opaque;
 FWCfgCallback callback;
+FWCfgReadCallback read_callback;
 } FWCfgEntry;
 
 struct FWCfgState {
@@ -249,8 +250,12 @@ static uint8_t fw_cfg_read(FWCfgState *s)
 
 if (s-cur_entry == FW_CFG_INVALID || !e-data || s-cur_offset = e-len)
 ret = 0;
-else
+else {
+if (e-read_callback) {
+e-read_callback(e-callback_opaque, s-cur_offset);
+}
 ret = e-data[s-cur_offset++];
+}
 
 trace_fw_cfg_read(s, ret);
 return ret;
@@ -381,7 +386,10 @@ static const VMStateDescription vmstate_fw_cfg = {
 }
 };
 
-void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
+static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key,
+   FWCfgReadCallback callback,
+   void *callback_opaque,
+   void *data, size_t len)
 {
 int arch = !!(key  FW_CFG_ARCH_LOCAL);
 
@@ -391,6 +399,13 @@ void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void 
*data, size_t len)
 
 s-entries[arch][key].data = data;
 s-entries[arch][key].len = (uint32_t)len;
+s-entries[arch][key].read_callback = callback;
+s-entries[arch][key].callback_opaque = callback_opaque;
+}
+
+void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
+{
+fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len);
 }
 
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
@@ -444,8 +459,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, 
FWCfgCallback callback,
 s-entries[arch][key].callback = callback;
 }
 
-void fw_cfg_add_file(FWCfgState *s,  const char *filename,
- void *data, size_t len)
+void fw_cfg_add_file_callback(FWCfgState *s,  const char *filename,
+  FWCfgReadCallback callback, void 
*callback_opaque,
+  void *data, size_t len)
 {
 int i, index;
 size_t dsize;
@@ -459,7 +475,8 @@ void fw_cfg_add_file(FWCfgState *s,  const char *filename,
 index = be32_to_cpu(s-files-count);
 assert(index  FW_CFG_FILE_SLOTS);
 
-fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index,
+   callback, callback_opaque, data, len);
 
 pstrcpy(s-files-f[index].name, sizeof(s-files-f[index].name),
 filename);
@@ -477,6 +494,12 @@ void fw_cfg_add_file(FWCfgState *s,  const char *filename,
 s-files-count = cpu_to_be32(index+1);
 }
 
+void fw_cfg_add_file(FWCfgState *s,  const char *filename,
+ void *data, size_t len)
+{
+fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
+}
+
 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 {
 size_t len;
-- 
MST




[Qemu-devel] [PATCH v3 4/4] Curling: the receiver

2013-10-15 Thread Jules Wang
The receiver does migration loop until the migration connection is
lost. Then, it is started as a backup.

The receiver does not load vm state once the migration begins.
Instead, it perfetches one whole migration data into a buffer,
then loads vm state from that buffer afterwards.

Signed-off-by: Jules Wang junqing.w...@cs2c.com.cn
---
 include/migration/qemu-file.h |   1 +
 include/sysemu/sysemu.h   |   2 +
 migration.c   |  22 --
 savevm.c  | 158 --
 4 files changed, 173 insertions(+), 10 deletions(-)

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 0f757fb..f01ff10 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -92,6 +92,7 @@ typedef struct QEMUFileOps {
 QEMURamHookFunc *after_ram_iterate;
 QEMURamHookFunc *hook_ram_load;
 QEMURamSaveFunc *save_page;
+QEMUFileGetBufferFunc *get_prefetch_buffer;
 } QEMUFileOps;
 
 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 31d5e3f..e94193c 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -87,6 +87,8 @@ void qemu_savevm_state_complete(QEMUFile *f,
 void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 int qemu_loadvm_state(QEMUFile *f);
+int qemu_loadvm_state_ft(QEMUFile *f);
+bool is_ft_migration(QEMUFile *f);
 
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
diff --git a/migration.c b/migration.c
index 28acd05..e0734a7 100644
--- a/migration.c
+++ b/migration.c
@@ -19,6 +19,7 @@
 #include monitor/monitor.h
 #include migration/qemu-file.h
 #include sysemu/sysemu.h
+#include sysemu/cpus.h
 #include block/block.h
 #include qemu/sockets.h
 #include migration/block.h
@@ -101,13 +102,24 @@ static void process_incoming_migration_co(void *opaque)
 {
 QEMUFile *f = opaque;
 int ret;
+int count = 0;
 
-ret = qemu_loadvm_state(f);
-qemu_fclose(f);
-if (ret  0) {
-fprintf(stderr, load of migration failed\n);
-exit(EXIT_FAILURE);
+if (is_ft_migration(f)) {
+while (qemu_loadvm_state_ft(f) = 0) {
+count++;
+DPRINTF(incoming count %d\r, count);
+}
+qemu_fclose(f);
+DPRINTF(ft connection lost, launching self..\n);
+} else {
+ret = qemu_loadvm_state(f);
+qemu_fclose(f);
+if (ret  0) {
+fprintf(stderr, load of migration failed\n);
+exit(EXIT_FAILURE);
+}
 }
+cpu_synchronize_all_post_init();
 qemu_announce_self();
 DPRINTF(successfully loaded vm state\n);
 
diff --git a/savevm.c b/savevm.c
index e75d5d4..611fda2 100644
--- a/savevm.c
+++ b/savevm.c
@@ -52,6 +52,8 @@
 #define ARP_PTYPE_IP 0x0800
 #define ARP_OP_REQUEST_REV 0x3
 
+#define PREFETCH_BUFFER_SIZE 0x01
+
 static int announce_self_create(uint8_t *buf,
uint8_t *mac_addr)
 {
@@ -135,6 +137,10 @@ struct QEMUFile {
 unsigned int iovcnt;
 
 int last_error;
+
+uint8_t *prefetch_buf;
+uint64_t prefetch_buf_index;
+uint64_t prefetch_buf_size;
 };
 
 typedef struct QEMUFileStdio
@@ -193,6 +199,25 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, 
int64_t pos, int size)
 return len;
 }
 
+static int socket_get_prefetch_buffer(void *opaque, uint8_t *buf,
+  int64_t pos, int size)
+{
+QEMUFile *f = opaque;
+
+if (f-prefetch_buf_size - pos = 0) {
+return 0;
+}
+
+if (f-prefetch_buf_size - pos  size) {
+size = f-prefetch_buf_size - pos;
+}
+
+memcpy(buf, f-prefetch_buf + pos, size);
+
+return size;
+}
+
+
 static int socket_close(void *opaque)
 {
 QEMUFileSocket *s = opaque;
@@ -440,6 +465,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
 static const QEMUFileOps socket_read_ops = {
 .get_fd = socket_get_fd,
 .get_buffer = socket_get_buffer,
+.get_prefetch_buffer = socket_get_prefetch_buffer,
 .close =  socket_close
 };
 
@@ -746,6 +772,8 @@ int qemu_fclose(QEMUFile *f)
 if (f-last_error) {
 ret = f-last_error;
 }
+
+g_free(f-prefetch_buf);
 g_free(f);
 return ret;
 }
@@ -829,6 +857,14 @@ void qemu_put_byte(QEMUFile *f, int v)
 
 static void qemu_file_skip(QEMUFile *f, int size)
 {
+if (f-prefetch_buf_index + size = f-prefetch_buf_size) {
+f-prefetch_buf_index += size;
+return;
+} else {
+size -= f-prefetch_buf_size - f-prefetch_buf_index;
+f-prefetch_buf_index = f-prefetch_buf_size;
+}
+
 if (f-buf_index + size = f-buf_size) {
 f-buf_index += size;
 }
@@ -838,6 +874,23 @@ static int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int 
size, size_t offset)
 {
 int pending;
 int index;
+int done;
+
+if (f-ops-get_prefetch_buffer) {
+if (f-prefetch_buf_index + 

[Qemu-devel] [PATCH v3 0/4] Curling: KVM Fault Tolerance

2013-10-15 Thread Jules Wang
v2 - v3:
* add documentation of new option in qapi-schema.

* long option name: ft - fault-tolerant

v1 - v2:
* cmdline: migrate curling:tcp:address:port 
   -  migrate -f tcp:address:port

* sender: use QEMU_VM_FILE_MAGIC_FT as the header of the migration
  to indicate this is a ft migration.

* receiver: look for the signature: 
QEMU_VM_EOF_MAGIC + QEMU_VM_FILE_MAGIC_FT(64bit total)
which indicates the end of one migration.
--
Jules Wang (4):
  Curling: add doc
  Curling: cmdline interface.
  Curling: the sender
  Curling: the receiver

 arch_init.c   |  25 --
 docs/curling.txt  |  51 
 hmp-commands.hx   |  10 ++-
 hmp.c |   3 +-
 include/migration/migration.h |   1 +
 include/migration/qemu-file.h |   1 +
 include/sysemu/sysemu.h   |   5 +-
 migration.c   |  50 ++--
 qapi-schema.json  |   6 +-
 qmp-commands.hx   |   3 +-
 savevm.c  | 178 +++---
 11 files changed, 303 insertions(+), 30 deletions(-)
 create mode 100644 docs/curling.txt

-- 
1.8.0.1





Re: [Qemu-devel] [RFC PATCH] drive-backup 'stream' mode

2013-10-15 Thread Paolo Bonzini
Il 14/10/2013 22:10, Wolfgang Richter ha scritto:
 Okay, I think my impression might be wrong, but I thought
 'drive-mirror' would become deprecated with the new 'drive-backup'
 command and code.
 
 If we look at what they do (current documentation and code),
 'drive-backup' AFAIK behaves the same for all modes of 'drive-mirror'
 _except_ mode 'none' with _better_ consistency guarantees.  That is,
 'drive-backup' clearly provides a point-in-time snapshot, whereas
 'drive-mirror' may create a point-in-time snapshot, but it can not
 guarantee that.

They are different.

drive-backup provides a point-in-time snapshot at the time the job is
started.  Completing the job stops writing to the target.

drive-mirror provides a copy at the time the job is completed.
Completing the job stops writing to the source.

 In addition, 'drive-backup's code is cleaner, simpler, and easier to
 work with (in my opinion) than 'drive-mirror's code.  This is because
 of the new hooks in block.c for tracked requests etc. so that the job
 can insert code to be run on every write in a clean manner (I think).

The simpler code for drive-backup is because it doesn't have performance
requirements.  drive-mirror has to be optimized because otherwise too
many dirty sectors pile up and the job doesn't converge.  drive-backup
runs synchronously as the VM writes to the disk.

Using the hooks in block.c we can change drive-mirror to use an active
(but still asynchronous) approach as long as the in-flight I/O does not
exceed the size of the drive-mirror buffer.  This would not simplify the
code however, it would only guarantee that I/Os are performed in the
same order as the original operations issued by the VM.

Paolo



Re: [Qemu-devel] [PATCH 1/1] add output register property and update the

2013-10-15 Thread Zhou Yuan
From: Zhouy zhouyuan.f...@cn.fujitsu.com
To: qemu-devel@nongnu.org
Date: Tue, 15 Oct 2013 15:20:47 -0400
Subject: Re: [PATCH 1/1] add output register property and update the
 outputports level when necessary

I found some instruction of output port register in the datasheet:
 Reads from the output port register reflect the value that is in the flip-flop
controlling the output selection, not the actual I/O value, which may differ if
the out-put is overloaded.
So the level of output pins should be updated according to the Output Register
when “Configuration Register is writen. 

 qemu-master/hw/gpio/max7310.c |   33 ++---
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/qemu-master/hw/gpio/max7310.c b/qemu-master/hw/gpio/max7310.c
index 59b2877..ffbeb6f 100644
--- a/qemu-master/hw/gpio/max7310.c
+++ b/qemu-master/hw/gpio/max7310.c
@@ -19,10 +19,25 @@ typedef struct {
 uint8_t polarity;
 uint8_t status;
 uint8_t command;
+uint8_t output;
 qemu_irq handler[8];
 qemu_irq *gpio_in;
 } MAX7310State;
 
+/*this function to update outputports level*/
+static void max7310_update(MAX7310State *s)
+{
+uint8_t diff = 0;
+uint8_t line = 0;
+for (diff = (s-output ^ s-level)  ~s-direction; diff;
+diff = ~(1  line)) {
+line = ffs(diff) - 1;
+if (s-handler[line]) {
+qemu_set_irq(s-handler[line], (s-output  line)  1);
+}
+}
+s-level = (s-level  s-direction) | (s-level  ~s-direction);
+}
+
 static void max7310_reset(DeviceState *dev)
 {
 MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, I2C_SLAVE(dev));
@@ -31,6 +46,8 @@ static void max7310_reset(DeviceState *dev)
 s-polarity = 0xf0;
 s-status = 0x01;
 s-command = 0x00;
+s-output = 0x00;
+max7310_update(s);
 }
 
 static int max7310_rx(I2CSlave *i2c)
@@ -43,7 +60,7 @@ static int max7310_rx(I2CSlave *i2c)
 break;
 
 case 0x01:/* Output port */
-return s-level  ~s-direction;
+return s-output;
 break;
 
 case 0x02:/* Polarity inversion */
@@ -71,8 +88,6 @@ static int max7310_rx(I2CSlave *i2c)
 static int max7310_tx(I2CSlave *i2c, uint8_t data)
 {
 MAX7310State *s = (MAX7310State *) i2c;
-uint8_t diff;
-int line;
 
 if (s-len ++  1) {
 #ifdef VERBOSE
@@ -89,13 +104,8 @@ static int max7310_tx(I2CSlave *i2c, uint8_t data)
 
 switch (s-command) {
 case 0x01:/* Output port */
-for (diff = (data ^ s-level)  ~s-direction; diff;
-diff = ~(1  line)) {
-line = ffs(diff) - 1;
-if (s-handler[line])
-qemu_set_irq(s-handler[line], (data  line)  1);
-}
-s-level = (s-level  s-direction) | (data  ~s-direction);
+s-output = data;
+max7310_update(s);
 break;
 
 case 0x02:/* Polarity inversion */
@@ -103,8 +113,8 @@ static int max7310_tx(I2CSlave *i2c, uint8_t data)
 break;
 
 case 0x03:/* Configuration */
-s-level = ~(s-direction ^ data);
 s-direction = data;
+max7310_update(s);
 break;
 
 case 0x04:/* Timeout */
@@ -156,6 +166,7 @@ static const VMStateDescription vmstate_max7310 = {
 VMSTATE_UINT8(polarity, MAX7310State),
 VMSTATE_UINT8(status, MAX7310State),
 VMSTATE_UINT8(command, MAX7310State),
+VMSTATE_UINT8(output, MAX7310State),
 VMSTATE_I2C_SLAVE(i2c, MAX7310State),
 VMSTATE_END_OF_LIST()
 }
-- 
1.7.6
Ping,anyone?


--
A new email address of FJWAN is launched from Apr.1 2007.
The updated address is: zhouyuan.f...@cn.fujitsu.com 
--
Zhou Yuan
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
TEL:+86+25-86630566-9555
FUJITSU INTERNAL:7998-9555
FAX:+86+25-83317685
EMail:zhouyuan.f...@cn.fujitsu.com
--
This communication is for use by the intended recipient(s) only and may contain 
information that is privileged, confidential and exempt from disclosure under 
applicable law. If you are not an intended recipient of this communication, you 
are hereby notified that any dissemination, distribution or copying hereof is 
strictly prohibited.  If you have received this communication in error, please 
notify me by reply e-mail, permanently delete this communication from your 
system, and destroy any hard copies you may have printed.
 
zhouyuan.f...@cn.fujitsu.com
15:14:50


Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Gerd Hoffmann
  Hi,

 Yes but at the cost of overspecifying it.
 I think it's down to the name: it's called pcimem64-start
 but it can actually be less than 4G and we need to worry what to
 do then. Also, 64 doesn't really mean 4G.
 
 So how about reserve-memory-over-4g?
 bios then does 1ull  32 + reserve-memory-over-4g
 to figure out how much to skip.

We are reaching the point where it becomes pointless bikeshedding ...

I want a interface which is clearly defined and which doesn't break if
the way we use the address space above 4g changes (hotplug,
non-contignous memory, whatever).  So make it depend on the memory
deployed isn't a clever idea.

So at the end of the day it comes down to specify an address, either
relative to 4g (your reserve-memory-over-4g suggestion) or relative to
zero (Igors pcimem64-start patch).  Both will do the job.  In both cases
the bios has to check it has no conflicts with known ram regions (i.e.
compare against 132 + RamSizeAbove4G).

I personally don't see the point in having the address relative to 4g
and prefer the pcimem64-start approach.  We could rename it to
pcimem64-minimum-address to make more clear this is about keeping some
space free rather than specifyng a fixed address where the 64bit pci
bars should be mapped to.  But at the end of the day I don't care too
much, how we are going to name the baby is just a matter of taste and
not really critical for the interface ...

What is the state of the qemu side patches btw?

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 3/5] vmstate: Simplify field-skipping load/save logic

2013-10-15 Thread Markus Armbruster
Eduardo Habkost ehabk...@redhat.com writes:

 This makes the code more readable, making each condition that makes a
 field be skipped much more visible, and reduces one level of indentation
 in the code.

 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
 ---
  savevm.c | 156 
 ---
  1 file changed, 80 insertions(+), 76 deletions(-)

 diff --git a/savevm.c b/savevm.c
 index 9562669..16276e7 100644
 --- a/savevm.c
 +++ b/savevm.c
 @@ -1694,50 +1694,52 @@ int vmstate_load_state(QEMUFile *f, const 
 VMStateDescription *vmsd,
  return ret;
  }
  for (field = vmsd-fields; field-name; field++) {
 -if ((field-field_exists 
 - field-field_exists(opaque, version_id)) ||
 -(!field-field_exists 
 - field-version_id = version_id)) {
 -void *base_addr = opaque + field-offset;
 -int i, n_elems = 1;
 -int size = field-size;
 -
 -if (field-flags  VMS_VBUFFER) {
 -size = *(int32_t *)(opaque+field-size_offset);
 -if (field-flags  VMS_MULTIPLY) {
 -size *= field-size;
 -}
 -}
 -if (field-flags  VMS_ARRAY) {
 -n_elems = field-num;
 -} else if (field-flags  VMS_VARRAY_INT32) {
 -n_elems = *(int32_t *)(opaque+field-num_offset);
 -} else if (field-flags  VMS_VARRAY_UINT32) {
 -n_elems = *(uint32_t *)(opaque+field-num_offset);
 -} else if (field-flags  VMS_VARRAY_UINT16) {
 -n_elems = *(uint16_t *)(opaque+field-num_offset);
 -} else if (field-flags  VMS_VARRAY_UINT8) {
 -n_elems = *(uint8_t *)(opaque+field-num_offset);
 +if (field-field_exists  !field-field_exists(opaque, version_id)) 
 {
 +continue;
 +}
 +if (field-version_id  version_id) {
 +continue;
 +}
 +
 +void *base_addr = opaque + field-offset;
 +int i, n_elems = 1;
 +int size = field-size;
 +
 +if (field-flags  VMS_VBUFFER) {
 +size = *(int32_t *)(opaque+field-size_offset);
 +if (field-flags  VMS_MULTIPLY) {
 +size *= field-size;
  }
 -if (field-flags  VMS_POINTER) {
 -base_addr = *(void **)base_addr + field-start;
 +}
 +if (field-flags  VMS_ARRAY) {
 +n_elems = field-num;
 +} else if (field-flags  VMS_VARRAY_INT32) {
 +n_elems = *(int32_t *)(opaque+field-num_offset);
 +} else if (field-flags  VMS_VARRAY_UINT32) {
 +n_elems = *(uint32_t *)(opaque+field-num_offset);
 +} else if (field-flags  VMS_VARRAY_UINT16) {
 +n_elems = *(uint16_t *)(opaque+field-num_offset);
 +} else if (field-flags  VMS_VARRAY_UINT8) {
 +n_elems = *(uint8_t *)(opaque+field-num_offset);
 +}
 +if (field-flags  VMS_POINTER) {
 +base_addr = *(void **)base_addr + field-start;
 +}
 +for (i = 0; i  n_elems; i++) {
 +void *addr = base_addr + size * i;
 +
 +if (field-flags  VMS_ARRAY_OF_POINTER) {
 +addr = *(void **)addr;
  }
 -for (i = 0; i  n_elems; i++) {
 -void *addr = base_addr + size * i;
 -
 -if (field-flags  VMS_ARRAY_OF_POINTER) {
 -addr = *(void **)addr;
 -}
 -if (field-flags  VMS_STRUCT) {
 -ret = vmstate_load_state(f, field-vmsd, addr,
 - field-vmsd-version_id);
 -} else {
 -ret = field-info-get(f, addr, size);
 +if (field-flags  VMS_STRUCT) {
 +ret = vmstate_load_state(f, field-vmsd, addr,
 + field-vmsd-version_id);
 +} else {
 +ret = field-info-get(f, addr, size);
  
 -}
 -if (ret  0) {
 -return ret;
 -}
 +}
 +if (ret  0) {
 +return ret;
  }
  }
  }

With whitespace change ignored:

@@ -1694,10 +1694,13 @@
 return ret;
 }
 for (field = vmsd-fields; field-name; field++) {
-if ((field-field_exists 
- field-field_exists(opaque, version_id)) ||
-(!field-field_exists 
- field-version_id = version_id)) {
+if (field-field_exists  !field-field_exists(opaque, version_id)) {
+continue;
+}
+if (field-version_id  version_id) {
+continue;
+}
+
 void *base_addr = opaque + field-offset;
 int i, n_elems = 1;
 int size = field-size;
@@ -1740,4 +1743,3 @@
 }
 }
   

Re: [Qemu-devel] [PATCH V14 00/11] Add support for binding guest numa nodes to host numa nodes

2013-10-15 Thread Wanlong Gao
Hi folks,

Settled another week, who can pick?

Thanks,
Wanlong Gao

 As you know, QEMU can't direct it's memory allocation now, this may cause
 guest cross node access performance regression.
 And, the worse thing is that if PCI-passthrough is used,
 direct-attached-device uses DMA transfer between device and qemu process.
 All pages of the guest will be pinned by get_user_pages().
 
 KVM_ASSIGN_PCI_DEVICE ioctl
   kvm_vm_ioctl_assign_device()
 =kvm_assign_device()
   = kvm_iommu_map_memslots()
 = kvm_iommu_map_pages()
= kvm_pin_pages()
 
 So, with direct-attached-device, all guest page's page count will be +1 and
 any page migration will not work. AutoNUMA won't too.
 
 So, we should set the guest nodes memory allocation policy before
 the pages are really mapped.
 
 According to this patch set, we are able to set guest nodes memory policy
 like following:
 
  -numa node,nodeid=0,cpus=0, \
  -numa mem,size=1024M,policy=membind,host-nodes=0-1 \
  -numa node,nodeid=1,cpus=1 \
  -numa mem,size=1024M,policy=interleave,host-nodes=1
 
 This supports 
 policy={default|membind|interleave|preferred},relative=true,host-nodes=N-N 
 like format.
 
 And add a QMP command query-numa to show numa info through
 this API.
 
 And convert the info numa monitor command to use this
 QMP command query-numa.
 
 This version removes set-mem-policy qmp and hmp commands temporarily
 as Marcelo and Paolo suggested.
 
 V1-V2:
 change to use QemuOpts in numa options (Paolo)
 handle Error in mpol parser (Paolo)
 change qmp command format to mem-policy=membind,mem-hostnode=0-1 like 
 (Paolo)
 V2-V3:
 also handle Error in cpus parser (5/10)
 split out common parser from cpus and hostnode parser (Bandan 6/10)
 V3-V4:
 rebase to request for comments
 V4-V5:
 use OptVisitor and split -numa option (Paolo)
  - s/set-mpol/set-mem-policy (Andreas)
  - s/mem-policy/policy
  - s/mem-hostnode/host-nodes
 fix hmp command process after error (Luiz)
 add qmp command query-numa and convert info numa to it (Luiz)
 V5-V6:
 remove tabs in json file (Laszlo, Paolo)
 add back -numa node,mem=xxx as legacy (Paolo)
 change cpus and host-nodes to array (Laszlo, Eric)
 change nodeid to uint16
 add NumaMemPolicy enum type (Eric)
 rebased on Laszlo's OptsVisitor: support / flatten integer ranges for 
 repeating options patch set, thanks for Laszlo's help
 V6-V7:
 change UInt16 to uint16 (Laszlo)
 fix a typo in adding qmp command set-mem-policy
 V7-V8:
 rebase to current master with Laszlo's V2 of OptsVisitor patch set
 fix an adding white space line error
 V8-V9:
 rebase to current master
 check if total numa memory size is equal to ram_size (Paolo)
 add comments to the OptsVisitor stuff in qapi-schema.json (Eric, Laszlo)
 replace the use of numa_num_configured_nodes() (Andrew)
 avoid abusing the fact i==nodeid (Andrew)
 V9-V10:
 rebase to current master
 remove libnuma (Andrew)
 MAX_NODES=64 - MAX_NODES=128 since libnuma selected 128 (Andrew)
 use MAX_NODES instead of MAX_CPUMASK_BITS for host_mem bitmap (Andrew)
 remove a useless clear_bit() operation (Andrew)
 V10-V11:
 rebase to current master
 fix maxnode argument of mbind(2)
 V11-V12:
 rebase to current master
 split patch 02/11 of V11 (Eduardo)
 add some max value check (Eduardo)
 split MAX_NODES change patch (Eduardo)
 V12-V13:
 rebase to current master
 thanks for Luiz's review (Luiz)
 doc hmp command set-mem-policy (Luiz)
 rename: NUMAInfo - NUMANode (Luiz)
 V13-V14:
 remove set-mem-policy qmp and hmp commands (Marcelo, Paolo)
 
 
 *I hope this can catch up the train of 1.7.*
 
 Thanks,
 Wanlong Gao
 
 Wanlong Gao (11):
   NUMA: move numa related code to new file numa.c
   NUMA: check if the total numa memory size is equal to ram_size
   NUMA: Add numa_info structure to contain numa nodes info
   NUMA: convert -numa option to use OptsVisitor
   NUMA: introduce NumaMemOptions
   NUMA: add -numa mem, options
   NUMA: expand MAX_NODES from 64 to 128
   NUMA: parse guest numa nodes memory policy
   NUMA: set guest numa nodes memory policy
   NUMA: add qmp command query-numa
   NUMA: convert hmp command info_numa to use qmp command query_numa
 
  Makefile.target |   2 +-
  cpus.c  |  14 --
  hmp.c   |  57 +++
  hmp.h   |   1 +
  hw/i386/pc.c|   4 +-
  include/sysemu/cpus.h   |   1 -
  include/sysemu/sysemu.h |  18 ++-
  monitor.c   |  21 +--
  numa.c  | 395 
 
  qapi-schema.json| 112 ++
  qemu-options.hx |   6 +-
  qmp-commands.hx |  48 ++
  vl.c| 160 +++-
  13 files changed, 654 insertions(+), 185 deletions(-)
  create mode 100644 numa.c
 




Re: [Qemu-devel] [PATCH v2] net/net: Change the default mac address of nic

2013-10-15 Thread mike

On 10/15/2013 02:05 PM, Stefan Weil wrote:

Am 15.10.2013 07:57, schrieb mike:

On 10/15/2013 01:07 PM, Stefan Weil wrote:

Am 15.10.2013 06:17, schrieb Mike Qiu:

Changelog to v1:
 Find remainder of macaddr-a[5] by modulo 256,
 otherwise it may be overflow by add index++.

The default mac address is 52:54:00:12:34:56 + index, this will
cause problem that when we boot up more than one guest with all
mac addresses unset by default, assume that each guest has one
nic. In this situation, all the guest's nic has the same mac address.

This patch is to solve this bug.

Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
---
   net/net.c | 9 ++---
   1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/net.c b/net/net.c
index c330c9a..9e72764 100644
--- a/net/net.c
+++ b/net/net.c
@@ -21,6 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN
* THE SOFTWARE.
*/
+#include time.h
+
   #include config-host.h
 #include net/net.h
@@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr
*macaddr)
 if (memcmp(macaddr, zero, sizeof(zero)) != 0)
   return;
+srand((unsigned)time(NULL));
   macaddr-a[0] = 0x52;
   macaddr-a[1] = 0x54;
   macaddr-a[2] = 0x00;
-macaddr-a[3] = 0x12;
-macaddr-a[4] = 0x34;
-macaddr-a[5] = 0x56 + index++;
+macaddr-a[3] = rand() % 256;
+macaddr-a[4] = rand() % 256;
+macaddr-a[5] = (rand() % 256 + index++) % 256;
   }
 /**

There is no overflow which must be handled because a[5] is an uint8_t
value, so the assignment automatically limits the range to 0...255.

OK, you are right, but I think we'd better to ensure this,
even though a[5] is an uint8_t.

Is it reasonable to get a random mac address in your guest? I don't
think so. It would no longer be possible to connect to a guest using
ssh, restart that guest and connect again with ssh.

Why not? I have do the experiment, after reboot, the mac is not changed.
and the ip address always the same.

And can be login to the guest after reboot.

restart means terminate QEMU and start it again.

OK,  qemu support the mac address unset right ?
So it may be a joke if just can start only one VM with mac address unset :).

In your case, also can use monitor to get the mac address, simply 'info 
network' :)

Then you can do as if you set the mac address.

Thanks
Mike









Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Andrew Jones
On Tue, Oct 15, 2013 at 12:26:10PM +0530, Anup Patel wrote:
 Hi Andrew,
 
 On Mon, Oct 14, 2013 at 9:29 PM, Andrew Jones drjo...@redhat.com wrote:
  This is a virtio version of hw/misc/debugexit and should evolve into a
  virtio version of pc-testdev. pc-testdev uses the PC's ISA bus, whereas
  this testdev can be plugged into a virtio-mmio transport, which is
  needed for kvm-unit-tests/arm. virtio-testdev uses the virtio device
  config space as a communication channel, and implements an RTAS-like
  protocol through it allowing guests to execute commands. Only three
  commands are currently implemented;
  1) VERSION: for version compatibility checks
  2) CLEAR:   set all the config space back to zero
  3) EXIT:exit() from qemu with a status code
 
 How about adding RESET command to reset the VM?
 

Hi Anup,

I'm not opposed to it, but at the moment I'm not sure how we would
utilize it within kvm-unit-tests. Maybe it would be useful for another
application though? So maybe we can add it as an add-on patch at the
time we come up with its use case?

Thanks for the review!

drew



[Qemu-devel] [RFC PATCH] spapr-vty: workaround reg property for old kernels

2013-10-15 Thread Alexey Kardashevskiy
Old kernels ( 3.1) handle hvcX devices different in different parts.
Sometime the kernel assumes that the hvc device numbers start from zero
and if there is just one hvc, then it is hvc0.

However kernel's add_preferred_console() uses the very last byte of
the VTY's reg property as an hvc number so it might end up with something
different than hvc.

The problem appears on SLES11SP3 and RHEL6. If to run QEMU without
-nodefaults, then the default VTY is created first on a VIO bus and gets
reg==0x7100 so it will be hvc0 and everything will be fine.
If to run QEMU with:
 -nodefaults \
 -chardev socket,id=char1,host=localhost,port=8001,server,telnet,mux=on \
 -device spapr-vty,chardev=char1 \
 -mon chardev=char1,mode=readline,id=mon1 \

then the exactly the same config is expected but in this case spapr-vty
gets reg==0x7101 and therefore it becomes hvc1 and lots of debug
output is missing. SLES11SP3 does not even boot as /dev/console is
redirected to /dev/hvc0 which is dead.

The issue can be solved by manual selection of VTY's reg property to
have last byte equal to zero.

The alternative would be to use separate reg property counter for
automatic reg property generation and this is what the patch does.

Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---

Since libvirt uses -nodefault a lot and in this case spapr-nvram gets
created first and gets reg=0x7100, we cannot just ignore this. Also,
it does not seem an option to require libvirt users to specify spapr-vty
reg property every time.

Can anyone think of a simpler solutionu? Thanks.


---
 hw/ppc/spapr_vio.c | 7 ++-
 include/hw/ppc/spapr_vio.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index a6a0a51..2d56950 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -438,7 +438,11 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
 VIOsPAPRBus *bus = DO_UPCAST(VIOsPAPRBus, bus, dev-qdev.parent_bus);
 
 do {
-dev-reg = bus-next_reg++;
+if (!object_dynamic_cast(OBJECT(qdev), spapr-vty)) {
+dev-reg = bus-next_reg++;
+} else {
+dev-reg = bus-next_vty_reg++;
+}
 } while (reg_conflict(dev));
 }
 
@@ -501,6 +505,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
 qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, spapr-vio);
 bus = DO_UPCAST(VIOsPAPRBus, bus, qbus);
 bus-next_reg = 0x7100;
+bus-next_vty_reg = 0x71000100;
 
 /* hcall-vio */
 spapr_register_hypercall(H_VIO_SIGNAL, h_vio_signal);
diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index d8b3b03..3a92d9e 100644
--- a/include/hw/ppc/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
@@ -73,6 +73,7 @@ struct VIOsPAPRDevice {
 struct VIOsPAPRBus {
 BusState bus;
 uint32_t next_reg;
+uint32_t next_vty_reg;
 int (*init)(VIOsPAPRDevice *dev);
 int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
 };
-- 
1.8.4.rc4




Re: [Qemu-devel] [PATCH] hmp: Add '\n' in monitor_printf()

2013-10-15 Thread Kevin Wolf
Am 15.10.2013 um 05:38 hat mike geschrieben:
 On 10/14/2013 10:36 PM, Markus Armbruster wrote:
 Mike Qiu qiud...@linux.vnet.ibm.com writes:
 
 Without this, output of 'info block'
 
 scsi0-hd0: /images/f18-ppc64.qcow2 (qcow2)
   [not inserted]
 scsi0-cd2: [not inserted]
  Removable device: not locked, tray closed
 
 floppy0: [not inserted]
  Removable device: not locked, tray closed
 
 sd0: [not inserted]
  Removable device: not locked, tray closed
 
 There will be no additional lines between scsi0-hd0 scsi0-cd2,
 and break the info style.
 Just saw a similar one:
 
  (qemu) info block
  disk0: test.img (raw)
   [not inserted]
  cd: [not inserted]
  Removable device: not locked, tray closed
 
  foo: tmp.img (raw)
  Removable device: not locked, tray closed
   [not inserted](qemu)
 
 This patch is to solve this.
 
 Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
 ---
   hmp.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/hmp.c b/hmp.c
 index 5891507..2d2e5f8 100644
 --- a/hmp.c
 +++ b/hmp.c
 @@ -367,7 +367,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
   info-value-inserted-iops_wr_max,
   info-value-inserted-iops_size);
   } else {
 -monitor_printf(mon,  [not inserted]);
 +monitor_printf(mon,  [not inserted]\n);
   }
   if (verbose) {
 monitor_printf(mon, \nImages:\n);
 
 What about removing the newline before Images?
 A good idea I think, it no need to add addition lines in one info.

 But see commit id: fbe2e26c15af35e4d157874dc80f6a19eebaa83b
 [...]
 It was changed to add this, so there maybe some reasons I think,

Like everything else in that commit, I did that change because I found it
more readable.

The problem seems to be commit 3e9fab69 ('block: Add support for
throttling burst max in QMP and the command line'), which added a bogus
[not inserted] message. We simply need to drop it altogether instead of
adding a newline.

  I think we should also drop this newline:
 
   if (info-value-removable) {
   monitor_printf(mon, Removable device: %slocked, tray 
  %s\n,
  info-value-locked ?  : not ,
  info-value-tray_open ? open : closed);
   }

Why? Look:

(qemu) info block
scsi0-cd0: /tmp/cdrom.qcow2 (qcow2)
Removable device: not locked, tray closed
Backing file: /home/kwolf/images/iso/Fedora-18-x86_64-Live-Desktop.iso 
(chain depth: 1)
I/O throttling:   bps=1048576 bps_rd=0 bps_wr=0 bps_max=104857 bps_rd_max=0 
bps_wr_max=0 iops=0 iops_rd=0 iops_wr=0 iops_max=0 iops_rd_max=0 iops_wr_max=0 
iops_size=0

Do you really want to remove the newline?

Kevin



[Qemu-devel] [PATCH -V6 1/3] target-ppc: Update external_htab even when HTAB is managed by kernel

2013-10-15 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

We will use this in later patches to make sure we use the right load
functions when copying hpte entries.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/ppc/spapr.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 004184d..22f2a8a 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -716,6 +716,13 @@ static void spapr_cpu_reset(void *opaque)
 env-spr[SPR_HIOR] = 0;
 
 env-external_htab = (uint8_t *)spapr-htab;
+if (kvm_enabled()  !env-external_htab) {
+/*
+ * HV KVM, set external_htab to 1 so our ppc_hash64_load_hpte*
+ * functions do the right thing.
+ */
+env-external_htab = (void *)1;
+}
 env-htab_base = -1;
 env-htab_mask = HTAB_SIZE(spapr) - 1;
 env-spr[SPR_SDR1] = (target_ulong)(uintptr_t)spapr-htab |
-- 
1.8.3.2




Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Michael S. Tsirkin
On Tue, Oct 15, 2013 at 10:01:01AM +0200, Gerd Hoffmann wrote:
   Hi,
 
  Yes but at the cost of overspecifying it.
  I think it's down to the name: it's called pcimem64-start
  but it can actually be less than 4G and we need to worry what to
  do then. Also, 64 doesn't really mean 4G.
  
  So how about reserve-memory-over-4g?
  bios then does 1ull  32 + reserve-memory-over-4g
  to figure out how much to skip.
 
 We are reaching the point where it becomes pointless bikeshedding ...
 
 I want a interface which is clearly defined and which doesn't break if
 the way we use the address space above 4g changes (hotplug,
 non-contignous memory, whatever).  So make it depend on the memory
 deployed isn't a clever idea.
 
 So at the end of the day it comes down to specify an address, either
 relative to 4g (your reserve-memory-over-4g suggestion) or relative to
 zero (Igors pcimem64-start patch).  Both will do the job.  In both cases
 the bios has to check it has no conflicts with known ram regions (i.e.
 compare against 132 + RamSizeAbove4G).

Actually it doesn't: bios doesn't use RAM above 4G value.
It passes it to guest but ignores it itself.
So you can likely boot guest and let it figure it out.


 
 I personally don't see the point in having the address relative to 4g
 and prefer the pcimem64-start approach.  We could rename it to
 pcimem64-minimum-address to make more clear this is about keeping some
 space free rather than specifyng a fixed address where the 64bit pci
 bars should be mapped to.  But at the end of the day I don't care too
 much, how we are going to name the baby is just a matter of taste and
 not really critical for the interface ...

I agree with this last claim.
Finding a nice name

 What is the state of the qemu side patches btw?
 
 cheers,
   Gerd
 



Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Igor Mammedov
On Tue, 15 Oct 2013 10:01:01 +0200
Gerd Hoffmann kra...@redhat.com wrote:

   Hi,
 
  Yes but at the cost of overspecifying it.
  I think it's down to the name: it's called pcimem64-start
  but it can actually be less than 4G and we need to worry what to
  do then. Also, 64 doesn't really mean 4G.
  
  So how about reserve-memory-over-4g?
  bios then does 1ull  32 + reserve-memory-over-4g
  to figure out how much to skip.
 
 We are reaching the point where it becomes pointless bikeshedding ...
 
 I want a interface which is clearly defined and which doesn't break if
 the way we use the address space above 4g changes (hotplug,
 non-contignous memory, whatever).  So make it depend on the memory
 deployed isn't a clever idea.
 
 So at the end of the day it comes down to specify an address, either
 relative to 4g (your reserve-memory-over-4g suggestion) or relative to
 zero (Igors pcimem64-start patch).  Both will do the job.  In both cases
 the bios has to check it has no conflicts with known ram regions (i.e.
 compare against 132 + RamSizeAbove4G).
 
 I personally don't see the point in having the address relative to 4g
 and prefer the pcimem64-start approach.  We could rename it to
 pcimem64-minimum-address to make more clear this is about keeping some
 space free rather than specifyng a fixed address where the 64bit pci
 bars should be mapped to.  But at the end of the day I don't care too
 much, how we are going to name the baby is just a matter of taste and
 not really critical for the interface ...
Michael,

My preference is the same as Gerd's.
Though if you NACK this approach, I'm fine with relative to 4g approach
as you suggest, the only change I'd like to see in naming is memory
reservation to be replaced with pcimem64, i.e. something like:
 pcimem64-4gb-offset
to reflect value we are actually passing in.

 
 What is the state of the qemu side patches btw?
I've them ready but they conflict with you 1Tb in e820 RFC,
I can post relevant patches as soon as we agree on this topic.
May I pick up your patch and post it along with pcimem64-start patches?
 
 
 cheers,
   Gerd
 
 
 




[Qemu-devel] [PATCH -V6 3/3] target-ppc: Fix htab_mask calculation

2013-10-15 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Correctly update the htab_mask using the return value of
KVM_PPC_ALLOCATE_HTAB ioctl. Also we don't update sdr1
on GET_SREGS for HV. So don't update htab_mask if sdr1
is found to be zero. Fix the pte index calculation to be
same as that found in the kernel

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/ppc/spapr.c  | 3 ++-
 target-ppc/mmu-hash64.c | 2 +-
 target-ppc/mmu_helper.c | 4 +++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 22f2a8a..d4f3502 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -724,7 +724,8 @@ static void spapr_cpu_reset(void *opaque)
 env-external_htab = (void *)1;
 }
 env-htab_base = -1;
-env-htab_mask = HTAB_SIZE(spapr) - 1;
+/* 128 (2**7) bytes in each HPTEG */
+env-htab_mask = (1ULL  ((spapr)-htab_shift - 7)) - 1;
 env-spr[SPR_SDR1] = (target_ulong)(uintptr_t)spapr-htab |
 (spapr-htab_shift - 18);
 }
diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c
index 5c797c3..ddd8440 100644
--- a/target-ppc/mmu-hash64.c
+++ b/target-ppc/mmu-hash64.c
@@ -354,7 +354,7 @@ static hwaddr ppc_hash64_pteg_search(CPUPPCState *env, 
hwaddr hash,
 target_ulong pte0, pte1;
 unsigned long pte_index;
 
-pte_index = (hash * HPTES_PER_GROUP)  env-htab_mask;
+pte_index = (hash  env-htab_mask) * HPTES_PER_GROUP;
 token = ppc_hash64_start_access(ppc_env_get_cpu(env), pte_index, htab_fd);
 if (!token) {
 return -1;
diff --git a/target-ppc/mmu_helper.c b/target-ppc/mmu_helper.c
index 04a840b..c39cb7b 100644
--- a/target-ppc/mmu_helper.c
+++ b/target-ppc/mmu_helper.c
@@ -2025,7 +2025,9 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
  stored in SDR1\n, htabsize);
 htabsize = 28;
 }
-env-htab_mask = (1ULL  (htabsize + 18)) - 1;
+if (htabsize) {
+env-htab_mask = (1ULL  (htabsize + 18 - 7)) - 1;
+}
 env-htab_base = value  SDR_64_HTABORG;
 } else
 #endif /* defined(TARGET_PPC64) */
-- 
1.8.3.2




[Qemu-devel] [PATCH -V6 2/3] target-ppc: Fix page table lookup with kvm enabled

2013-10-15 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

With kvm enabled, we store the hash page table information in the hypervisor.
Use ioctl to read the htab contents. Without this we get the below error when
trying to read the guest address

 (gdb) x/10 do_fork
 0xc0098660 do_fork:   Cannot access memory at address 
0xc0098660
 (gdb)

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
Changes from V5:

* Added two new patches
* Address review comments

 hw/ppc/spapr_hcall.c| 47 --
 target-ppc/kvm.c| 53 ++
 target-ppc/kvm_ppc.h| 19 
 target-ppc/mmu-hash64.c | 77 -
 target-ppc/mmu-hash64.h | 23 ++-
 5 files changed, 181 insertions(+), 38 deletions(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index f10ba8a..e04bf6c 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -52,6 +52,8 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment 
*spapr,
 target_ulong raddr;
 target_ulong i;
 hwaddr hpte;
+void *token;
+bool htab_fd;
 
 /* only handle 4k and 16M pages for now */
 if (pteh  HPTE64_V_LARGE) {
@@ -94,25 +96,32 @@ static target_ulong h_enter(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 if ((pte_index * HASH_PTE_SIZE_64)  ~env-htab_mask) {
 return H_PARAMETER;
 }
+
+i = 0;
+hpte = pte_index * HASH_PTE_SIZE_64;
 if (likely((flags  H_EXACT) == 0)) {
 pte_index = ~7ULL;
-hpte = pte_index * HASH_PTE_SIZE_64;
-for (i = 0; ; ++i) {
+token = ppc_hash64_start_access(cpu, pte_index, htab_fd);
+do {
 if (i == 8) {
+ppc_hash64_stop_access(token, htab_fd);
 return H_PTEG_FULL;
 }
-if ((ppc_hash64_load_hpte0(env, hpte)  HPTE64_V_VALID) == 0) {
+if ((ppc_hash64_load_hpte0(env, token, i)  HPTE64_V_VALID) == 0) {
 break;
 }
-hpte += HASH_PTE_SIZE_64;
-}
+} while (i++);
+ppc_hash64_stop_access(token, htab_fd);
 } else {
-i = 0;
-hpte = pte_index * HASH_PTE_SIZE_64;
-if (ppc_hash64_load_hpte0(env, hpte)  HPTE64_V_VALID) {
+token = ppc_hash64_start_access(cpu, pte_index, htab_fd);
+if (ppc_hash64_load_hpte0(env, token, 0)  HPTE64_V_VALID) {
+ppc_hash64_stop_access(token, htab_fd);
 return H_PTEG_FULL;
 }
+ppc_hash64_stop_access(token, htab_fd);
 }
+hpte += i * HASH_PTE_SIZE_64;
+
 ppc_hash64_store_hpte1(env, hpte, ptel);
 /* eieio();  FIXME: need some sort of barrier for smp? */
 ppc_hash64_store_hpte0(env, hpte, pteh | HPTE64_V_HPTE_DIRTY);
@@ -134,16 +143,18 @@ static RemoveResult remove_hpte(CPUPPCState *env, 
target_ulong ptex,
 target_ulong *vp, target_ulong *rp)
 {
 hwaddr hpte;
+void *token;
+bool htab_fd;
 target_ulong v, r, rb;
 
 if ((ptex * HASH_PTE_SIZE_64)  ~env-htab_mask) {
 return REMOVE_PARM;
 }
 
-hpte = ptex * HASH_PTE_SIZE_64;
-
-v = ppc_hash64_load_hpte0(env, hpte);
-r = ppc_hash64_load_hpte1(env, hpte);
+token = ppc_hash64_start_access(ppc_env_get_cpu(env), ptex, htab_fd);
+v = ppc_hash64_load_hpte0(env, token, 0);
+r = ppc_hash64_load_hpte1(env, token, 0);
+ppc_hash64_stop_access(token, htab_fd);
 
 if ((v  HPTE64_V_VALID) == 0 ||
 ((flags  H_AVPN)  (v  ~0x7fULL) != avpn) ||
@@ -152,6 +163,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, 
target_ulong ptex,
 }
 *vp = v;
 *rp = r;
+hpte = ptex * HASH_PTE_SIZE_64;
 ppc_hash64_store_hpte0(env, hpte, HPTE64_V_HPTE_DIRTY);
 rb = compute_tlbie_rb(v, r, ptex);
 ppc_tlb_invalidate_one(env, rb);
@@ -260,16 +272,18 @@ static target_ulong h_protect(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 target_ulong pte_index = args[1];
 target_ulong avpn = args[2];
 hwaddr hpte;
+void *token;
+bool htab_fd;
 target_ulong v, r, rb;
 
 if ((pte_index * HASH_PTE_SIZE_64)  ~env-htab_mask) {
 return H_PARAMETER;
 }
 
-hpte = pte_index * HASH_PTE_SIZE_64;
-
-v = ppc_hash64_load_hpte0(env, hpte);
-r = ppc_hash64_load_hpte1(env, hpte);
+token = ppc_hash64_start_access(cpu, pte_index, htab_fd);
+v = ppc_hash64_load_hpte0(env, token, 0);
+r = ppc_hash64_load_hpte1(env, token, 0);
+ppc_hash64_stop_access(token, htab_fd);
 
 if ((v  HPTE64_V_VALID) == 0 ||
 ((flags  H_AVPN)  (v  ~0x7fULL) != avpn)) {
@@ -282,6 +296,7 @@ static target_ulong h_protect(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 r |= (flags  48)  HPTE64_R_KEY_HI;
 r |= flags  (HPTE64_R_PP | HPTE64_R_N | HPTE64_R_KEY_LO);
 rb = compute_tlbie_rb(v, r, pte_index);
+hpte = pte_index * HASH_PTE_SIZE_64;
 ppc_hash64_store_hpte0(env, hpte, (v  

Re: [Qemu-devel] [PATCH] blockdev: fix cdrom read_only flag

2013-10-15 Thread Kevin Wolf
Am 15.10.2013 um 03:27 hat Fam Zheng geschrieben:
 Since 0ebd24e0, cdrom doesn't have read-only on by default, which will
 error out when using an read only image. Fix it by setting the default
 value when parsing opts.
 
 Reported-by: Edivaldo de Araujo Pereira edivaldoapere...@yahoo.com.br
 Signed-off-by: Fam Zheng f...@redhat.com
 ---
  blockdev.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)
 
 diff --git a/blockdev.c b/blockdev.c
 index 4f76e28..7f5ef4a 100644
 --- a/blockdev.c
 +++ b/blockdev.c
 @@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
 BlockInterfaceType block_default_type)
  int cyls, heads, secs, translation;
  int max_devs, bus_id, unit_id, index;
  const char *devaddr;
 -bool read_only, copy_on_read;
 +bool read_only = false;
 +bool copy_on_read;
  Error *local_err = NULL;
  
  /* Change legacy command line options into QMP ones */
 @@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
 BlockInterfaceType block_default_type)
  media = MEDIA_DISK;
  } else if (!strcmp(value, cdrom)) {
  media = MEDIA_CDROM;
 -qdict_put(bs_opts, read-only, qstring_from_str(on));
 +read_only = true;
  } else {
  error_report('%s' invalid media, value);
  goto fail;
 @@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
 BlockInterfaceType block_default_type)
  }
  
  /* copy-on-read is disabled with a warning for read-only devices */
 -read_only = qemu_opt_get_bool(legacy_opts, read-only, false);
 +read_only = qemu_opt_get_bool(legacy_opts, read-only, read_only);

I believe we must move this line to above the media=... handling for
compatibility with old versions. Or actually, using |= instead of = may
be enough.

The reason is this command line:

-drive file=test.iso,media=cdrom,readonly=off

Which, obviously, means that a read-only CD-ROM device should be
created.

Kevin



Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Michael S. Tsirkin
On Tue, Oct 15, 2013 at 11:05:48AM +0200, Igor Mammedov wrote:
 On Tue, 15 Oct 2013 10:01:01 +0200
 Gerd Hoffmann kra...@redhat.com wrote:
 
Hi,
  
   Yes but at the cost of overspecifying it.
   I think it's down to the name: it's called pcimem64-start
   but it can actually be less than 4G and we need to worry what to
   do then. Also, 64 doesn't really mean 4G.
   
   So how about reserve-memory-over-4g?
   bios then does 1ull  32 + reserve-memory-over-4g
   to figure out how much to skip.
  
  We are reaching the point where it becomes pointless bikeshedding ...
  
  I want a interface which is clearly defined and which doesn't break if
  the way we use the address space above 4g changes (hotplug,
  non-contignous memory, whatever).  So make it depend on the memory
  deployed isn't a clever idea.
  
  So at the end of the day it comes down to specify an address, either
  relative to 4g (your reserve-memory-over-4g suggestion) or relative to
  zero (Igors pcimem64-start patch).  Both will do the job.  In both cases
  the bios has to check it has no conflicts with known ram regions (i.e.
  compare against 132 + RamSizeAbove4G).
  
  I personally don't see the point in having the address relative to 4g
  and prefer the pcimem64-start approach.  We could rename it to
  pcimem64-minimum-address to make more clear this is about keeping some
  space free rather than specifyng a fixed address where the 64bit pci
  bars should be mapped to.  But at the end of the day I don't care too
  much, how we are going to name the baby is just a matter of taste and
  not really critical for the interface ...
 Michael,
 
 My preference is the same as Gerd's.
 Though if you NACK this approach, I'm fine with relative to 4g approach
 as you suggest, the only change I'd like to see in naming is memory
 reservation to be replaced with pcimem64, i.e. something like:
  pcimem64-4gb-offset
 to reflect value we are actually passing in.

I'm not going to nack.

  
  What is the state of the qemu side patches btw?
 I've them ready but they conflict with you 1Tb in e820 RFC,
 I can post relevant patches as soon as we agree on this topic.
 May I pick up your patch and post it along with pcimem64-start patches?

So for qemu we really need to merge them together with
memory hotplug I think.  It's not a big patch correct?
If it's small there's no need to merge just this interface
first, let's merge it all together.

  
  cheers,
Gerd
  
  
  



Re: [Qemu-devel] [SeaBIOS] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Gerd Hoffmann
  Hi,

  What is the state of the qemu side patches btw?
 I've them ready but they conflict with you 1Tb in e820 RFC,
 I can post relevant patches as soon as we agree on this topic.
 May I pick up your patch and post it along with pcimem64-start patches?

Yes, makes sense it just pick it into the series.

cheers,
  Gerd






Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Gerd Hoffmann
  Hi,

   What is the state of the qemu side patches btw?
  I've them ready but they conflict with you 1Tb in e820 RFC,
  I can post relevant patches as soon as we agree on this topic.
  May I pick up your patch and post it along with pcimem64-start patches?
 
 So for qemu we really need to merge them together with
 memory hotplug I think.

I'd prefer to not delay them until the full memory hotplug is ready to
go though, for release planning reasons.

Once the pcimem64-$whatever patch is in (+apci-from-qemu) no additional
support is needed in seabios to handle memory hotplug, correct?

So we can go prepare a seabios release when the interfaces are settled
and merged, and continuing the work on memory hotplug can happen in
parallel.

cheers,
  Gerd






Re: [Qemu-devel] [PATCH] blockdev: fix cdrom read_only flag

2013-10-15 Thread Fam Zheng
On Tue, 10/15 11:13, Kevin Wolf wrote:
 Am 15.10.2013 um 03:27 hat Fam Zheng geschrieben:
  Since 0ebd24e0, cdrom doesn't have read-only on by default, which will
  error out when using an read only image. Fix it by setting the default
  value when parsing opts.
  
  Reported-by: Edivaldo de Araujo Pereira edivaldoapere...@yahoo.com.br
  Signed-off-by: Fam Zheng f...@redhat.com
  ---
   blockdev.c | 7 ---
   1 file changed, 4 insertions(+), 3 deletions(-)
  
  diff --git a/blockdev.c b/blockdev.c
  index 4f76e28..7f5ef4a 100644
  --- a/blockdev.c
  +++ b/blockdev.c
  @@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
  BlockInterfaceType block_default_type)
   int cyls, heads, secs, translation;
   int max_devs, bus_id, unit_id, index;
   const char *devaddr;
  -bool read_only, copy_on_read;
  +bool read_only = false;
  +bool copy_on_read;
   Error *local_err = NULL;
   
   /* Change legacy command line options into QMP ones */
  @@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
  BlockInterfaceType block_default_type)
   media = MEDIA_DISK;
   } else if (!strcmp(value, cdrom)) {
   media = MEDIA_CDROM;
  -qdict_put(bs_opts, read-only, qstring_from_str(on));
  +read_only = true;
   } else {
   error_report('%s' invalid media, value);
   goto fail;
  @@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
  BlockInterfaceType block_default_type)
   }
   
   /* copy-on-read is disabled with a warning for read-only devices */
  -read_only = qemu_opt_get_bool(legacy_opts, read-only, false);
  +read_only = qemu_opt_get_bool(legacy_opts, read-only, read_only);
 
 I believe we must move this line to above the media=... handling for
 compatibility with old versions. Or actually, using |= instead of = may
 be enough.
 
 The reason is this command line:
 
 -drive file=test.iso,media=cdrom,readonly=off
 
 Which, obviously, means that a read-only CD-ROM device should be
 created.
 

Oh, I didn't notice readony=off means a read-only CD-ROM before...

Fam



Re: [Qemu-devel] [PATCH] hmp: Add '\n' in monitor_printf()

2013-10-15 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 15.10.2013 um 05:38 hat mike geschrieben:
 On 10/14/2013 10:36 PM, Markus Armbruster wrote:
 Mike Qiu qiud...@linux.vnet.ibm.com writes:
 
 Without this, output of 'info block'
 
 scsi0-hd0: /images/f18-ppc64.qcow2 (qcow2)
   [not inserted]
 scsi0-cd2: [not inserted]
  Removable device: not locked, tray closed
 
 floppy0: [not inserted]
  Removable device: not locked, tray closed
 
 sd0: [not inserted]
  Removable device: not locked, tray closed
 
 There will be no additional lines between scsi0-hd0 scsi0-cd2,
 and break the info style.
 Just saw a similar one:
 
  (qemu) info block
  disk0: test.img (raw)
   [not inserted]
  cd: [not inserted]
  Removable device: not locked, tray closed
 
  foo: tmp.img (raw)
  Removable device: not locked, tray closed
   [not inserted](qemu)
 
 This patch is to solve this.
 
 Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
 ---
   hmp.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/hmp.c b/hmp.c
 index 5891507..2d2e5f8 100644
 --- a/hmp.c
 +++ b/hmp.c
 @@ -367,7 +367,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
   info-value-inserted-iops_wr_max,
   info-value-inserted-iops_size);
   } else {
 -monitor_printf(mon,  [not inserted]);
 +monitor_printf(mon,  [not inserted]\n);
   }
   if (verbose) {
 monitor_printf(mon, \nImages:\n);
 
 What about removing the newline before Images?
 A good idea I think, it no need to add addition lines in one info.

 But see commit id: fbe2e26c15af35e4d157874dc80f6a19eebaa83b
 [...]
 It was changed to add this, so there maybe some reasons I think,

 Like everything else in that commit, I did that change because I found it
 more readable.

 The problem seems to be commit 3e9fab69 ('block: Add support for
 throttling burst max in QMP and the command line'), which added a bogus
 [not inserted] message. We simply need to drop it altogether instead of
 adding a newline.

  I think we should also drop this newline:
 
   if (info-value-removable) {
   monitor_printf(mon, Removable device: %slocked, tray 
  %s\n,
  info-value-locked ?  : not ,
  info-value-tray_open ? open : closed);
   }

 Why? Look:

 (qemu) info block
 scsi0-cd0: /tmp/cdrom.qcow2 (qcow2)
 Removable device: not locked, tray closed
 Backing file: 
 /home/kwolf/images/iso/Fedora-18-x86_64-Live-Desktop.iso (chain depth: 1)
 I/O throttling:   bps=1048576 bps_rd=0 bps_wr=0 bps_max=104857 
 bps_rd_max=0 bps_wr_max=0 iops=0 iops_rd=0 iops_wr=0 iops_max=0 iops_rd_max=0 
 iops_wr_max=0 iops_size=0

 Do you really want to remove the newline?

This one made me think I do:

foo: tmp.img (raw)
Removable device: not locked, tray closed
 [not inserted](qemu) 

If the '[not inserted]' is wrong and needs to go, then I actually don't.



[Qemu-devel] [PATCH v2] blockdev: fix cdrom read_only flag

2013-10-15 Thread Fam Zheng
Since 0ebd24e0, cdrom doesn't have read-only on by default, which will
error out when using an read only image. Fix it by setting the default
value when parsing opts.

Reported-by: Edivaldo de Araujo Pereira edivaldoapere...@yahoo.com.br
Signed-off-by: Fam Zheng f...@redhat.com

---
v2: fix backward compatibility by force read-only with cdrom. (Kevin)

Signed-off-by: Fam Zheng f...@redhat.com
---
 blockdev.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 4f76e28..b260477 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
BlockInterfaceType block_default_type)
 int cyls, heads, secs, translation;
 int max_devs, bus_id, unit_id, index;
 const char *devaddr;
-bool read_only, copy_on_read;
+bool read_only = false;
+bool copy_on_read;
 Error *local_err = NULL;
 
 /* Change legacy command line options into QMP ones */
@@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
BlockInterfaceType block_default_type)
 media = MEDIA_DISK;
 } else if (!strcmp(value, cdrom)) {
 media = MEDIA_CDROM;
-qdict_put(bs_opts, read-only, qstring_from_str(on));
+read_only = true;
 } else {
 error_report('%s' invalid media, value);
 goto fail;
@@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
BlockInterfaceType block_default_type)
 }
 
 /* copy-on-read is disabled with a warning for read-only devices */
-read_only = qemu_opt_get_bool(legacy_opts, read-only, false);
+read_only |= qemu_opt_get_bool(legacy_opts, read-only, false);
 copy_on_read = qemu_opt_get_bool(legacy_opts, copy-on-read, false);
 
 if (read_only  copy_on_read) {
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Igor Mammedov
On Tue, 15 Oct 2013 12:16:43 +0300
Michael S. Tsirkin m...@redhat.com wrote:

 On Tue, Oct 15, 2013 at 11:05:48AM +0200, Igor Mammedov wrote:
  On Tue, 15 Oct 2013 10:01:01 +0200
  Gerd Hoffmann kra...@redhat.com wrote:
  
 Hi,
   
Yes but at the cost of overspecifying it.
I think it's down to the name: it's called pcimem64-start
but it can actually be less than 4G and we need to worry what to
do then. Also, 64 doesn't really mean 4G.

So how about reserve-memory-over-4g?
bios then does 1ull  32 + reserve-memory-over-4g
to figure out how much to skip.
   
   We are reaching the point where it becomes pointless bikeshedding ...
   
   I want a interface which is clearly defined and which doesn't break if
   the way we use the address space above 4g changes (hotplug,
   non-contignous memory, whatever).  So make it depend on the memory
   deployed isn't a clever idea.
   
   So at the end of the day it comes down to specify an address, either
   relative to 4g (your reserve-memory-over-4g suggestion) or relative to
   zero (Igors pcimem64-start patch).  Both will do the job.  In both cases
   the bios has to check it has no conflicts with known ram regions (i.e.
   compare against 132 + RamSizeAbove4G).
   
   I personally don't see the point in having the address relative to 4g
   and prefer the pcimem64-start approach.  We could rename it to
   pcimem64-minimum-address to make more clear this is about keeping some
   space free rather than specifyng a fixed address where the 64bit pci
   bars should be mapped to.  But at the end of the day I don't care too
   much, how we are going to name the baby is just a matter of taste and
   not really critical for the interface ...
  Michael,
  
  My preference is the same as Gerd's.
  Though if you NACK this approach, I'm fine with relative to 4g approach
  as you suggest, the only change I'd like to see in naming is memory
  reservation to be replaced with pcimem64, i.e. something like:
   pcimem64-4gb-offset
  to reflect value we are actually passing in.
 
 I'm not going to nack.
Ok, then I'll repost with suggested pcimem64-minimum-address but no other
changes.

 
   
   What is the state of the qemu side patches btw?
  I've them ready but they conflict with you 1Tb in e820 RFC,
  I can post relevant patches as soon as we agree on this topic.
  May I pick up your patch and post it along with pcimem64-start patches?
 
 So for qemu we really need to merge them together with
 memory hotplug I think.  It's not a big patch correct?
 If it's small there's no need to merge just this interface
 first, let's merge it all together.
It's quite independent from memhotplug so I'll just cherry-pick ~3-4 patches
and post them.

   
   cheers,
 Gerd
   
   
   
 




Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Anup Patel
On Tue, Oct 15, 2013 at 2:06 PM, Andrew Jones drjo...@redhat.com wrote:
 On Tue, Oct 15, 2013 at 12:26:10PM +0530, Anup Patel wrote:
 Hi Andrew,

 On Mon, Oct 14, 2013 at 9:29 PM, Andrew Jones drjo...@redhat.com wrote:
  This is a virtio version of hw/misc/debugexit and should evolve into a
  virtio version of pc-testdev. pc-testdev uses the PC's ISA bus, whereas
  this testdev can be plugged into a virtio-mmio transport, which is
  needed for kvm-unit-tests/arm. virtio-testdev uses the virtio device
  config space as a communication channel, and implements an RTAS-like
  protocol through it allowing guests to execute commands. Only three
  commands are currently implemented;
  1) VERSION: for version compatibility checks
  2) CLEAR:   set all the config space back to zero
  3) EXIT:exit() from qemu with a status code

 How about adding RESET command to reset the VM?


 Hi Anup,

 I'm not opposed to it, but at the moment I'm not sure how we would
 utilize it within kvm-unit-tests. Maybe it would be useful for another
 application though? So maybe we can add it as an add-on patch at the
 time we come up with its use case?

I suggested it because we have machvirt machine in QEMU for
KVM ARM/ARM64 which has only VirtIO devices. In machvirt, we
don't have mechanism to reset the system because none of the
VirtIO devices have such a mechanism. Now since you are introducing
a testdev, we can have a RESET command in VirtIO and implement
VirtIO REBOOT driver in Linux kernel to use it.

Currently, due to no RESET support in machvirt we are not able
to reboot Guest Linux from Guest console.


 Thanks for the review!

 drew

Thanks,
Anup



Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Anup Patel
On Tue, Oct 15, 2013 at 3:17 PM, Anup Patel a...@brainfault.org wrote:
 On Tue, Oct 15, 2013 at 2:06 PM, Andrew Jones drjo...@redhat.com wrote:
 On Tue, Oct 15, 2013 at 12:26:10PM +0530, Anup Patel wrote:
 Hi Andrew,

 On Mon, Oct 14, 2013 at 9:29 PM, Andrew Jones drjo...@redhat.com wrote:
  This is a virtio version of hw/misc/debugexit and should evolve into a
  virtio version of pc-testdev. pc-testdev uses the PC's ISA bus, whereas
  this testdev can be plugged into a virtio-mmio transport, which is
  needed for kvm-unit-tests/arm. virtio-testdev uses the virtio device
  config space as a communication channel, and implements an RTAS-like
  protocol through it allowing guests to execute commands. Only three
  commands are currently implemented;
  1) VERSION: for version compatibility checks
  2) CLEAR:   set all the config space back to zero
  3) EXIT:exit() from qemu with a status code

 How about adding RESET command to reset the VM?


 Hi Anup,

 I'm not opposed to it, but at the moment I'm not sure how we would
 utilize it within kvm-unit-tests. Maybe it would be useful for another
 application though? So maybe we can add it as an add-on patch at the
 time we come up with its use case?

 I suggested it because we have machvirt machine in QEMU for
 KVM ARM/ARM64 which has only VirtIO devices. In machvirt, we
 don't have mechanism to reset the system because none of the
 VirtIO devices have such a mechanism. Now since you are introducing
 a testdev, we can have a RESET command in VirtIO and implement
 VirtIO REBOOT driver in Linux kernel to use it.

 Currently, due to no RESET support in machvirt we are not able
 to reboot Guest Linux from Guest console.

The RESET support will not fit here only if testdev is supposed to be
used for kvm-unit-tests only.

Anyways, its just a suggestion.



 Thanks for the review!

 drew

 Thanks,
 Anup

Regards,
Anup



Re: [Qemu-devel] [PATCH v2] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Igor Mammedov
On Tue, 15 Oct 2013 11:24:19 +0200
Gerd Hoffmann kra...@redhat.com wrote:

   Hi,
 
What is the state of the qemu side patches btw?
   I've them ready but they conflict with you 1Tb in e820 RFC,
   I can post relevant patches as soon as we agree on this topic.
   May I pick up your patch and post it along with pcimem64-start patches?
  
  So for qemu we really need to merge them together with
  memory hotplug I think.
 
 I'd prefer to not delay them until the full memory hotplug is ready to
 go though, for release planning reasons.
 
 Once the pcimem64-$whatever patch is in (+apci-from-qemu) no additional
 support is needed in seabios to handle memory hotplug, correct?
almost,
according our latest discussions it will make SMBIOS reflect incorrect
memory devices info after reboot, but that could go before mem hotplug or even
as follow up to make SMBIOS work with non-contiguous memory ranges.

 
 So we can go prepare a seabios release when the interfaces are settled
 and merged, and continuing the work on memory hotplug can happen in
 parallel.
true, and that will make resulting memhotplug series smaller.

 cheers,
   Gerd
 
 
 




[Qemu-devel] qemu 1.7 seabios -- release planning

2013-10-15 Thread Gerd Hoffmann
  Hi,

It's probably going to be a bit tough this time.  We are pretty late in
the qemu 1.7 devel cycle, soft freeze today, and a big chunk of code
(ahci-tables-from qemu) which needs seabios support[1] is just about to
be pulled.

That leaves only two weeks (with kvm forum in the middle!) until qemu
1.7 hard freeze with -rc0 (2013-10-29), which should ideally have a
seabios update so it can be tested in the rc phase.

There are two more interface updates (pass pcimem64-start address + e820
entries for ram regions) which would be good to get in while being at
it.

seabios patches are ready for the most part and just waiting for the
qemu counterparts to be merged first.

The timing constrains suggest we should tightly align the releases, with
seabios releases being a bit earlier, i.e. something like this:

  (1) merge pending qemu patches
  (2) merge pending seabios patches
  (3) tag -rc0 seabios release [asap, no later than 2013-10-28]
  (4) merge seabios update into qemu
  (5) qemu hard freeze, -rc0 release with seabios update [2013-10-29]
  (6) seabios freeze in parallel with qemu hard freeze
  (7) apply seabios fixes if needed.
  (8) tag final seabios release [targeting qemu -rc2 or -rc3 date here]
  (9) merge seabios bugfix update into qemu

Qemu 1.7 schedule is here: http://wiki.qemu.org/Planning/1.7

Comments?

cheers,
  Gerd

[1] Strictly speaking it isn't absolutely required, but would be very
good to have.





Re: [Qemu-devel] [PATCH] hmp: Add '\n' in monitor_printf()

2013-10-15 Thread mike

On 10/15/2013 04:58 PM, Kevin Wolf wrote:

Am 15.10.2013 um 05:38 hat mike geschrieben:

On 10/14/2013 10:36 PM, Markus Armbruster wrote:

Mike Qiu qiud...@linux.vnet.ibm.com writes:


Without this, output of 'info block'

scsi0-hd0: /images/f18-ppc64.qcow2 (qcow2)
  [not inserted]
scsi0-cd2: [not inserted]
 Removable device: not locked, tray closed

floppy0: [not inserted]
 Removable device: not locked, tray closed

sd0: [not inserted]
 Removable device: not locked, tray closed

There will be no additional lines between scsi0-hd0 scsi0-cd2,
and break the info style.

Just saw a similar one:

 (qemu) info block
 disk0: test.img (raw)
  [not inserted]
 cd: [not inserted]
 Removable device: not locked, tray closed

 foo: tmp.img (raw)
 Removable device: not locked, tray closed
  [not inserted](qemu)


This patch is to solve this.

Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
---
  hmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hmp.c b/hmp.c
index 5891507..2d2e5f8 100644
--- a/hmp.c
+++ b/hmp.c
@@ -367,7 +367,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
  info-value-inserted-iops_wr_max,
  info-value-inserted-iops_size);
  } else {
-monitor_printf(mon,  [not inserted]);
+monitor_printf(mon,  [not inserted]\n);
  }
  if (verbose) {

monitor_printf(mon, \nImages:\n);

What about removing the newline before Images?

A good idea I think, it no need to add addition lines in one info.

But see commit id: fbe2e26c15af35e4d157874dc80f6a19eebaa83b
[...]
It was changed to add this, so there maybe some reasons I think,

Like everything else in that commit, I did that change because I found it
more readable.

The problem seems to be commit 3e9fab69 ('block: Add support for
throttling burst max in QMP and the command line'), which added a bogus
[not inserted] message. We simply need to drop it altogether instead of
adding a newline.


Yes, I agree with you. but maybe need the author of the commit 3e9fab69
('block: Add support for throttling burst max in QMP and the command line')
to have some comments on this line, I think.

I think we should also drop this newline:

  if (info-value-removable) {
  monitor_printf(mon, Removable device: %slocked, tray %s\n,
 info-value-locked ?  : not ,
 info-value-tray_open ? open : closed);
  }

Why? Look:

(qemu) info block
scsi0-cd0: /tmp/cdrom.qcow2 (qcow2)
 Removable device: not locked, tray closed
 Backing file: /home/kwolf/images/iso/Fedora-18-x86_64-Live-Desktop.iso 
(chain depth: 1)
 I/O throttling:   bps=1048576 bps_rd=0 bps_wr=0 bps_max=104857 
bps_rd_max=0 bps_wr_max=0 iops=0 iops_rd=0 iops_wr=0 iops_max=0 iops_rd_max=0 
iops_wr_max=0 iops_size=0

Do you really want to remove the newline?

I'm not, but Markus suggest to do so.

Thanks
Mike

Kevin








Re: [Qemu-devel] [PATCH] hmp: Add '\n' in monitor_printf()

2013-10-15 Thread mike

On 10/15/2013 05:31 PM, Markus Armbruster wrote:

Kevin Wolf kw...@redhat.com writes:


Am 15.10.2013 um 05:38 hat mike geschrieben:

On 10/14/2013 10:36 PM, Markus Armbruster wrote:

Mike Qiu qiud...@linux.vnet.ibm.com writes:


Without this, output of 'info block'

scsi0-hd0: /images/f18-ppc64.qcow2 (qcow2)
  [not inserted]
scsi0-cd2: [not inserted]
 Removable device: not locked, tray closed

floppy0: [not inserted]
 Removable device: not locked, tray closed

sd0: [not inserted]
 Removable device: not locked, tray closed

There will be no additional lines between scsi0-hd0 scsi0-cd2,
and break the info style.

Just saw a similar one:

 (qemu) info block
 disk0: test.img (raw)
  [not inserted]
 cd: [not inserted]
 Removable device: not locked, tray closed

 foo: tmp.img (raw)
 Removable device: not locked, tray closed
  [not inserted](qemu)


This patch is to solve this.

Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
---
  hmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hmp.c b/hmp.c
index 5891507..2d2e5f8 100644
--- a/hmp.c
+++ b/hmp.c
@@ -367,7 +367,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
  info-value-inserted-iops_wr_max,
  info-value-inserted-iops_size);
  } else {
-monitor_printf(mon,  [not inserted]);
+monitor_printf(mon,  [not inserted]\n);
  }
  if (verbose) {

monitor_printf(mon, \nImages:\n);

What about removing the newline before Images?

A good idea I think, it no need to add addition lines in one info.

But see commit id: fbe2e26c15af35e4d157874dc80f6a19eebaa83b
[...]
It was changed to add this, so there maybe some reasons I think,

Like everything else in that commit, I did that change because I found it
more readable.

The problem seems to be commit 3e9fab69 ('block: Add support for
throttling burst max in QMP and the command line'), which added a bogus
[not inserted] message. We simply need to drop it altogether instead of
adding a newline.


I think we should also drop this newline:

  if (info-value-removable) {
  monitor_printf(mon, Removable device: %slocked, tray %s\n,
 info-value-locked ?  : not ,
 info-value-tray_open ? open : closed);
  }

Why? Look:

(qemu) info block
scsi0-cd0: /tmp/cdrom.qcow2 (qcow2)
 Removable device: not locked, tray closed
 Backing file: /home/kwolf/images/iso/Fedora-18-x86_64-Live-Desktop.iso 
(chain depth: 1)
 I/O throttling:   bps=1048576 bps_rd=0 bps_wr=0 bps_max=104857 
bps_rd_max=0 bps_wr_max=0 iops=0 iops_rd=0 iops_wr=0 iops_max=0 iops_rd_max=0 
iops_wr_max=0 iops_size=0

Do you really want to remove the newline?

This one made me think I do:

 foo: tmp.img (raw)
 Removable device: not locked, tray closed
  [not inserted](qemu)

If the '[not inserted]' is wrong and needs to go, then I actually don't.
Here '[not inserted]' is very strange, if the commit author has some 
reasonable reasons,

we can keep it, otherwise, I think we should remove it.

Thanks
Mike








Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Peter Maydell
On 15 October 2013 10:47, Anup Patel a...@brainfault.org wrote:
 On Tue, Oct 15, 2013 at 2:06 PM, Andrew Jones drjo...@redhat.com wrote:
 I'm not opposed to it, but at the moment I'm not sure how we would
 utilize it within kvm-unit-tests. Maybe it would be useful for another
 application though? So maybe we can add it as an add-on patch at the
 time we come up with its use case?

 I suggested it because we have machvirt machine in QEMU for
 KVM ARM/ARM64 which has only VirtIO devices. In machvirt, we
 don't have mechanism to reset the system because none of the
 VirtIO devices have such a mechanism. Now since you are introducing
 a testdev, we can have a RESET command in VirtIO and implement
 VirtIO REBOOT driver in Linux kernel to use it.

 Currently, due to no RESET support in machvirt we are not able
 to reboot Guest Linux from Guest console.

We shouldn't be abusing a device intended for testing to
provide necessary features. If we need guest reboot support
(which seems like an obvious thing to want) then we need
to implement a sensible mechanism for it.

-- PMM



Re: [Qemu-devel] [PATCH v2] target-arm: Implement ARMv8 VSEL instruction.

2013-10-15 Thread Peter Maydell
On 3 October 2013 15:37, Peter Maydell peter.mayd...@linaro.org wrote:
 Ah, that means the ARM ARM table is incorrect, because it implies
 that VSEL is conditional (which it definitely isn't). I need to look
 at where the new insns are in the T32/A32 encodings in more
 detail, then, which I don't have time for just at the moment.

Yes, these are in what would be the CDP2 space in both T32
and A32. So, quick sketch of what I think we should do:
 * move the disas_vfp_insn() calls outside disas_coproc_insn()
   (and in the thumb decode case, to before the if bit 28 set
   then goto illegal_op check)
   (basically what you have in this patch is fine)
 * add a call to disas_vfp_insn() in the unconditional code
   (what you have there in this patch is fine, but remember that
   QEMU coding style mandates braces; use scripts/checkpatch.pl.)
 * in disas_vfp_insn(), just after the is vfp disabled? check, add:

 if (extract32(insn, 28, 4) == 0xf) {
/* Encodings with T=1 (Thumb) or unconditional (ARM):
 * only used in v8 and above
 */
return 1;
 }

That all goes into patch 1 of 2, which is just doing refactoring
and makes no changes in behaviour.

 * then in patch 2 of the series, actually add the VSEL
   support, by replacing that 'return 1' with
   'return disas_vfp_v8_insn(env, s, insn);'
   and implementing that function with the VSEL support.
   [It seems better to me to have this separate rather than
   fully integrated into the existing logic of disas_vfp_insn
   because we know that no new insn is ever going to use the
   legacy/deprecated vfp vector support. And the function is
   already 800 lines long...]

thanks
-- PMM



Re: [Qemu-devel] [RFC PATCH v2 6/6] hw: arm_gic_kvm: Add KVM VGIC save/restore logic

2013-10-15 Thread Peter Maydell
On 27 September 2013 09:11, Alex Bennée alex.ben...@linaro.org wrote:

 christoffer.d...@linaro.org writes:

 Save and restore the ARM KVM VGIC state from the kernel.  We rely on
 snip

  static const VMStateDescription vmstate_gic = {
  .name = arm_gic,
 -.version_id = 6,
 -.minimum_version_id = 6,
 +.version_id = 7,
 +.minimum_version_id = 7,
  .pre_save = gic_pre_save,
  .post_load = gic_post_load,
  .fields = (VMStateField[]) {

 Does this mean QEMU and Kernel need to be kept in lock-step for
 compatibility?

No. This patch is a little confusing because it's both adding
the new fields and also adding the save/restore support, but
once we have the data structures and vmstate in QEMU holding
all the state the kernel needs, there shouldn't be any need
to update the vmstate in a backwards-incompatible way.


 +//#define DEBUG_GIC_KVM
 +
 +#ifdef DEBUG_GIC_KVM
 +static const int debug_gic_kvm = 1;
 +#else
 +static const int debug_gic_kvm = 0;
 +#endif
 +
 +#define DPRINTF(fmt, ...) do { \
 +if (debug_gic_kvm) { \
 +printf(arm_gic:  fmt , ## __VA_ARGS__); \
 +} \
 +} while (0)
 +

 Shouldn't we be using QEMU logging framework for this? Also for the
 fprintfs later on.

No, these are debug printfs, not things which would be interesting
to the average user/person trying to debug a guest. We don't
have a particularly clean framework for compile time
enabled debug printfs, so 'some random macro in each individual
file' is the current approach.

-- PMM



Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Gleb Natapov
On Tue, Oct 15, 2013 at 11:14:12AM +0100, Peter Maydell wrote:
 On 15 October 2013 10:47, Anup Patel a...@brainfault.org wrote:
  On Tue, Oct 15, 2013 at 2:06 PM, Andrew Jones drjo...@redhat.com wrote:
  I'm not opposed to it, but at the moment I'm not sure how we would
  utilize it within kvm-unit-tests. Maybe it would be useful for another
  application though? So maybe we can add it as an add-on patch at the
  time we come up with its use case?
 
  I suggested it because we have machvirt machine in QEMU for
  KVM ARM/ARM64 which has only VirtIO devices. In machvirt, we
  don't have mechanism to reset the system because none of the
  VirtIO devices have such a mechanism. Now since you are introducing
  a testdev, we can have a RESET command in VirtIO and implement
  VirtIO REBOOT driver in Linux kernel to use it.
 
  Currently, due to no RESET support in machvirt we are not able
  to reboot Guest Linux from Guest console.
 
 We shouldn't be abusing a device intended for testing to
 provide necessary features. If we need guest reboot support
 (which seems like an obvious thing to want) then we need
 to implement a sensible mechanism for it.
 
Definitely. Test device is only for use by unit tests. It does not normally
present and may contain hacks not suitable for human consumption.

--
Gleb.



[Qemu-devel] [RFH] Qemu main thread is blocked in g_poll in windows guest

2013-10-15 Thread Xiexiangyou
Hi all:

Windows2008 Guest run without pressure for long time. Sometimes, it stop and 
looks like hanging. But when I connect to it with VNC, It resume to run, but 
VM's time is delayed . 
When the vm is hanging, I check the main thread of QEMU. I find that the thread 
is blocked in g_poll function. it is waiting for a SIG, However, there is no 
SIG .

I tried the clock with hpet and no hpet, but came out the same problem. 
Then I upgrade the glibc to newer, it didn't work too.
I'm confused. Is the reason that VM in sleep state and doesn't emit the signal. 
I set the windows 's power option, enable/disable the allow the wake 
timers, I didn't work.

Is anybody have met the same problem before, or know the reason. Your reply 
will be very helpful.

Thanks

--xiexiangyou



Re: [Qemu-devel] [PATCH] virtio: Introduce virtio-testdev

2013-10-15 Thread Anup Patel
On Tue, Oct 15, 2013 at 4:08 PM, Gleb Natapov g...@redhat.com wrote:
 On Tue, Oct 15, 2013 at 11:14:12AM +0100, Peter Maydell wrote:
 On 15 October 2013 10:47, Anup Patel a...@brainfault.org wrote:
  On Tue, Oct 15, 2013 at 2:06 PM, Andrew Jones drjo...@redhat.com wrote:
  I'm not opposed to it, but at the moment I'm not sure how we would
  utilize it within kvm-unit-tests. Maybe it would be useful for another
  application though? So maybe we can add it as an add-on patch at the
  time we come up with its use case?
 
  I suggested it because we have machvirt machine in QEMU for
  KVM ARM/ARM64 which has only VirtIO devices. In machvirt, we
  don't have mechanism to reset the system because none of the
  VirtIO devices have such a mechanism. Now since you are introducing
  a testdev, we can have a RESET command in VirtIO and implement
  VirtIO REBOOT driver in Linux kernel to use it.
 
  Currently, due to no RESET support in machvirt we are not able
  to reboot Guest Linux from Guest console.

 We shouldn't be abusing a device intended for testing to
 provide necessary features. If we need guest reboot support
 (which seems like an obvious thing to want) then we need
 to implement a sensible mechanism for it.

 Definitely. Test device is only for use by unit tests. It does not normally
 present and may contain hacks not suitable for human consumption.

Got it.


 --
 Gleb.

Thanks,
Anup



Re: [Qemu-devel] [PATCH v2] blockdev: fix cdrom read_only flag

2013-10-15 Thread Kevin Wolf
Am 15.10.2013 um 11:45 hat Fam Zheng geschrieben:
 Since 0ebd24e0, cdrom doesn't have read-only on by default, which will
 error out when using an read only image. Fix it by setting the default
 value when parsing opts.
 
 Reported-by: Edivaldo de Araujo Pereira edivaldoapere...@yahoo.com.br
 Signed-off-by: Fam Zheng f...@redhat.com
 
 ---
 v2: fix backward compatibility by force read-only with cdrom. (Kevin)
 
 Signed-off-by: Fam Zheng f...@redhat.com

Reviewed-by: Kevin Wolf kw...@redhat.com



[Qemu-devel] [PATCH] .travis.yml: basic compile and check recipes

2013-10-15 Thread alex . bennee
From: Alex Bennée a...@bennee.com

This adds a build matrix definition for travis-ci.org continuous
integration service. It is usable on any public repository hosted on
GitHub. Once you have created an account signed into Travis you can
enable it on selected projects via travis-ci.org/profile. Alternatively
you can configure the service hooks on GitHub via the repository
Settings tab,then Service Hooks and selecting Travis.

Once setup Travis will automatically test every push as well as any pull
requests submitted to that repository.

The build matrix is currently split by target architecture (see TARGETS
environment variable) because a full build of QEMU can take some time.
This way you get quick feedback for any obvious errors. The additional
environment variables exist to allow additional builds to tweak the
environment. These are:

EXTRA_CONFIG - extra terms passed to configure
EXTRA_PKGS - extra dev packages to install
TEST_CMD - default make check, can be overridden

I've confined the additional stuff to x86/x86_64 for convenience.

As Travis supports clang the main builds are done twice (once for gcc
and once for clang). However clang is disabled for the debug/trace
builds for the purposes of brevity.

Other wrinkles:

 * The lttng user-space tracing back-end is disabled
   (it is currently horribly broken)
 * The ftrace back-end doesn't run make check
   (it requires a mounted debugfs to work)
 * There are two debug enabled build (with and without TCG interpreter)

Signed-off-by: Alex Bennée a...@bennee.com
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com
---
 .travis.yml | 69 +
 1 file changed, 69 insertions(+)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000..15d36b1
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,69 @@
+language: c
+compiler:
+  - gcc
+  - clang
+env:
+  global:
+- TEST_CMD=make check
+- EXTRA_CONFIG=
+# Development packages, EXTRA_PKGS saved for additional builds
+- CORE_PKGS=libusb-1.0-0-dev libiscsi-dev librados-dev libncurses5-dev
+- NET_PKGS=libseccomp-dev libgnutls-dev libssh2-1-dev  
libspice-server-dev libspice-protocol-dev libnss3-dev
+- GUI_PKGS=libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev 
libpixman-1-dev
+- EXTRA_PKGS=
+  matrix:
+  - TARGETS=alpha-softmmu,alpha-linux-user
+  - TARGETS=arm-softmmu,arm-linux-user
+  - TARGETS=cris-softmmu
+  - TARGETS=i386-softmmu,x86_64-softmmu
+  - TARGETS=lm32-softmmu
+  - TARGETS=m68k-softmmu 
+  - TARGETS=microblaze-softmmu,microblazeel-softmmu
+  - TARGETS=mips-softmmu,mips64-softmmu,mips64el-softmmu,mipsel-softmmu
+  - TARGETS=moxie-softmmu
+  - TARGETS=or32-softmmu,
+  - TARGETS=ppc-softmmu,ppc64-softmmu,ppcemb-softmmu
+  - TARGETS=s390x-softmmu
+  - TARGETS=sh4-softmmu,sh4eb-softmmu
+  - TARGETS=sparc-softmmu,sparc64-softmmu
+  - TARGETS=unicore32-softmmu
+  - TARGETS=xtensa-softmmu,xtensaeb-softmmu
+before_install:
+  - git submodule update --init --recursive
+  - sudo apt-get update -qq
+  - sudo apt-get install -qq ${CORE_PKGS} ${NET_PKGS} ${GUI_PKGS} ${EXTRA_PKGS}
+script: ./configure --target-list=${TARGETS} ${EXTRA_CONFIG}  make  
${TEST_CMD}
+matrix:
+  # We manually include a number of additional build for non-standard bits
+  include:
+# Debug related options
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-debug
+  compiler: gcc
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-debug --enable-tcg-interpreter
+  compiler: gcc
+# Currently configure doesn't force --disable-pie
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-gprof --enable-gcov --disable-pie
+  compiler: gcc
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_PKGS=sparse
+   EXTRA_CONFIG=--enable-sparse
+  compiler: gcc
+# All the trace backends (apart from dtrace)
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-trace-backend=stderr
+  compiler: gcc
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-trace-backend=simple
+  compiler: gcc
+- env: TARGETS=i386-softmmu,x86_64-softmmu
+   EXTRA_CONFIG=--enable-trace-backend=ftrace
+   TEST_CMD=
+  compiler: gcc
+# This disabled make check for the ftrace backend which needs more setting 
up
+# Currently broken on 12.04 due to mis-packaged liburcu and changed API, 
will be pulled.
+#- env: TARGETS=i386-softmmu,x86_64-softmmu
+#   EXTRA_PKGS=liblttng-ust-dev liburcu-dev
+#   EXTRA_CONFIG=--enable-trace-backend=ust
-- 
1.8.4




[Qemu-devel] [PULL v5 0/0] .travis.yml: basic compile and check recipies

2013-10-15 Thread alex . bennee
Hi Anthony,

Here is my first pull request to add a simple .travis.yml profile to the
code base. I'm hoping to expand the range of testing once this is merged
(the tcg code gen tests are next on my list). However as it stands this
already catches build failures and regressions.

Since v4:
  - dropped SeaBIOS patch

Cheers,

Alex

The following changes since commit 1680d485777ecf436d724631ea8722cc0c66990e:

  Merge remote-tracking branch 'rth/tcg-ldst-6' into staging (2013-10-14 
09:59:59 -0700)

are available in the git repository at:


  http://github.com/stsquad/qemu.git travis-ci

for you to fetch changes up to 90878d2c083629a4ee99b2d03158838b35e218c3:

  .travis.yml: basic compile and check recipes (2013-10-15 10:00:10 +0100)


Alex Bennée (1):
  .travis.yml: basic compile and check recipes

 .travis.yml | 69 +
 1 file changed, 69 insertions(+)
 create mode 100644 .travis.yml




Re: [Qemu-devel] [PATCH] hmp: Add '\n' in monitor_printf()

2013-10-15 Thread Benoît Canet

Hello,

Le Tuesday 15 Oct 2013 à 18:07:16 (+0800), mike a écrit :
 On 10/15/2013 04:58 PM, Kevin Wolf wrote:
 Am 15.10.2013 um 05:38 hat mike geschrieben:
 On 10/14/2013 10:36 PM, Markus Armbruster wrote:
 Mike Qiu qiud...@linux.vnet.ibm.com writes:
 
 Without this, output of 'info block'
 
 scsi0-hd0: /images/f18-ppc64.qcow2 (qcow2)
   [not inserted]
 scsi0-cd2: [not inserted]
  Removable device: not locked, tray closed
 
 floppy0: [not inserted]
  Removable device: not locked, tray closed
 
 sd0: [not inserted]
  Removable device: not locked, tray closed
 
 There will be no additional lines between scsi0-hd0 scsi0-cd2,
 and break the info style.
 Just saw a similar one:
 
  (qemu) info block
  disk0: test.img (raw)
   [not inserted]
  cd: [not inserted]
  Removable device: not locked, tray closed
 
  foo: tmp.img (raw)
  Removable device: not locked, tray closed
   [not inserted](qemu)
 
 This patch is to solve this.
 
 Signed-off-by: Mike Qiu qiud...@linux.vnet.ibm.com
 ---
   hmp.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/hmp.c b/hmp.c
 index 5891507..2d2e5f8 100644
 --- a/hmp.c
 +++ b/hmp.c
 @@ -367,7 +367,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
   info-value-inserted-iops_wr_max,
   info-value-inserted-iops_size);
   } else {
 -monitor_printf(mon,  [not inserted]);
 +monitor_printf(mon,  [not inserted]\n);
   }
   if (verbose) {
 monitor_printf(mon, \nImages:\n);
 
 What about removing the newline before Images?
 A good idea I think, it no need to add addition lines in one info.
 
 But see commit id: fbe2e26c15af35e4d157874dc80f6a19eebaa83b
 [...]
 It was changed to add this, so there maybe some reasons I think,
 Like everything else in that commit, I did that change because I found it
 more readable.
 
 The problem seems to be commit 3e9fab69 ('block: Add support for
 throttling burst max in QMP and the command line'), which added a bogus
 [not inserted] message. We simply need to drop it altogether instead of
 adding a newline.
 
 Yes, I agree with you. but maybe need the author of the commit 3e9fab69
 ('block: Add support for throttling burst max in QMP and the command line')
 to have some comments on this line, I think.

Hello,

I do not remember even thinking about adding this monitor_printf in 3e9fab69.
It must be the result of a bad conflict resolve or something like that.
Sorry for adding this.
Do you want me to send a two liner to remove this ? 

Best regards

Benoît

 I think we should also drop this newline:
 
   if (info-value-removable) {
   monitor_printf(mon, Removable device: %slocked, tray 
  %s\n,
  info-value-locked ?  : not ,
  info-value-tray_open ? open : closed);
   }
 Why? Look:
 
 (qemu) info block
 scsi0-cd0: /tmp/cdrom.qcow2 (qcow2)
  Removable device: not locked, tray closed
  Backing file: 
  /home/kwolf/images/iso/Fedora-18-x86_64-Live-Desktop.iso (chain depth: 1)
  I/O throttling:   bps=1048576 bps_rd=0 bps_wr=0 bps_max=104857 
  bps_rd_max=0 bps_wr_max=0 iops=0 iops_rd=0 iops_wr=0 iops_max=0 
  iops_rd_max=0 iops_wr_max=0 iops_size=0
 
 Do you really want to remove the newline?
 I'm not, but Markus suggest to do so.
 
 Thanks
 Mike
 Kevin
 
 
 
 
 



Re: [Qemu-devel] [RFC PATCH v2 6/6] hw: arm_gic_kvm: Add KVM VGIC save/restore logic

2013-10-15 Thread Peter Maydell
On 26 September 2013 22:03, Christoffer Dall
christoffer.d...@linaro.org wrote:
 Save and restore the ARM KVM VGIC state from the kernel.  We rely on
 QEMU to marshal the GICState data structure and therefore simply
 synchronize the kernel state with the QEMU emulated state in both
 directions.

 We take some care on the restore path to check the VGIC has been
 configured with enough IRQs and CPU interfaces that we can properly
 restore the state, and for separate set/clear registers we first fully
 clear the registers and then set the required bits.

 Signed-off-by: Christoffer Dall christoffer.d...@linaro.org

 Changelog [v2]:
  - Remove num_irq from GIC VMstate structure
  - Increment GIC VMstate version number
  - Use extract32/deposit32 for bit-field modifications
  - Address other smaller review comments
  - Renames kvm_arm_gic_dist_[readr/writer] functions to
kvm_dist_[get/put] and shortened other function names
  - Use concrete format for APRn
 ---
  hw/intc/arm_gic_common.c |5 +-
  hw/intc/arm_gic_kvm.c|  424 
 +-
  hw/intc/gic_internal.h   |8 +
  3 files changed, 433 insertions(+), 4 deletions(-)

 diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c
 index 5449d77..1d3b738 100644
 --- a/hw/intc/arm_gic_common.c
 +++ b/hw/intc/arm_gic_common.c
 @@ -58,8 +58,8 @@ static const VMStateDescription vmstate_gic_irq_state = {

  static const VMStateDescription vmstate_gic = {
  .name = arm_gic,
 -.version_id = 6,
 -.minimum_version_id = 6,
 +.version_id = 7,
 +.minimum_version_id = 7,
  .pre_save = gic_pre_save,
  .post_load = gic_post_load,
  .fields = (VMStateField[]) {
 @@ -78,6 +78,7 @@ static const VMStateDescription vmstate_gic = {
  VMSTATE_UINT16_ARRAY(current_pending, GICState, NCPU),
  VMSTATE_UINT8_ARRAY(bpr, GICState, NCPU),
  VMSTATE_UINT8_ARRAY(abpr, GICState, NCPU),
 +VMSTATE_UINT32_2DARRAY(apr, GICState, 4, NCPU),

I feel like we should add this new apr state (plus some
documentation and at least the TCG read/write interface
to the state) in one patch and then put the save/load
in its own patch.

 +err = kvm_device_ioctl(s-dev_fd, type, attr);
 +if (err  0) {
 +fprintf(stderr, KVM_{SET/GET}_DEVICE_ATTR failed: %s\n,
 +strerror(-err));
 +abort();

Bad indent.

 +}
 +}
  static void kvm_arm_gic_put(GICState *s)
  {
 -/* TODO: there isn't currently a kernel interface to set the GIC state */
 +uint32_t reg;
 +int i;
 +int cpu;
 +int num_cpu;
 +int num_irq;
 +
 +if (!kvm_arm_gic_can_save_restore(s)) {
 +DPRINTF(Cannot put kernel gic state, no kernel interface);
 +return;
 +}
 +
 +/* Note: We do the restore in a slightly different order than the save
 + * (where the order doesn't matter and is simply ordered according to the
 + * register offset values */
 +
 +/*
 + * Distributor State
 + */
 +
 +/* s-enabled - GICD_CTLR */
 +reg = s-enabled;
 +kvm_gicd_access(s, 0x0, 0, reg, true);
 +
 +/* Sanity checking on GICD_TYPER and s-num_irq, s-num_cpu */
 +kvm_gicd_access(s, 0x4, 0, reg, false);
 +num_irq = ((reg  0x1f) + 1) * 32;
 +num_cpu = ((reg  0xe0)  5) + 1;
 +
 +if (num_irq  s-num_irq) {
 +fprintf(stderr, Restoring %u IRQs, but kernel supports max 
 %d\n,
 +s-num_irq, num_irq);
 +abort();
 +} else if (num_cpu != s-num_cpu ) {
 +fprintf(stderr, Restoring %u CPU interfaces, kernel only has 
 %d\n,
 +s-num_cpu, num_cpu);
 +/* Did we not create the VCPUs in the kernel yet? */
 +abort();
 +}
 +
 +/* TODO: Consider checking compatibility with the IIDR ? */
 +
 +/* irq_state[n].enabled - GICD_ISENABLERn */
 +kvm_dist_put(s, 0x180, 1, s-num_irq, translate_clear);
 +kvm_dist_put(s, 0x100, 1, s-num_irq, translate_enabled);
 +
 +/* s-irq_target[irq] - GICD_ITARGETSRn
 + * (restore targets before pending to ensure the pending state is set on
 + * the appropriate CPU interfaces in the kernel) */
 +kvm_dist_put(s, 0x800, 8, s-num_irq, translate_targets);
 +
 +/* irq_state[n].pending + irq_state[n].level - GICD_ISPENDRn */
 +kvm_dist_put(s, 0x280, 1, s-num_irq, translate_clear);
 +kvm_dist_put(s, 0x200, 1, s-num_irq, translate_pending);
 +
 +/* irq_state[n].active - GICD_ISACTIVERn */
 +kvm_dist_put(s, 0x380, 1, s-num_irq, translate_clear);
 +kvm_dist_put(s, 0x300, 1, s-num_irq, translate_active);
 +
 +/* irq_state[n].trigger - GICD_ICFRn */
 +kvm_dist_put(s, 0xc00, 2, s-num_irq, translate_trigger);
 +
 +/* s-priorityX[irq] - ICD_IPRIORITYRn */
 +kvm_dist_put(s, 0x400, 8, s-num_irq, translate_priority);
 +
 +/* s-sgi_source - ICD_CPENDSGIRn */
 +kvm_dist_put(s, 

Re: [Qemu-devel] [RFC PATCH v3 4/5] Update documentation for LTTng ust tracing

2013-10-15 Thread Alex Bennée

mohamad.ge...@gmail.com writes:

 Signed-off-by: Mohamad Gebai mohamad.ge...@polymtl.ca
 ---
  docs/tracing.txt |   31 +++
  1 file changed, 31 insertions(+)

 diff --git a/docs/tracing.txt b/docs/tracing.txt
 index bfc261b..64683db 100644
 --- a/docs/tracing.txt
 +++ b/docs/tracing.txt
 @@ -214,6 +214,37 @@ The ust backend uses the LTTng Userspace Tracer 
 library.  There are no
  monitor commands built into QEMU, instead UST utilities should be used to 
 list,
  enable/disable, and dump traces.
  
 +Package lttng-tools is required for userspace tracing. After running Qemu, 
 LTTng
 +should be able to list all available events:
 +
 +lttng list -u

Running this gives me:

quote
UST events:
-
None
/quote

Before or after running qemu. What is the mechanism lttng expects to
find out all these events?

 +
 +Create tracing session:
 +
 +lttng create mysession
 +
 +Enable events:
 +
 +lttng enable-event qemu:g_malloc -u
 +
 +Where the events can either be a comma-separated list of events, or -a to
 +enable all tracepoint events. Start and stop tracing as needed:
 +
 +lttng start
 +lttng stop
 +
 +View the trace:
 +
 +lttng view
 +
 +Destroy tracing session:
 +
 +lttng destroy
 +
 +Babeltrace can be used at any later time to view the trace:
 +
 +babeltrace $HOME/lttng-traces/mysession-date-time
 +

The rest of this looks OK and worked on my system.

  === SystemTap ===
  
  The dtrace backend uses DTrace sdt probes but has only been tested with


-- 
Alex Bennée



Re: [Qemu-devel] [PATCH 3/5] vmstate: Simplify field-skipping load/save logic

2013-10-15 Thread Paolo Bonzini
Il 14/10/2013 18:45, Eduardo Habkost ha scritto:
 +if (field-field_exists  !field-field_exists(opaque, version_id)) 
 {
 +continue;
 +}
 +if (field-version_id  version_id) {
 +continue;
 +}

What Markus observed...

I think the change is fine because we currently never have field_exists
and version_id set for the same field.

However, I suggest to move the change to a separate patch, and swap the
two ifs in this one.

Paolo



Re: [Qemu-devel] [RFC PATCH v2 0/3] Fix UST backend for LTTng 2.x

2013-10-15 Thread Stefan Hajnoczi
On Mon, Oct 14, 2013 at 01:05:14PM -0400, Mohamad Gebai wrote:
 Sorry for the delay, just submitted the updated documentation.

Great, thanks.  Things are busy here due to KVM Forum/LinuxCon Europe
next week.  I'll try to take a look this week though so we can merge
this.

Stefan



Re: [Qemu-devel] [RFH] Qemu main thread is blocked in g_poll in windows guest

2013-10-15 Thread Paolo Bonzini
Il 15/10/2013 12:21, Xiexiangyou ha scritto:
 Hi all:
 
 Windows2008 Guest run without pressure for long time. Sometimes, it
 stop and looks like hanging. But when I connect to it with VNC, It
 resume to run, but VM's time is delayed . When the vm is hanging, I
 check the main thread of QEMU. I find that the thread is blocked in
 g_poll function. it is waiting for a SIG, However, there is no SIG .
 
 I tried the clock with hpet and no hpet, but came out the same
 problem. Then I upgrade the glibc to newer, it didn't work too. I'm
 confused. Is the reason that VM in sleep state and doesn't emit the
 signal. I set the windows 's power option, enable/disable the
 allow the wake timers, I didn't work.
 
 Is anybody have met the same problem before, or know the reason. Your
 reply will be very helpful.

This post is missing a few pieces of information:

* What version of QEMU is this?

* What is the command line?

* How do you know g_poll is waiting for a signal and not for a file
descriptor?

* What is the backtrace of the main thread?  What is the backtrace of
the VCPU thread?

etc.

Paolo



Re: [Qemu-devel] [PULL 00/43] pci, pc, acpi fixes, enhancements

2013-10-15 Thread Igor Mammedov
On Mon, 14 Oct 2013 15:42:37 -0700
Anthony Liguori anth...@codemonkey.ws wrote:

 Michael S. Tsirkin m...@redhat.com writes:
 
  Anthony, I know you wanted to review some of the patches,
  since you didn't respond either all's well or you
  could not find the time.
  I think we are better off merging them for 1.7 and then - worst case,
  if major issues surface - disabling the functionality at the last minute
  than delaying the merge even more.
 
 There is no way I'll pull this for 1.7.  Changes like this aren't going
 to get merged at the last minute.  A good chunk of the series lacks
 any Reviewed-bys including the actual hotplug behind a pci bridge bits
 which is the whole point of the series.

 This is a huge series and I still am not convinced this is the right
 path forward.  The alternative to this series is a small set of changes
 to SeaBIOS to support PCI bridge hotplug, no?
It's also needed for memory hotplug to make any progress, there is no point
posting it before ACPI tables are merged.
  
 Or 10k SLOC of code into QEMU that includes breaking migration
 compatibility.
 
 Regards,
 
 Anthony Liguori
 
  The following changes since commit e26d3e734650640fabd7d95ace4f3a6f88725e0b:
 
smbios: Factor out smbios_maybe_add_str() (2013-09-28 23:49:39 +0300)
 
  are available in the git repository at:
 
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_anthony
 
  for you to fetch changes up to 6cab1e721fa6a487f67e1dba986f68fee30d:
 
acpi-build: enable hotplug for PCI bridges (2013-10-14 17:48:58 +0300)
 
  
  pci, pc, acpi fixes, enhancements
 
  This includes some pretty big changes:
  - pci master abort support by Marcel
  - pci IRQ API rework by Marcel
  - acpi generation and pci bridge hotplug support by myself
 
  Everything has gone through several revisions, latest versions have been on
  list for a while without any more comments, tested by several
  people.
 
  Please pull for 1.7.
 
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
 
  
  Igor Mammedov (1):
cleanup object.h: include error.h directly
 
  Marcel Apfelbaum (11):
memory: Change MemoryRegion priorities from unsigned to signed
docs/memory: Explictly state that MemoryRegion priority is signed
hw/pci: partially handle pci master abort
hw/core: Add interface to allocate and free a single IRQ
hw/pci: add pci wrappers for allocating and asserting irqs
hw/pci-bridge: set PCI_INTERRUPT_PIN register before shpc init
hw/vmxnet3: set interrupts using pci irq wrappers
hw/vfio: set interrupts using pci irq wrappers
hw: set interrupts using pci irq wrappers
hw/pcie: AER and hot-plug events must use device's interrupt
hw/pci: removed irq field from PCIDevice
 
  Michael S. Tsirkin (31):
qom: cleanup struct Error references
qom: add pointer to int property helpers
pci: fix up w64 size calculation helper
fw_cfg: interface to trigger callback on read
loader: support for unmapped ROM blobs
pcie_host: expose UNMAPPED macro
pcie_host: expose address format
q35: use macro for MCFG property name
q35: expose mmcfg size as a property
i386: add ACPI table files from seabios
acpi: add rules to compile ASL source
acpi: pre-compiled ASL files
acpi: ssdt pcihp: updat generated file
loader: use file path size from fw_cfg.h
i386: add bios linker/loader
loader: allow adding ROMs in done callbacks
i386: define pc guest info
acpi/piix: add macros for acpi property names
piix: APIs for pc guest info
ich9: APIs for pc guest info
pvpanic: add API to access io port
hpet: add API to find it
acpi: add interface to access user-installed tables
pc: use new api to add builtin tables
i386: ACPI table generation code from seabios
ssdt: fix PBLK length
ssdt-proc: update generated file
pci: add pci_for_each_bus_depth_first
pcihp: generalization of piix4 acpi
piix4: add acpi pci hotplug support
acpi-build: enable hotplug for PCI bridges
 
   configure   |9 +-
   hw/i386/acpi-build.h|9 +
   hw/i386/acpi-defs.h |  331 ++
   hw/i386/bios-linker-loader.h|   27 +
   hw/lm32/lm32_hwsetup.h  |2 +-
   include/exec/memory.h   |4 +-
   include/hw/acpi/acpi.h  |4 +
   include/hw/acpi/ich9.h  |2 +
   include/hw/acpi/pcihp.h |   72 +
   include/hw/acpi/piix4.h |8 +
   include/hw/i386/ich9.h  |2 +
   include/hw/i386/pc.h|   27 +
   include/hw/irq.h|7 +
   include/hw/loader.h   

Re: [Qemu-devel] [PATCH 3/5] vmstate: Simplify field-skipping load/save logic

2013-10-15 Thread Eduardo Habkost
On Tue, Oct 15, 2013 at 10:01:12AM +0200, Markus Armbruster wrote:
 Eduardo Habkost ehabk...@redhat.com writes:
 
  This makes the code more readable, making each condition that makes a
  field be skipped much more visible, and reduces one level of indentation
  in the code.
 
  Signed-off-by: Eduardo Habkost ehabk...@redhat.com
  ---
   savevm.c | 156 
  ---
   1 file changed, 80 insertions(+), 76 deletions(-)
 
  diff --git a/savevm.c b/savevm.c
  index 9562669..16276e7 100644
  --- a/savevm.c
  +++ b/savevm.c
  @@ -1694,50 +1694,52 @@ int vmstate_load_state(QEMUFile *f, const 
  VMStateDescription *vmsd,
   return ret;
   }
   for (field = vmsd-fields; field-name; field++) {
  -if ((field-field_exists 
  - field-field_exists(opaque, version_id)) ||
  -(!field-field_exists 
  - field-version_id = version_id)) {
  -void *base_addr = opaque + field-offset;
  -int i, n_elems = 1;
  -int size = field-size;
  -
  -if (field-flags  VMS_VBUFFER) {
  -size = *(int32_t *)(opaque+field-size_offset);
  -if (field-flags  VMS_MULTIPLY) {
  -size *= field-size;
  -}
  -}
  -if (field-flags  VMS_ARRAY) {
  -n_elems = field-num;
  -} else if (field-flags  VMS_VARRAY_INT32) {
  -n_elems = *(int32_t *)(opaque+field-num_offset);
  -} else if (field-flags  VMS_VARRAY_UINT32) {
  -n_elems = *(uint32_t *)(opaque+field-num_offset);
  -} else if (field-flags  VMS_VARRAY_UINT16) {
  -n_elems = *(uint16_t *)(opaque+field-num_offset);
  -} else if (field-flags  VMS_VARRAY_UINT8) {
  -n_elems = *(uint8_t *)(opaque+field-num_offset);
  +if (field-field_exists  !field-field_exists(opaque, 
  version_id)) {
  +continue;
  +}
  +if (field-version_id  version_id) {
  +continue;
  +}
  +
  +void *base_addr = opaque + field-offset;
  +int i, n_elems = 1;
  +int size = field-size;
  +
  +if (field-flags  VMS_VBUFFER) {
  +size = *(int32_t *)(opaque+field-size_offset);
  +if (field-flags  VMS_MULTIPLY) {
  +size *= field-size;
   }
  -if (field-flags  VMS_POINTER) {
  -base_addr = *(void **)base_addr + field-start;
  +}
  +if (field-flags  VMS_ARRAY) {
  +n_elems = field-num;
  +} else if (field-flags  VMS_VARRAY_INT32) {
  +n_elems = *(int32_t *)(opaque+field-num_offset);
  +} else if (field-flags  VMS_VARRAY_UINT32) {
  +n_elems = *(uint32_t *)(opaque+field-num_offset);
  +} else if (field-flags  VMS_VARRAY_UINT16) {
  +n_elems = *(uint16_t *)(opaque+field-num_offset);
  +} else if (field-flags  VMS_VARRAY_UINT8) {
  +n_elems = *(uint8_t *)(opaque+field-num_offset);
  +}
  +if (field-flags  VMS_POINTER) {
  +base_addr = *(void **)base_addr + field-start;
  +}
  +for (i = 0; i  n_elems; i++) {
  +void *addr = base_addr + size * i;
  +
  +if (field-flags  VMS_ARRAY_OF_POINTER) {
  +addr = *(void **)addr;
   }
  -for (i = 0; i  n_elems; i++) {
  -void *addr = base_addr + size * i;
  -
  -if (field-flags  VMS_ARRAY_OF_POINTER) {
  -addr = *(void **)addr;
  -}
  -if (field-flags  VMS_STRUCT) {
  -ret = vmstate_load_state(f, field-vmsd, addr,
  - field-vmsd-version_id);
  -} else {
  -ret = field-info-get(f, addr, size);
  +if (field-flags  VMS_STRUCT) {
  +ret = vmstate_load_state(f, field-vmsd, addr,
  + field-vmsd-version_id);
  +} else {
  +ret = field-info-get(f, addr, size);
   
  -}
  -if (ret  0) {
  -return ret;
  -}
  +}
  +if (ret  0) {
  +return ret;
   }
   }
   }
 
 With whitespace change ignored:
 
 @@ -1694,10 +1694,13 @@
  return ret;
  }
  for (field = vmsd-fields; field-name; field++) {
 -if ((field-field_exists 
 - field-field_exists(opaque, version_id)) ||
 -(!field-field_exists 
 - field-version_id = version_id)) {
 +if (field-field_exists  !field-field_exists(opaque, version_id)) 
 {
 +continue;
 +}
 +if (field-version_id  version_id) {
 +

Re: [Qemu-devel] [PATCH 12/11] virtio-pci: avoid extra pointer dereferences on fast path

2013-10-15 Thread Frederic Konrad

Hi Paolo,

This looks ok, but I don't find the branch where it applies?

Seems it's already fixed on master.

Thanks,
Fred

On 14/10/2013 18:23, Paolo Bonzini wrote:

We do not need to access vdev on the MSI-X fast path of virtio_pci_notify.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
It is possible to get rid of BusChild altogether, but even then
this would be one less pointer dereference, and it's a simpler
patch.  So let's do this instead for 1.7.

  hw/virtio/virtio-pci.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1a179ea..a191c24 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -113,12 +113,13 @@ static inline VirtIOPCIProxy 
*to_virtio_pci_proxy_fast(DeviceState *d)
  static void virtio_pci_notify(DeviceState *d, uint16_t vector)
  {
  VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d);
-VirtIODevice *vdev = virtio_bus_get_device(proxy-bus);
  
  if (msix_enabled(proxy-pci_dev))

  msix_notify(proxy-pci_dev, vector);
-else
+else {
+VirtIODevice *vdev = virtio_bus_get_device(proxy-bus);
  qemu_set_irq(proxy-pci_dev.irq[0], vdev-isr  1);
+}
  }
  
  static void virtio_pci_save_config(DeviceState *d, QEMUFile *f)





Re: [Qemu-devel] [PATCH 12/11] virtio-pci: avoid extra pointer dereferences on fast path

2013-10-15 Thread Paolo Bonzini
Il 15/10/2013 14:13, Frederic Konrad ha scritto:
 Hi Paolo,
 
 This looks ok, but I don't find the branch where it applies?
 
 Seems it's already fixed on master.

It's on top of the previous 11 patches.

Paolo




Re: [Qemu-devel] [RFH] Qemu main thread is blocked in g_poll in windows guest

2013-10-15 Thread Xiexiangyou
Thanks for your reply :-)
The QEMU version is 1.5.1,and the KVM version is 3.6

QEMU command:
/usr/bin/qemu-kvm -name win2008_dc_5 -S -machine 
pc-i440fx-1.5,accel=kvm,usb=off -m 2048 -realtime mlock=off -smp 
4,maxcpus=64,sockets=16,cores=4,threads=1 -uuid 
13e08e3e-cd23-4450-8bd3-60e7c220316d -no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/win2008_dc_5.monitor,server,nowait
 -mon chardev=charmonitor,id=monitor,mode=control -rtc 
base=utc,clock=vm,driftfix=slew -no-hpet -no-shutdown -device 
piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device 
virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x4 -device 
virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 -drive 
file=/dev/vmdisk/win2008_dc_5,if=none,id=drive-scsi0-0-0-0,format=qcow2,cache=none,aio=native
 -device 
scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=1
 -netdev tap,fd=28,id=hostnet0,vhost=on,vhostfd=29 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:16:49:23,bus=pci.0,addr=0x3 
-chardev 
socket,id=charchannel0,path=/var/run/libvirt/qemu/win2008_dc_5.extend,server,nowait
 -device 
virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.1
 -chardev 
socket,id=charchannel1,path=/var/run/libvirt/qemu/win2008_dc_5.agent,server,nowait
 -device 
virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,id=channel1,name=org.qemu.guest_agent.0
 -device usb-tablet,id=input0 -vnc 0.0.0.0:4 -device 
cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6

(gdb) bt
#0  0x7f9ba661a423 in poll () from /lib64/libc.so.6
#1  0x0059460f in os_host_main_loop_wait (timeout=4294967295) at 
main-loop.c:226
#2  0x005946a4 in main_loop_wait (nonblocking=0) at main-loop.c:464
#3  0x00619309 in main_loop () at vl.c:2182
#4  0x0061fb5e in main (argc=54, argv=0x7fff879830c8, 
envp=0x7fff87983280) at vl.c:4611

Main thread's strace message:
# strace -p 6386
Process 6386 attached - interrupt to quit
restart_syscall(... resuming interrupted call ...

cpu thread's strace message:
# strace -p 6389
Process 6389 attached - interrupt to quit
rt_sigtimedwait([BUS USR1], 0x7f9ba36fbc00) = -1 EAGAIN (Resource temporarily 
unavailable)
rt_sigpending([])   = 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
ioctl(17, 0xae80, 0)= 0
...

Thanks!
--xie

-Original Message-
From: Paolo Bonzini [mailto:paolo.bonz...@gmail.com] On Behalf Of Paolo Bonzini
Sent: Tuesday, October 15, 2013 7:52 PM
To: Xiexiangyou
Cc: qemu-devel@nongnu.org; qemu-devel-requ...@nongnu.org; k...@vger.kernel.org; 
Huangpeng (Peter); Luonengjun
Subject: Re: [RFH] Qemu main thread is blocked in g_poll in windows guest

Il 15/10/2013 12:21, Xiexiangyou ha scritto:
 Hi all:
 
 Windows2008 Guest run without pressure for long time. Sometimes, it
 stop and looks like hanging. But when I connect to it with VNC, It
 resume to run, but VM's time is delayed . When the vm is hanging, I
 check the main thread of QEMU. I find that the thread is blocked in
 g_poll function. it is waiting for a SIG, However, there is no SIG .
 
 I tried the clock with hpet and no hpet, but came out the same
 problem. Then I upgrade the glibc to newer, it didn't work too. I'm
 confused. Is the reason that VM in sleep state and doesn't emit the
 signal. I set the windows 's power option, enable/disable the
 allow the wake timers, I didn't work.
 
 Is anybody have met the same problem before, or know the reason. Your
 reply will be very helpful.

This post is missing a few pieces of information:

* What version of QEMU is this?

* What is the command line?

* How do you know g_poll is waiting for a signal and not for a file
descriptor?

* What is the backtrace of the main thread?  What is the backtrace of
the VCPU thread?

etc.

Paolo



[Qemu-devel] Why is TYPE_CPU no-user? (was: [PATCH RFC 0/9] Clean up and fix no_user)

2013-10-15 Thread Markus Armbruster
Andreas,

To go beyond RFC with this series, I need to explain why TYPE_CPU
cannot_instantiate_with_device_add_yet.  Would you be so kind and help
me out with a suitable comment?

You can find examples in PATCH 2-7/9.



Re: [Qemu-devel] [PATCH qom-cpu 00/21 v9] target-i386: convert CPU features into properties

2013-10-15 Thread Vadim Rozenfeld


- Original Message -
From: Igor Mammedov imamm...@redhat.com
To: Igor Mammedov imamm...@redhat.com
Cc: Anthony Liguori aligu...@us.ibm.com, Eduardo Habkost 
ehabk...@redhat.com, qemu-devel@nongnu.org, Vadim Rozenfeld 
vroze...@redhat.com, Paolo Bonzini pbonz...@redhat.com, Andreas Färber 
afaer...@suse.de
Sent: Monday, October 14, 2013 3:09:11 PM
Subject: Re: [Qemu-devel] [PATCH qom-cpu 00/21 v9] target-i386: convert CPU 
features into properties

On Tue, 16 Jul 2013 00:25:53 +0200
Igor Mammedov imamm...@redhat.com wrote:

 It's reordered and rebased v8 plus CPUID feature bits conversion to properties
 and cleanups that are removing unused anymore *_feature_name arrays.
 
 dynamic = static properties conversion is still making sense as cleanup of
 initfn(), consolidating all properties in one place and making uniform
 property setters signatures, so it was kept.
 
 hyperv and dynamic = static properties conversion are covered by virt-test's
 qemu_cpu test group.
 
 On top of that, CPUID feature bits conversion and cleanups it's allowed.
 
 git for testing: https://github.com/imammedo/qemu/tree/x86-cpu-properties.v9
 
 v8-v9:
 * reorder hyperv/check/force and cpu_x86_parse_featurestr() cleanups to be 
 the first
 * when converting dynamic properties inline custom DEFINE_PROP_FOO directly in
   cpu_x86_properties property array. (req: afaerber)
 * change f- CPUID feature bits prefix to feat- (req: afaerber)
 * replace F_* macros with a single X86CPU_FEAT() macro and simplify it setting
 default value to 0, intended for defaults to be set by initfn()
 * kvmclock: fix endless loop on compat kvmclock2 append
 * converted check_features_against_host() and x86_cpu_list() to use
   static properties definition for feature name lookups, removing along the 
 way
   unused anymore *_feature_name arrays.
 
 v7-v8:
 * split out dynamic properties convertion patch into per property patches
   to simplify review
 * drop feature bits convertion
 
 v6-v7:
 * convert globals check_cpuid, enforce_cpuid and  hyperv_* to fields of
   CPUState
 * Make PropertyInfo-s static
 * maintain legacy kvmclock semantic in cpu_x86_parse_featurestr()
 * existing properties code are not moved around, just fixed signatures where
   it's needed and used visitors.
 
 v5-v6:
 * when converting feature names to property names, replace '_' with '-'
 * separate patches converting existing dynamic properties into one, were
   squashed into one [1/9] and change tested with virt-test(next).
 * patches that were touching +-foo features are squashed into one [9/9],
   to avoid behavior change between them(f-kvmclock property).
 * the rest of conversions were basicaly rebased on top of current qom-cpu-next
   tree, with small corrections
 
 Igor Mammedov (20):
   target-i386: Move hyperv_* static globals to X86CPU
   target-i386: convert 'hv_spinlocks' to static property
   target-i386: convert 'hv_relaxed' to static property
   target-i386: convert 'hv_vapic' to static property
   target-i386: convert 'check' and 'enforce' to static properties
   target-i386: cleanup 'foo' feature handling'
   target-i386: cleanup 'foo=val' feature handling
   target-i386: cpu: convert 'level' to static property
   target-i386: cpu: convert 'xlevel' to static property
   target-i386: cpu: convert 'family' to static property
   target-i386: cpu: convert 'model' to static property
   target-i386: cpu: convert 'stepping' to static property
   target-i386: cpu: convert 'vendor' to static property
   target-i386: cpu: convert 'model-id' to static property
   target-i386: cpu: convert 'tsc-frequency' to static property
   target-i386: set [+-]feature using static properties
   qdev: introduce qdev_prop_find_bit()
   target-i386: use static properties in check_features_against_host() to
 print CPUID feature names
   target-i386: use static properties to list CPUID features
   target-i386: remove unused *_feature_name arrays
 
  hw/core/qdev-properties.c|  15 +
  include/hw/qdev-properties.h |  13 +
  target-i386/Makefile.objs|   2 +-
  target-i386/cpu-qom.h|   6 +
  target-i386/cpu.c| 705 
 +--
  target-i386/cpu.h|   4 +
  target-i386/hyperv.c |  64 
  target-i386/hyperv.h |  45 ---
  target-i386/kvm.c|  36 ++-
  9 files changed, 415 insertions(+), 475 deletions(-)
  delete mode 100644 target-i386/hyperv.c
  delete mode 100644 target-i386/hyperv.h
 

ping?

Hi Igor,
Looks fine with me.
Best regards,
Vadim.



Re: [Qemu-devel] [PATCH 00/11] virtio: cleanup and fix hot-unplug

2013-10-15 Thread Michael S. Tsirkin
On Tue, Oct 08, 2013 at 07:02:44PM +0200, Paolo Bonzini wrote:
 Il 20/09/2013 16:57, Paolo Bonzini ha scritto:
  This series fixes hot-unplug of virtio devices, which can crash due to
  dangling pointer accesses.
  
  The current implementation supports guest-initiated hot-unplug via the
  virtio_bus_destroy_device function, but not hot-unplugging the virtio
  device by virtue of unplugging its parent container device.
  
  The problem is that the callback for the bus implementation to cleanup
  is placed in the wrong place; it is in virtio_bus_destroy_device, which
  should be called by the bus, instead of being somewhere in device code.
  We need to have the callback in device code (for example in dc-exit),
  so that we invoke it on every unplug action, no matter who starts it.
  
  Thus, the series cleans up plugging and unplugging of virtio devices
  so that it does not need any help from the bus (patches 1-4).  It then
  stops the virtio devices' overriding of dc-exit, moving their cleanup
  code to the new exit callback in VirtioDeviceClass (patches 5-10).
  Finally, patch 11 can make virtio-pci implement the device_unplugged
  callback.
  
  Something similar is probably needed in virtio-ccw too.  However,
  virtio-ccw needs more surgery because it does not include a device_plugged
  callback either, so I did not touch it.
 
 Michael, I prepared a rebase of
 http://permalink.gmane.org/gmane.comp.emulators.qemu/225985 on top of
 these patches and sent it to Andreas.  My understanding is that he will
 send them to qemu-devel.
 
 Let me know if you want to handle these patches yourself, or I can send
 a pull request for both directly with your Acked-bys.
 
 As to review, I think it can be usefully split as follows:
 
 - 4-10 for Andreas
 
 - 3 for Alex
 
 - 2 11 for you
 
 - 1 for either you or Andreas
 
 Paolo

OK so I can merge this but need Acks from Alex and Andreas, right?

  
  Paolo Bonzini (11):
virtio-bus: remove vdev field
virtio-pci: remove vdev field
virtio-ccw: remove vdev field
virtio-bus: cleanup plug/unplug interface
virtio-blk: switch exit callback to VirtioDeviceClass
virtio-serial: switch exit callback to VirtioDeviceClass
virtio-net: switch exit callback to VirtioDeviceClass
virtio-scsi: switch exit callback to VirtioDeviceClass
virtio-balloon: switch exit callback to VirtioDeviceClass
virtio-rng: switch exit callback to VirtioDeviceClass
virtio-pci: add device_unplugged callback
  
   hw/block/virtio-blk.c   |  10 ++--
   hw/char/virtio-serial-bus.c |  10 ++--
   hw/net/virtio-net.c |  11 ++--
   hw/s390x/virtio-ccw.c   |  80 +++
   hw/s390x/virtio-ccw.h   |   1 -
   hw/scsi/vhost-scsi.c|  11 ++--
   hw/scsi/virtio-scsi.c   |  15 +++--
   hw/virtio/virtio-balloon.c  |  10 ++--
   hw/virtio/virtio-bus.c  |  81 +++
   hw/virtio/virtio-mmio.c |   9 +--
   hw/virtio/virtio-pci.c  | 119 
  
   hw/virtio/virtio-pci.h  |   1 -
   hw/virtio/virtio-rng.c  |  10 ++--
   hw/virtio/virtio.c  |   7 ++-
   include/hw/virtio/virtio-bus.h  |  22 +---
   include/hw/virtio/virtio-scsi.h |   2 +-
   include/hw/virtio/virtio.h  |   1 +
   17 files changed, 223 insertions(+), 177 deletions(-)
  



Re: [Qemu-devel] [RFH] Qemu main thread is blocked in g_poll in windows guest

2013-10-15 Thread Paolo Bonzini
Il 15/10/2013 14:18, Xiexiangyou ha scritto:
 (gdb) bt
 #0  0x7f9ba661a423 in poll () from /lib64/libc.so.6
 #1  0x0059460f in os_host_main_loop_wait (timeout=4294967295) at 
 main-loop.c:226
 #2  0x005946a4 in main_loop_wait (nonblocking=0) at main-loop.c:464
 #3  0x00619309 in main_loop () at vl.c:2182
 #4  0x0061fb5e in main (argc=54, argv=0x7fff879830c8, 
 envp=0x7fff87983280) at vl.c:4611

This backtrace looks okay.  poll is not holding the iothread lock and
thus the VCPU thread can run QEMU code.

It also looks like the VCPU thread is doing nothing special besides
running KVM_RUN.  Did you take the backtrace during one of these hangups?

Paolo




[Qemu-devel] [PATCH] map 64-bit PCI BARs at location provided by emulator

2013-10-15 Thread Igor Mammedov
Currently 64-bit PCI BARs are unconditionally mapped by BIOS right
over 4G + RamSizeOver4G location, which doesn't allow to reserve
extra space before 64-bit PCI window. For memory hotplug an extra
RAM space might be reserved after present 64-bit RAM end and BIOS
should map 64-bit PCI BARs after it.

Introduce etc/pcimem64-minimum-addres romfile to provide BIOS
a hint where it should start mapping of 64-bit PCI BARs.
If romfile is missing BIOS reverts to legacy behavior and starts
mapping right after high memory.

Signed-off-by: Igor Mammedov imamm...@redhat.com
v3:
  * rename etc/pcimem64-start to etc/pcimem64-minimum-addres
v2:
  * place 64-bit window behind high RAM end if etc/pcimem64-start
points below it.
---
 src/fw/pciinit.c |   13 -
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index b29db99..64a37c3 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -18,6 +18,8 @@
 #include paravirt.h // RamSize
 #include string.h // memset
 #include util.h // pci_setup
+#include byteorder.h // le64_to_cpu
+#include romfile.h // romfile_loadint
 
 #define PCI_DEVICE_MEM_MIN 0x1000
 #define PCI_BRIDGE_IO_MIN  0x1000
@@ -764,6 +766,15 @@ static void pci_bios_map_devices(struct pci_bus *busses)
 {
 if (pci_bios_init_root_regions(busses)) {
 struct pci_region r64_mem, r64_pref;
+u64 ram64_end = 0x1ULL + RamSizeOver4G;
+u64 base64 = 
le64_to_cpu(romfile_loadint(etc/pcimem64-minimum-address,
+ ram64_end));
+if (base64  ram64_end) {
+dprintf(1, ignorig etc/pcimem64-minimum-address [0x%llx] below 
+   present RAM, placing 64-bit PCI window behind RAM end: 

+   0x%llx, base64, ram64_end);
+base64 = ram64_end;
+}
 r64_mem.list.first = NULL;
 r64_pref.list.first = NULL;
 pci_region_migrate_64bit_entries(busses[0].r[PCI_REGION_TYPE_MEM],
@@ -779,7 +790,7 @@ static void pci_bios_map_devices(struct pci_bus *busses)
 u64 align_mem = pci_region_align(r64_mem);
 u64 align_pref = pci_region_align(r64_pref);
 
-r64_mem.base = ALIGN(0x1LL + RamSizeOver4G, align_mem);
+r64_mem.base = ALIGN(base64, align_mem);
 r64_pref.base = ALIGN(r64_mem.base + sum_mem, align_pref);
 pcimem64_start = r64_mem.base;
 pcimem64_end = r64_pref.base + sum_pref;
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2] net/net: Change the default mac address of nic

2013-10-15 Thread Eric Blake
On 10/14/2013 11:07 PM, Stefan Weil wrote:
 
 Is it reasonable to get a random mac address in your guest? I don't
 think so. It would no longer be possible to connect to a guest using
 ssh, restart that guest and connect again with ssh.

Agreed - libvirt ALWAYS passes a MAC to qemu, even if the user did not
specify a MAC to libvirt, precisely because the MAC must be reproducible
rather than random to avoid changing the guest ABI.  I don't think this
patch is needed - it's up to management to use qemu correctly.

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



signature.asc
Description: OpenPGP digital signature


  1   2   3   >