[Qemu-devel] [PATCH 2/2] ioapic use QOM style

2013-09-27 Thread xiaoqiang zhao
Change intc/ioapic kvm/ioapic to use QOM' realizefn.
To achive this, I move variable 'ioapic_no' from static to global.
Then, ioapic_realize and kvm_ioapic_realize can drop the 'instance_no' 
argument.  Instead of parent, child increase ioapic_no now.

Signed-off-by: xiaoqiang zhao zxq_yx_...@163.com
---
 hw/i386/kvm/ioapic.c  |   35 ++-
 hw/intc/ioapic.c  |   41 ++---
 hw/intc/ioapic_common.c   |   17 +--
 include/hw/i386/ioapic_internal.h |1 -
 4 files changed, 75 insertions(+), 19 deletions(-)

diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c
index f11a540..b08865d 100644
--- a/hw/i386/kvm/ioapic.c
+++ b/hw/i386/kvm/ioapic.c
@@ -15,6 +15,22 @@
 #include hw/i386/apic_internal.h
 #include sysemu/kvm.h
 
+#define TYPE_KVM_IOAPIC kvm-ioapic
+#define KVM_IOAPIC_CLASS(class) \
+OBJECT_CLASS_CHECK(KVMIOAPICClass, (class), TYPE_KVM_IOAPIC)
+#define KVM_IOAPIC_GET_CLASS(obj) \
+OBJECT_GET_CLASS(KVMIOAPICClass, (obj), TYPE_KVM_IOAPIC)
+
+/**
+ * KVMIOAPICClass:
+ * @parent_ralize: The parent's ralizefn
+ */
+typedef struct KVMIOAPICClass {
+IOAPICCommonClass parent_class;
+
+DeviceRealize parent_realize;
+} KVMIOAPICClass;
+
 /* PC Utility function */
 void kvm_pc_setup_irq_routing(bool pci_enabled)
 {
@@ -127,11 +143,16 @@ static void kvm_ioapic_set_irq(void *opaque, int irq, int 
level)
 apic_report_irq_delivered(delivered);
 }
 
-static void kvm_ioapic_init(IOAPICCommonState *s, int instance_no)
+static void kvm_ioapic_realize(DeviceState *dev, Error **errp)
 {
-memory_region_init_reservation(s-io_memory, NULL, kvm-ioapic, 0x1000);
+IOAPICCommonState *s = IOAPIC_COMMON(dev);
+KVMIOAPICClass *kic = KVM_IOAPIC_GET_CLASS(dev);
 
-qdev_init_gpio_in(DEVICE(s), kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
+memory_region_init_reservation(s-io_memory, NULL, TYPE_KVM_IOAPIC, 
0x1000);
+
+qdev_init_gpio_in(dev, kvm_ioapic_set_irq, IOAPIC_NUM_PINS);
+
+kic-parent_realize(dev, errp);
 }
 
 static Property kvm_ioapic_properties[] = {
@@ -143,19 +164,23 @@ static void kvm_ioapic_class_init(ObjectClass *klass, 
void *data)
 {
 IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
+KVMIOAPICClass *kic = KVM_IOAPIC_CLASS(klass);
 
-k-init  = kvm_ioapic_init;
 k-pre_save  = kvm_ioapic_get;
 k-post_load = kvm_ioapic_put;
 dc-reset= kvm_ioapic_reset;
 dc-props= kvm_ioapic_properties;
+
+kic-parent_realize = dc-realize;
+dc-realize = kvm_ioapic_realize;
 }
 
 static const TypeInfo kvm_ioapic_info = {
-.name  = kvm-ioapic,
+.name  = TYPE_KVM_IOAPIC,
 .parent = TYPE_IOAPIC_COMMON,
 .instance_size = sizeof(KVMIOAPICState),
 .class_init = kvm_ioapic_class_init,
+.class_size = sizeof(KVMIOAPICClass),
 };
 
 static void kvm_ioapic_register_types(void)
diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
index d866e00..aeb3ed1 100644
--- a/hw/intc/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -27,6 +27,24 @@
 
 //#define DEBUG_IOAPIC
 
+#define TYPE_IOAPIC ioapic
+#define IOAPIC_CLASS(class) \
+OBJECT_CLASS_CHECK(IOAPICClass, (class), TYPE_IOAPIC)
+#define IOAPIC_GET_CLASS(obj) \
+OBJECT_GET_CLASS(IOAPICClass, (obj), TYPE_IOAPIC)
+
+/**
+ * IOAPICClass:
+ * @parent_realize: The parent's ralizefn
+ */
+typedef struct IOAPICClass {
+IOAPICCommonClass parent_class;
+
+DeviceRealize parent_realize;
+} IOAPICClass;
+
+extern int ioapic_no;
+
 #ifdef DEBUG_IOAPIC
 #define DPRINTF(fmt, ...)   \
 do { printf(ioapic:  fmt , ## __VA_ARGS__); } while (0)
@@ -225,30 +243,39 @@ static const MemoryRegionOps ioapic_io_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void ioapic_init(IOAPICCommonState *s, int instance_no)
+static void ioapic_realize(DeviceState *dev, Error **errp)
 {
+IOAPICCommonState *s = IOAPIC_COMMON(dev);
+IOAPICClass *ic = IOAPIC_GET_CLASS(dev);
+
 memory_region_init_io(s-io_memory, OBJECT(s), ioapic_io_ops, s,
-  ioapic, 0x1000);
+  TYPE_IOAPIC, 0x1000);
+
+qdev_init_gpio_in(dev, ioapic_set_irq, IOAPIC_NUM_PINS);
 
-qdev_init_gpio_in(DEVICE(s), ioapic_set_irq, IOAPIC_NUM_PINS);
+ioapics[ioapic_no] = s;
+ic-parent_realize(dev, errp);
 
-ioapics[instance_no] = s;
+/* increase the counter */
+ioapic_no++;
 }
 
 static void ioapic_class_init(ObjectClass *klass, void *data)
 {
-IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass);
+IOAPICClass *ic = IOAPIC_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-k-init = ioapic_init;
 dc-reset = ioapic_reset_common;
+ic-parent_realize = dc-realize;
+dc-realize = ioapic_realize;
 }
 
 static const TypeInfo ioapic_info = {
-.name  = ioapic,
+.name  = TYPE_IOAPIC,
 .parent= TYPE_IOAPIC_COMMON,
 .instance_size = 

[Qemu-devel] [PATCH 1/2] kvm/apic: use QOM style

2013-09-27 Thread xiaoqiang zhao
From: xiaoqiang.zhao zxq_yx_...@163.com

Change apic and kvm/apic to use QOM interface.

Includes:
1. APICCommonState now use QOM realizefn
2. Remove DO_UPCAST() for APICCommonState
3. Use type constant
4. Change DeviceState pointers from 'd' to 'dev', sounds better?

Signed-off-by: xiaoqiang zhao zxq_yx_...@163.com
---
 hw/i386/kvm/apic.c  |   40 ++
 hw/intc/apic.c  |   70 +--
 hw/intc/apic_common.c   |   70 +++
 include/hw/i386/apic_internal.h |1 -
 4 files changed, 113 insertions(+), 68 deletions(-)

diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index 5609063..5733dbb 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -13,6 +13,22 @@
 #include hw/pci/msi.h
 #include sysemu/kvm.h
 
+#define TYPE_KVM_APIC kvm-apic
+#define KVM_APIC_CLASS(class) \
+OBJECT_CLASS_CHECK(KVMAPICClass, (class), TYPE_KVM_APIC)
+#define KVM_APIC_GET_CLASS(obj) \
+OBJECT_GET_CLASS(KVMAPICClass, (obj), TYPE_KVM_APIC)
+
+/**
+ * KVMAPICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct KVMAPICClass {
+APICCommonClass parent_class;
+
+DeviceRealize parent_realize;
+} KVMAPICClass;
+
 static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
 int reg_id, uint32_t val)
 {
@@ -25,9 +41,9 @@ static inline uint32_t kvm_apic_get_reg(struct 
kvm_lapic_state *kapic,
 return *((uint32_t *)(kapic-regs + (reg_id  4)));
 }
 
-void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic)
+void kvm_put_apic_state(DeviceState *dev, struct kvm_lapic_state *kapic)
 {
-APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
+APICCommonState *s = APIC_COMMON(dev);
 int i;
 
 memset(kapic, 0, sizeof(*kapic));
@@ -51,9 +67,9 @@ void kvm_put_apic_state(DeviceState *d, struct 
kvm_lapic_state *kapic)
 kvm_apic_set_reg(kapic, 0x3e, s-divide_conf);
 }
 
-void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic)
+void kvm_get_apic_state(DeviceState *dev, struct kvm_lapic_state *kapic)
 {
-APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
+APICCommonState *s = APIC_COMMON(dev);
 int i, v;
 
 s-id = kvm_apic_get_reg(kapic, 0x2)  24;
@@ -171,34 +187,44 @@ static const MemoryRegionOps kvm_apic_io_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void kvm_apic_init(APICCommonState *s)
+static void kvm_apic_realize(DeviceState *dev, Error **errp)
 {
+APICCommonState *s = APIC_COMMON(dev);
+KVMAPICClass *kac = KVM_APIC_GET_CLASS(dev);
+
 memory_region_init_io(s-io_memory, NULL, kvm_apic_io_ops, s, 
kvm-apic-msi,
   APIC_SPACE_SIZE);
 
 if (kvm_has_gsi_routing()) {
 msi_supported = true;
 }
+
+kac-parent_realize(dev, errp);
 }
 
 static void kvm_apic_class_init(ObjectClass *klass, void *data)
 {
 APICCommonClass *k = APIC_COMMON_CLASS(klass);
+KVMAPICClass *kac = KVM_APIC_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-k-init = kvm_apic_init;
 k-set_base = kvm_apic_set_base;
 k-set_tpr = kvm_apic_set_tpr;
 k-get_tpr = kvm_apic_get_tpr;
 k-enable_tpr_reporting = kvm_apic_enable_tpr_reporting;
 k-vapic_base_update = kvm_apic_vapic_base_update;
 k-external_nmi = kvm_apic_external_nmi;
+
+kac-parent_realize = dc-realize;
+dc-realize = kvm_apic_realize;
 }
 
 static const TypeInfo kvm_apic_info = {
-.name = kvm-apic,
+.name = TYPE_KVM_APIC,
 .parent = TYPE_APIC_COMMON,
 .instance_size = sizeof(APICCommonState),
 .class_init = kvm_apic_class_init,
+.class_size = sizeof(KVMAPICClass),
 };
 
 static void kvm_apic_register_types(void)
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index a913186..0e0f71c 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -32,6 +32,20 @@
 #define SYNC_TO_VAPIC   0x2
 #define SYNC_ISR_IRR_TO_VAPIC   0x4
 
+#define TYPE_APIC apic
+#define APIC_CLASS(class) OBJECT_CLASS_CHECK(APICClass, (class), TYPE_APIC)
+#define APIC_GET_CLASS(obj) OBJECT_GET_CLASS(APICClass, (obj), TYPE_APIC)
+
+/**
+ * APICClass:
+ * @parent_realize: The parent's realizefn
+ */
+typedef struct APICClass {
+APICCommonClass parent_class;
+
+DeviceRealize parent_realize;
+} APICClass;
+
 static APICCommonState *local_apics[MAX_APICS + 1];
 
 static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode);
@@ -171,9 +185,9 @@ static void apic_local_deliver(APICCommonState *s, int 
vector)
 }
 }
 
-void apic_deliver_pic_intr(DeviceState *d, int level)
+void apic_deliver_pic_intr(DeviceState *dev, int level)
 {
-APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
+APICCommonState *s = APIC_COMMON(dev);
 
 if (level) {
 apic_local_deliver(s, APIC_LVT_LINT0);
@@ -376,9 +390,9 @@ static void apic_update_irq(APICCommonState *s)
 }
 }
 
-void 

[Qemu-devel] Hvmloader: Add _STA for PCI hotplug slots

2013-09-27 Thread Gonglei (Arei)
Hi,

In Xen platform, after using upstream qemu, the all of pci devices will show 
hotplug in the windows guest. 
In this situation, the windows guest may occur blue screen when VM' user click 
the icon of VGA card for trying unplug VGA card.
However, we don't hope VM's user can do such dangerous operation, and showing 
all pci devices inside the guest OS is unfriendly.

In addition, I find the traditional qemu have not this problem, and KVM also.

On the KVM platform, the seabios will read the RMV bits of pci slot (according 
the 0xae08 I/O port register), 
then modify the SSDT table. 

The key steps as follows:
In Seabios:
#define PCI_RMV_BASE 0xae0c// 0xae08 I/O port register
static void* build_ssdt(void)
{
 ...
 // build Device object for each slot
 u32 rmvc_pcrm = inl(PCI_RMV_BASE);
 ...
}

In upstream Qemu, read 0xae0c I/O port register function:
static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size)
{ 
...   
case PCI_RMV_BASE - PCI_HOTPLUG_ADDR:
val = s-pci0_hotplug_enable;
break;
}   
s-pci0_hotplug_enable is set by the follow function:

static void piix4_update_hotplug(PIIX4PMState *s)
{
...
s-pci0_hotplug_enable = ~0;
s-pci0_slot_device_present = 0;

QTAILQ_FOREACH_SAFE(kid, bus-children, sibling, next) {
DeviceState *qdev = kid-child;
PCIDevice *pdev = PCI_DEVICE(qdev);
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pdev);
int slot = PCI_SLOT(pdev-devfn);

//setting by PCIDeviceClass *k-no_hotplug
if (pc-no_hotplug) {
s-pci0_hotplug_enable = ~(1U  slot);
}

s-pci0_slot_device_present |= (1U  slot);
}
}

But, on the XEN platform, ACPI DSDT tables is produced by the hvmloader, 
more details in this patch:
http://xen.1045712.n5.nabble.com/xen-unstable-hvmloader-acpi-dsdt-Fix-PCI-hotplug-with-the-new-qemu-xen-td4947152.html

# Node ID 1a912ce93b506a185b54fd97986214e6eff8a0bc 
# Parent  6bc03e22f921aadfa7e5cebe92100cb01377947d 
hvmloader/acpi/dsdt: Fix PCI hotplug with the new qemu-xen. 

The ACPI PIIX4 device in QEMU upstream as not the same behavior to 
handle PCI hotplug. This patch introduce the necessary change to the 
DSDT ACPI table to behave as expceted by the new QEMU. 

To switch to this new DSDT table version, there is a new option 
--dm-version to mk_dsdt. 

Change are inspired by SeaBIOS DSDT source code. 

There is few things missing with the new QEMU: 
  - QEMU provide the plugged/unplugged status only per slot (and not 
per func like qemu-xen-traditionnal. 
  - I did not include the _STA ACPI method that give the status of a 
device (present, functionning properly) because qemu-xen does not 
handle it. 
  - I did not include the _RMV method that say if the device can be 
removed, 
because the IO port of QEMU that give this status always return 
true. In 
SeaBIOS table, they have a specific _RMV method for VGA, ISA that 
return 
false. But I'm not sure that we can do the same in Xen.


now, I add the _STA method, return the different value according the 0xae08 I/O 
port register on read,
a pci device allow hotplug return 0x1f, a pci device don't allow return 0x1e.
Then the pci devices which don't allow hotplug will not show inside the guest 
OS.

Index: tools/firmware/hvmloader/acpi/mk_dsdt.c
===
--- tools/firmware/hvmloader/acpi/mk_dsdt.c (revision 1105)
+++ tools/firmware/hvmloader/acpi/mk_dsdt.c (working copy)
@@ -437,6 +437,10 @@
 indent(); printf(B0EJ, 32,\n);
 pop_block();
 
+stmt(OperationRegion, SRMV, SystemIO, 0xae0c, 0x04);
+push_block(Field, SRMV, DWordAcc, NoLock, WriteAsZeros);
+indent(); printf(RMV, 32,\n);
+pop_block();
 /* hotplug_slot */
 for (slot = 1; slot = 31; slot++) {
 push_block(Device, S%i, slot); {
@@ -445,6 +449,14 @@
 stmt(Store, ShiftLeft(1, %#06x), B0EJ, slot);
 stmt(Return, 0x0);
 } pop_block();
+push_block(Method, _STA, 0);{
+   push_block(If, And(RMV, ShiftLeft(1, %#06x)), slot);
+  stmt(Return, 0x1F);
+   pop_block();
+   push_block(Else, NULL);
+  stmt(Return, 0x1E);
+   pop_block();
+};pop_block();
 stmt(Name, _SUN, %i, slot);
 } pop_block();
 }

Have you any ideas?Expecting your reply, thanks in advance!

Best regards,
-Gonglei


[Qemu-devel] Compiling Instructions for QEMU x86_64 for windows 64 bit

2013-09-27 Thread Vikas Desai
Hi,
Where can I find detailed compiling instructions for qemu on native windows 
x86_64 using mingw64.
Cheers,Vikas  

Re: [Qemu-devel] [PATCH] exec: cleanup DEBUG_SUBPAGE

2013-09-27 Thread Paolo Bonzini
Michael, want to pick this up for -trivial?

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

Il 27/09/2013 03:25, Amos Kong ha scritto:
 Touched some error after enabling DEBUG_SUBPAGE.
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  exec.c | 18 +-
  1 file changed, 9 insertions(+), 9 deletions(-)
 
 diff --git a/exec.c b/exec.c
 index 07aa2c6..5aef833 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -1573,7 +1573,7 @@ static uint64_t subpage_read(void *opaque, hwaddr addr,
  uint8_t buf[4];
  
  #if defined(DEBUG_SUBPAGE)
 -printf(%s: subpage %p len %d addr  TARGET_FMT_plx \n, __func__,
 +printf(%s: subpage %p len %u addr  TARGET_FMT_plx \n, __func__,
 subpage, len, addr);
  #endif
  address_space_read(subpage-as, addr + subpage-base, buf, len);
 @@ -1596,7 +1596,7 @@ static void subpage_write(void *opaque, hwaddr addr,
  uint8_t buf[4];
  
  #if defined(DEBUG_SUBPAGE)
 -printf(%s: subpage %p len %d addr  TARGET_FMT_plx
 +printf(%s: subpage %p len %u addr  TARGET_FMT_plx
  value %PRIx64\n,
 __func__, subpage, len, addr, value);
  #endif
 @@ -1617,16 +1617,16 @@ static void subpage_write(void *opaque, hwaddr addr,
  }
  
  static bool subpage_accepts(void *opaque, hwaddr addr,
 -unsigned size, bool is_write)
 +unsigned len, bool is_write)
  {
  subpage_t *subpage = opaque;
  #if defined(DEBUG_SUBPAGE)
 -printf(%s: subpage %p %c len %d addr  TARGET_FMT_plx \n,
 +printf(%s: subpage %p %c len %u addr  TARGET_FMT_plx \n,
 __func__, subpage, is_write ? 'w' : 'r', len, addr);
  #endif
  
  return address_space_access_valid(subpage-as, addr + subpage-base,
 -  size, is_write);
 +  len, is_write);
  }
  
  static const MemoryRegionOps subpage_ops = {
 @@ -1646,8 +1646,8 @@ static int subpage_register (subpage_t *mmio, uint32_t 
 start, uint32_t end,
  idx = SUBPAGE_IDX(start);
  eidx = SUBPAGE_IDX(end);
  #if defined(DEBUG_SUBPAGE)
 -printf(%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n, 
 __func__,
 -   mmio, start, end, idx, eidx, memory);
 +printf(%s: %p start %08x end %08x idx %08x eidx %08x section %d\n,
 +   __func__, mmio, start, end, idx, eidx, section);
  #endif
  for (; idx = eidx; idx++) {
  mmio-sub_section[idx] = section;
 @@ -1668,8 +1668,8 @@ static subpage_t *subpage_init(AddressSpace *as, hwaddr 
 base)
subpage, TARGET_PAGE_SIZE);
  mmio-iomem.subpage = true;
  #if defined(DEBUG_SUBPAGE)
 -printf(%s: %p base  TARGET_FMT_plx  len %08x %d\n, __func__,
 -   mmio, base, TARGET_PAGE_SIZE, subpage_memory);
 +printf(%s: %p base  TARGET_FMT_plx  len %08x\n, __func__,
 +   mmio, base, TARGET_PAGE_SIZE);
  #endif
  subpage_register(mmio, 0, TARGET_PAGE_SIZE-1, PHYS_SECTION_UNASSIGNED);
  
 




Re: [Qemu-devel] Patch Round-up for stable 1.6.1, freeze on 2013-09-30

2013-09-27 Thread Michael Tokarev

26.09.2013 23:38, Stefan Weil пишет:

Am 25.09.2013 14:57, schrieb Michael Roth:

Hi everyone,

The following new patches are queued for QEMU stable v1.6.1:

https://github.com/mdroth/qemu/commits/stable-1.6-staging

The release is planned for 2013-10-02:

http://wiki.qemu.org/Planning/1.6

Please respond here or CC qemu-sta...@nongnu.org on any patches you
think should be included in the release. The cut-off date is
2013-09-30 for new patches.

Testing/feedback is greatly appreciated.

Thanks!



Please add this one from Michael Tokarev, too:
http://patchwork.ozlabs.org/patch/276560/


A small correction/nitpick: it is not from me originally,
it is from Wenchao Xia, but indeed, I verified and signed
it.


It fixes a compiler warning from MinGW-w32 gcc in QEMU 1.5.3.


I'm not sure it qualifies for -stable however, because it
merely fixes a compiler warning, the code is actually correct
both ways.  Ofcourse the compile with -Werror will fail with
SOME compilers/versions, but is it the only place where we
have warnings?

Thanks!

/mjt



Re: [Qemu-devel] [PATCH v3] kvm: add set_one_reg/get_one_reg helpers

2013-09-27 Thread Alexey Kardashevskiy
On 09/19/2013 12:45 PM, Alexey Kardashevskiy wrote:
 This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

Ping?


 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
 Changes:
 v3:
 * changed comments
 
 v2:
 * added Doc Comments
 * removed error_print
 ---
  include/sysemu/kvm.h | 21 +
  kvm-all.c| 18 ++
  2 files changed, 39 insertions(+)
 
 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index c7bc07b..9080ffe 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -319,4 +319,25 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, 
 EventNotifier *n, int virq);
  void kvm_pc_gsi_handler(void *opaque, int n, int level);
  void kvm_pc_setup_irq_routing(bool pci_enabled);
  void kvm_init_irq_routing(KVMState *s);
 +
 +/**
 + * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
 +/**
 + * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
  #endif
 diff --git a/kvm-all.c b/kvm-all.c
 index ded7fc8..cdc32ec 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -2049,3 +2049,21 @@ int kvm_on_sigbus(int code, void *addr)
  {
  return kvm_arch_on_sigbus(code, addr);
  }
 +
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
 +}
 +
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
 +}
 


-- 
Alexey



[Qemu-devel] [PATCH v7] powerpc: add PVR mask support

2013-09-27 Thread Alexey Kardashevskiy
IBM POWERPC processors encode PVR as a CPU family in higher 16 bits and
a CPU version in lower 16 bits. Since there is no significant change
in behavior between versions, there is no point to add every single CPU
version in QEMU's CPU list. Also, new CPU versions of already supported
CPU won't break the existing code.

This adds PVR value/mask support for KVM, i.e. for -cpu host option.

As CPU family class name for POWER7 is POWER7-family, there is no need
to touch aliases.

Cc: Andreas Färber afaer...@suse.de
Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

---
Changes:
v7:
* minor cleanups after Andreas Faerber comments

v6:
* family classes are abstract again
* POWER7+ moved to a separate patch as it also need a separate family
* added ppc_cpu_class_by_pvr_mask() which is a copy of
ppc_cpu_class_by_pvr() but compares PVRs with masks; this function is
called from KVM code only to support the -cpu host option; unlike
the original search function, the new one also includes abstract family
classes.

v5:
* removed pvr_default
* added hiding of family CPU classes (should not appear in -cpu ?)
* separated POWER7+ into a class (it used to be POWER7) and added a mask for it
* added mask for POWER8
* added _BASE suffix to PVR mask constants and moved them before actual CPUs

v4:
* removed bogus layer from hierarchy

v3:
* renamed macros to describe the functionality better
* added default PVR value for the powerpc cpu family (what alias used to do)

v2:
* aliases are replaced with another level in class hierarchy
---
 target-ppc/cpu-models.c |  1 +
 target-ppc/cpu-models.h |  5 +
 target-ppc/cpu-qom.h|  2 ++
 target-ppc/kvm.c|  4 
 target-ppc/translate_init.c | 44 
 5 files changed, 56 insertions(+)

diff --git a/target-ppc/cpu-models.c b/target-ppc/cpu-models.c
index 8dea560..04d88c5 100644
--- a/target-ppc/cpu-models.c
+++ b/target-ppc/cpu-models.c
@@ -44,6 +44,7 @@
 PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);   \
 \
 pcc-pvr  = _pvr;   \
+pcc-pvr_mask = CPU_POWERPC_DEFAULT_MASK;   \
 pcc-svr  = _svr;   \
 dc-desc  = _desc;  \
 }   \
diff --git a/target-ppc/cpu-models.h b/target-ppc/cpu-models.h
index d9145d1..731ec4a 100644
--- a/target-ppc/cpu-models.h
+++ b/target-ppc/cpu-models.h
@@ -39,6 +39,7 @@ extern PowerPCCPUAlias ppc_cpu_aliases[];
 /*/
 /* PVR definitions for most known PowerPC*/
 enum {
+CPU_POWERPC_DEFAULT_MASK   = 0x,
 /* PowerPC 401 family */
 /* Generic PowerPC 401 */
 #define CPU_POWERPC_401  CPU_POWERPC_401G2
@@ -552,10 +553,14 @@ enum {
 CPU_POWERPC_POWER6 = 0x003E,
 CPU_POWERPC_POWER6_5   = 0x0F01, /* POWER6 in POWER5 mode */
 CPU_POWERPC_POWER6A= 0x0F02,
+CPU_POWERPC_POWER7_BASE= 0x003F,
+CPU_POWERPC_POWER7_MASK= 0x,
 CPU_POWERPC_POWER7_v20 = 0x003F0200,
 CPU_POWERPC_POWER7_v21 = 0x003F0201,
 CPU_POWERPC_POWER7_v23 = 0x003F0203,
 CPU_POWERPC_POWER7P_v21= 0x004A0201,
+CPU_POWERPC_POWER8_BASE= 0x004B,
+CPU_POWERPC_POWER8_MASK= 0x,
 CPU_POWERPC_POWER8_v10 = 0x004B0100,
 CPU_POWERPC_970= 0x00390202,
 CPU_POWERPC_970FX_v10  = 0x00391100,
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index f3c710a..3f82629 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -54,6 +54,7 @@ typedef struct PowerPCCPUClass {
 void (*parent_reset)(CPUState *cpu);
 
 uint32_t pvr;
+uint32_t pvr_mask;
 uint32_t svr;
 uint64_t insns_flags;
 uint64_t insns_flags2;
@@ -99,6 +100,7 @@ static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
 #define ENV_OFFSET offsetof(PowerPCCPU, env)
 
 PowerPCCPUClass *ppc_cpu_class_by_pvr(uint32_t pvr);
+PowerPCCPUClass *ppc_cpu_class_by_pvr_mask(uint32_t pvr);
 
 void ppc_cpu_do_interrupt(CPUState *cpu);
 void ppc_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 715611a..4bc4496 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -1737,6 +1737,7 @@ static void kvmppc_host_cpu_class_init(ObjectClass *oc, 
void *data)
 uint32_t icache_size = kvmppc_read_int_cpu_dt(i-cache-size);
 
 /* Now fix up the class with information we can query from the host */
+pcc-pvr = mfpvr();
 
 if (vmx != -1) {
 /* Only override when we know 

[Qemu-devel] [PATCH] spapr: add compat machine option

2013-09-27 Thread Alexey Kardashevskiy
To be able to boot on newer hardware that the software support,
PowerISA defines a logical PVR, one per every PowerISA specification
version from 2.04.

This adds the compat option which takes values 205 or 206 and forces
QEMU to boot the guest with a logical PVR (CPU_POWERPC_LOGICAL_2_05 or
CPU_POWERPC_LOGICAL_2_06).

The guest reads the logical PVR value from cpu-version property of
a CPU device node.

Cc: Nikunj A Dadhania nik...@linux.vnet.ibm.com
Cc: Andreas Färber afaer...@suse.de
Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---
 hw/ppc/spapr.c  | 40 
 include/hw/ppc/spapr.h  |  2 ++
 target-ppc/cpu-models.h | 10 ++
 target-ppc/cpu.h|  3 +++
 target-ppc/kvm.c|  2 ++
 vl.c|  4 
 6 files changed, 61 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index a09a1d9..737452d 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -33,6 +33,7 @@
 #include sysemu/kvm.h
 #include kvm_ppc.h
 #include mmu-hash64.h
+#include cpu-models.h
 
 #include hw/boards.h
 #include hw/ppc/ppc.h
@@ -196,6 +197,26 @@ static XICSState *xics_system_init(int nr_servers, int 
nr_irqs)
 return icp;
 }
 
+static void spapr_compat_mode_init(sPAPREnvironment *spapr)
+{
+QemuOpts *machine_opts = qemu_get_machine_opts();
+uint64_t compat = qemu_opt_get_number(machine_opts, compat, 0);
+
+switch (compat) {
+case 0:
+break;
+case 205:
+spapr-arch_compat = CPU_POWERPC_LOGICAL_2_05;
+break;
+case 206:
+spapr-arch_compat = CPU_POWERPC_LOGICAL_2_06;
+break;
+default:
+perror(Unsupported mode, only are 205, 206 supported\n);
+break;
+}
+}
+
 static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
 {
 int ret = 0, offset;
@@ -206,6 +227,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment 
*spapr)
 
 CPU_FOREACH(cpu) {
 DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+CPUPPCState *env = (POWERPC_CPU(cpu)-env);
 uint32_t associativity[] = {cpu_to_be32(0x5),
 cpu_to_be32(0x0),
 cpu_to_be32(0x0),
@@ -238,6 +260,14 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment 
*spapr)
 if (ret  0) {
 return ret;
 }
+
+if (env-arch_compat) {
+ret = fdt_setprop(fdt, offset, cpu-version,
+  env-arch_compat, sizeof(env-arch_compat));
+if (ret  0) {
+return ret;
+}
+}
 }
 return ret;
 }
@@ -1145,6 +1175,8 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 spapr = g_malloc0(sizeof(*spapr));
 QLIST_INIT(spapr-phbs);
 
+spapr_compat_mode_init(spapr);
+
 cpu_ppc_hypercall = emulate_spapr_hypercall;
 
 /* Allocate RMA if necessary */
@@ -1226,6 +1258,14 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
 xics_cpu_setup(spapr-icp, cpu);
 
+/*
+ * If compat mode is set in the command line, pass it to CPU so KVM
+ * will be able to set it in the host kernel.
+ */
+if (spapr-arch_compat) {
+env-arch_compat = spapr-arch_compat;
+}
+
 qemu_register_reset(spapr_cpu_reset, cpu);
 }
 
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index ca175b0..201c578 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -34,6 +34,8 @@ typedef struct sPAPREnvironment {
 uint32_t epow_irq;
 Notifier epow_notifier;
 
+uint32_t arch_compat;/* Compatible PVR from the command line */
+
 /* Migration state */
 int htab_save_index;
 bool htab_first_pass;
diff --git a/target-ppc/cpu-models.h b/target-ppc/cpu-models.h
index 49ba4a4..d7c033c 100644
--- a/target-ppc/cpu-models.h
+++ b/target-ppc/cpu-models.h
@@ -583,6 +583,16 @@ enum {
 CPU_POWERPC_RS64II = 0x0034,
 CPU_POWERPC_RS64III= 0x0036,
 CPU_POWERPC_RS64IV = 0x0037,
+
+/* Logical CPUs */
+CPU_POWERPC_LOGICAL_MASK   = 0x,
+CPU_POWERPC_LOGICAL_2_04   = 0x0F01,
+CPU_POWERPC_LOGICAL_2_05   = 0x0F02,
+CPU_POWERPC_LOGICAL_2_06   = 0x0F03,
+CPU_POWERPC_LOGICAL_2_06_PLUS  = 0x0F13,
+CPU_POWERPC_LOGICAL_2_07   = 0x0F04,
+CPU_POWERPC_LOGICAL_2_08   = 0x0F05,
+
 #endif /* defined(TARGET_PPC64) */
 /* Original POWER */
 /* XXX: should be POWER (RIOS), RSC3308, RSC4608,
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 422a6bb..fc837c1 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -999,6 +999,9 @@ struct CPUPPCState {
 /* Device control registers */
 ppc_dcr_t *dcr_env;
 
+/* Architecture compatibility mode */
+uint32_t arch_compat;
+
 int dcache_line_size;
 int icache_line_size;
 
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 

Re: [Qemu-devel] [Qemu-stable] Patch Round-up for stable 1.6.1, freeze on 2013-09-30

2013-09-27 Thread Michael Tokarev

25.09.2013 16:57, Michael Roth wrote:

Hi everyone,

The following new patches are queued for QEMU stable v1.6.1:

https://github.com/mdroth/qemu/commits/stable-1.6-staging


It looks like at least some stuff from the series

 http://thread.gmane.org/gmane.comp.emulators.qemu/234440

is also needed for 1.6.1, because this series fixes CVE-2013-4377
(see https://bugzilla.redhat.com/show_bug.cgi?id=1012633 ).

Paolo, may you help to provide the fix for 1.6 for this?

Thanks,

/mjt



[Qemu-devel] [PATCH v3] spapr-rtas: fix h_rtas parameters reading

2013-09-27 Thread Alexey Kardashevskiy
On the real hardware, RTAS is called in real mode and therefore
top 4 bits of the address passed in the call are ignored.
So does the patch.

This converts h_rtas() to use existing rtas_ld() handlers.

This fixed rtas_ld()/rtas_st() to ignore top 4 bits.

Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---
Changes:
v3:
* ldl_be_phys() replaced with rtas_ld() which is already there
* rtas_ld()/rtas_st() fixed to chop top 4 bits

v2:
* masking from replaced with the use of cpu_ldl_data which can handle
realmode case properly
---
 hw/ppc/spapr_hcall.c   | 6 +++---
 include/hw/ppc/spapr.h | 9 +++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index b3bc2ea..7f07409 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -523,9 +523,9 @@ static target_ulong h_rtas(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
target_ulong opcode, target_ulong *args)
 {
 target_ulong rtas_r3 = args[0];
-uint32_t token = ldl_be_phys(rtas_r3);
-uint32_t nargs = ldl_be_phys(rtas_r3 + 4);
-uint32_t nret = ldl_be_phys(rtas_r3 + 8);
+uint32_t token = rtas_ld(rtas_r3, 0);
+uint32_t nargs = rtas_ld(rtas_r3, 1);
+uint32_t nret = rtas_ld(rtas_r3, 2);
 
 return spapr_rtas_call(cpu, spapr, token, nargs, rtas_r3 + 12,
nret, rtas_r3 + 12 + 4*nargs);
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 8c1d4a2..3731262 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -340,14 +340,19 @@ static inline int spapr_allocate_lsi(int hint)
 return spapr_allocate_irq(hint, true);
 }
 
+static inline uint64_t ppc64_phys_to_real(uint64_t addr)
+{
+return addr  ~0xF000ULL;
+}
+
 static inline uint32_t rtas_ld(target_ulong phys, int n)
 {
-return ldl_be_phys(phys + 4*n);
+return ldl_be_phys(ppc64_phys_to_real(phys + 4*n));
 }
 
 static inline void rtas_st(target_ulong phys, int n, uint32_t val)
 {
-stl_be_phys(phys + 4*n, val);
+stl_be_phys(ppc64_phys_to_real(phys + 4*n), val);
 }
 
 typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
-- 
1.8.4.rc4




Re: [Qemu-devel] [Qemu-stable] Patch Round-up for stable 1.6.1, freeze on 2013-09-30

2013-09-27 Thread Michael Tokarev

27.09.2013 12:07, Michael Tokarev пишет:

25.09.2013 16:57, Michael Roth wrote:

Hi everyone,

The following new patches are queued for QEMU stable v1.6.1:

https://github.com/mdroth/qemu/commits/stable-1.6-staging


It looks like at least some stuff from the series

  http://thread.gmane.org/gmane.comp.emulators.qemu/234440

is also needed for 1.6.1, because this series fixes CVE-2013-4377
(see https://bugzilla.redhat.com/show_bug.cgi?id=1012633 ).

Paolo, may you help to provide the fix for 1.6 for this?


This whole series is Cc: qemu-stable@, I haven't noticed that
before... ;)

Thanks,

/mjt





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

2013-09-27 Thread Alex Bennée

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?

  
 +//#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.

  #define TYPE_KVM_ARM_GIC kvm-arm-gic
  #define KVM_ARM_GIC(obj) \
   OBJECT_CHECK(GICState, (obj), TYPE_KVM_ARM_GIC)
 @@ -72,14 +87,419 @@ static void kvm_arm_gic_set_irq(void *opaque, int irq, 
 int level)
  kvm_set_irq(kvm_state, kvm_irq, !!level);
  }
  
 +static bool kvm_arm_gic_can_save_restore(GICState *s)
 +{
 +return s-dev_fd = 0;
 +}
 +
 +static void kvm_gic_access(GICState *s, int group, int offset,
 +   int cpu, uint32_t *val, bool write)
 +{
 +struct kvm_device_attr attr;
 +int type;
 +int err;
 +
 +cpu = cpu  0xff;
 +
 +attr.flags = 0;
 +attr.group = group;
 +attr.attr = (((uint64_t)cpu  KVM_DEV_ARM_VGIC_CPUID_SHIFT) 
 + KVM_DEV_ARM_VGIC_CPUID_MASK) |
 +(((uint64_t)offset  KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 
 + KVM_DEV_ARM_VGIC_OFFSET_MASK);
 +attr.addr = (uintptr_t)val;
 +
 +if (write) {
 +type = KVM_SET_DEVICE_ATTR;
 +} else {
 +type = KVM_GET_DEVICE_ATTR;
 +}
 +
 +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();
 +}
 +}
 +
 +static void kvm_gicd_access(GICState *s, int offset, int cpu,
 +uint32_t *val, bool write)
 +{
 +kvm_gic_access(s, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
 +   offset, cpu, val, write);
 +}
 +
 +static void kvm_gicc_access(GICState *s, int offset, int cpu,
 +uint32_t *val, bool write)
 +{
 +kvm_gic_access(s, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
 +   offset, cpu, val, write);
 +}
 +
 +#define for_each_irq_reg(_ctr, _max_irq, _field_width) \
 +for (_ctr = 0; _ctr  ((_max_irq) / (32 / (_field_width))); _ctr++)
 +
 +/*
 + * Translate from the in-kernel field for an IRQ value to/from the qemu
 + * representation.
 + */
 +typedef void (*vgic_translate_fn)(GICState *s, int irq, int cpu,
 +  uint32_t *field, bool to_kernel);
 +
 +/* synthetic translate function used for clear/set registers to completely
 + * clear a setting using a clear-register before setting the remaing bits
 + * using a set-register */
 +static void translate_clear(GICState *s, int irq, int cpu,
 +uint32_t *field, bool to_kernel)
 +{
 +if (to_kernel) {
 +*field = ~0;
 +} else {
 +/* does not make sense: qemu model doesn't use set/clear regs */
 +abort();
 +}
 +}
 +
 +static void translate_enabled(GICState *s, int irq, int cpu,
 +  uint32_t *field, bool to_kernel)
 +{
 +int cm = (irq  GIC_INTERNAL) ? (1  cpu) : ALL_CPU_MASK;
 +
 +if (to_kernel) {
 +*field = GIC_TEST_ENABLED(irq, cm);
 +} else {
 +if (*field  1) {
 +GIC_SET_ENABLED(irq, cm);
 +}
 +}
 +}
 +
 +static void translate_pending(GICState *s, int irq, int cpu,
 +  uint32_t *field, bool to_kernel)
 +{
 +int cm = (irq  GIC_INTERNAL) ? (1  cpu) : ALL_CPU_MASK;
 +
 +if (to_kernel) {
 +*field = GIC_TEST_PENDING(irq, cm);
 +} else {
 +if (*field  1) {
 +GIC_SET_PENDING(irq, cm);
 +/* TODO: Capture is level-line is held high in the kernel */
 +}
 +}
 +}
 +
 +static void translate_active(GICState *s, int irq, int cpu,
 + uint32_t *field, bool to_kernel)
 +{
 +int cm = (irq  GIC_INTERNAL) ? (1  cpu) : ALL_CPU_MASK;
 +
 +if (to_kernel) {
 +*field = GIC_TEST_ACTIVE(irq, cm);
 +} else {
 +if (*field  1) {

Should 1, 0x2 etc be #define'd constants?

snip
  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);
 +

[Qemu-devel] [PATCH] qcow2: Free only newly allocated clusters on error

2013-09-27 Thread Max Reitz
In expand_zero_clusters_in_l1, a new cluster is only allocated if it was
not already preallocated. On error, such preallocated clusters should
not be freed, but only the newly allocated ones.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2-cluster.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cab5f2e..077b42b 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1551,6 +1551,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState 
*bs, uint64_t *l1_table,
 uint64_t l2_entry = be64_to_cpu(l2_table[j]);
 int64_t offset = l2_entry  L2E_OFFSET_MASK, cluster_index;
 int cluster_type = qcow2_get_cluster_type(l2_entry);
+bool preallocated = offset != 0;
 
 if (cluster_type == QCOW2_CLUSTER_NORMAL) {
 cluster_index = offset  s-cluster_bits;
@@ -1576,8 +1577,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState 
*bs, uint64_t *l1_table,
 continue;
 }
 
-if (!offset) {
-/* not preallocated */
+if (!preallocated) {
 if (!bs-backing_hd) {
 /* not backed; therefore we can simply deallocate the
  * cluster */
@@ -1596,16 +1596,20 @@ static int expand_zero_clusters_in_l1(BlockDriverState 
*bs, uint64_t *l1_table,
 ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
 offset, s-cluster_size);
 if (ret  0) {
-qcow2_free_clusters(bs, offset, s-cluster_size,
-QCOW2_DISCARD_ALWAYS);
+if (!preallocated) {
+qcow2_free_clusters(bs, offset, s-cluster_size,
+QCOW2_DISCARD_ALWAYS);
+}
 goto fail;
 }
 
 ret = bdrv_write_zeroes(bs-file, offset / BDRV_SECTOR_SIZE,
 s-cluster_sectors);
 if (ret  0) {
-qcow2_free_clusters(bs, offset, s-cluster_size,
-QCOW2_DISCARD_ALWAYS);
+if (!preallocated) {
+qcow2_free_clusters(bs, offset, s-cluster_size,
+QCOW2_DISCARD_ALWAYS);
+}
 goto fail;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v2] spapr: Add ibm, purr property on power7 and newer

2013-09-27 Thread Alexey Kardashevskiy
PAPR+ says that no ibm,purr tells the guest that H_PURR is not
supported. However some guests still try calling H_PURR on POWER7 unless
the property is present and equal to 0. This adds the property for CPUs
supporting the PURR special register.

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---
Changes:
v2:
* the property is set now if PURR register is supported by QEMU
(at the moment it is POWER7, POWER7+, POWER8)
---
 hw/ppc/spapr.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index bca91d9..07ff4cf 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -485,6 +485,10 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
 _FDT((fdt_property(fdt, ibm,ppc-interrupt-gserver#s,
gservers_prop, sizeof(gservers_prop;
 
+if (env-spr_cb[SPR_PURR].oea_read) {
+_FDT((fdt_property(fdt, ibm,purr, NULL, 0)));
+}
+
 if (env-mmu_model  POWERPC_MMU_1TSEG) {
 _FDT((fdt_property(fdt, ibm,processor-segment-sizes,
segs, sizeof(segs;
-- 
1.8.4.rc4




Re: [Qemu-devel] [PATCH] icount: disable icount with multiprocessor guests

2013-09-27 Thread Paolo Bonzini
Il 25/09/2013 01:39, Peter Maydell ha scritto:
 On 25 September 2013 00:52, Paolo Bonzini pbonz...@redhat.com wrote:
 If -icount is enabled with multiprocessor guests, all CPUs increment
 the same counter, which then basically runs too fast by a factor of
 smp_cpus.  This makes little sense and complicates further a feature
 whose implementation is pretty obscure already.
 
 Just forbidding -icount with SMP configs seems like the wrong
 fix, though -- why wouldn't you want the deterministic execution
 icount (claims it) gives you with an SMP config?

Right now, the SMP version of icount is all but deterministic.  I/O and
rt_clock timers cause the TCG thread to relinquish the BQL, and the
round-robin will switch to the next VCPU.  Perhaps once the TCG loop
breaks free of the BQL we can modify icount to trigger a VCPU switch
every 2^16 instructions or something like that, and revert this patch.

Paolo



Re: [Qemu-devel] [PATCH] spapr: Add support for hwrng when available

2013-09-27 Thread Michael Ellerman
On Thu, 2013-09-26 at 13:06 +0200, Alexander Graf wrote:
 On 26.09.2013, at 08:37, Michael Ellerman wrote:
 
  Some powerpc systems have support for a hardware random number generator
  (hwrng). If such a hwrng is present the host kernel can provide access
  to it via the H_RANDOM hcall.
  
  The kernel advertises the presence of a hwrng with the KVM_CAP_PPC_HWRNG
  capability. If this is detected we add the appropriate device tree bits
  to advertise the presence of the hwrng to the guest kernel.
  
  Signed-off-by: Michael Ellerman mich...@ellerman.id.au
 
 Please implement this 100% without KVM first, then if we end up running into 
 performance bottlenecks we can always add KVM acceleration.

So have the host kernel read from the hwrng, export it to userspace via
a char device, which is then read by qemu, which then copies it back
into the host kernel, which can then give it to the guest.

Or from the guest perspective, instead of a cheap switch to host real
mode and back - a full switch to kernel virtual, then to user, back to
kernel, back to user, back to kernel, back to guest.

Frankly I can't see why that is a superior option?


 Also, please make sure to CC qemu-...@nongnu.org on PPC patches :).

Sorry, didn't realise there was one, will add it in future.

cheers






Re: [Qemu-devel] Qxl problem with xen domU, is xen spice and/or qemu bugs?

2013-09-27 Thread Gerd Hoffmann
  Hi,

  #2 When using f19 try without X11 first.  You should have a working
  framebuffer console on qxldrmfb before trying to get X11 going.
 
  I tried on Fedora19 minimal installation and with qxl the text console 
  is working and lsmod show also qxl.

Good, so the kernel driver is running fine.

  Is this your intended?

Yes.

  #3 qxl has a bunch of tracepoints.  Enable them, then compare xen
  results with kvm/tcg results to see where things start going wrong.
 
  I enabled qxl debug with these qemu paramters:
  -global qxl-vga.debug=1 -global qxl-vga.guestdebug=20

debug=1 doesn't do much, most is in tracepoints these days.  I'm using
the stderr tracer most of the time (enable it using configure).  Then
you can turn on qxl_* either in monitor (trace-events command) or via
-trace events=file-with-event-names.

  I tried to test Fedora19 on debian sid kvm host same qemu version 
  (1.6) on both sides but with qxl fails to start the DE, also in 
  fallback mode. Probably there are also regression on qemu and/or spice 
  about qxl.

I'm not aware of any regressions.
I'd suggest to try latest spice-server release.

HTH,
  Gerd






Re: [Qemu-devel] qemu-img create: set nocow flag to solve performance issue on btrfs

2013-09-27 Thread Chun Yan Liu


 On 9/27/2013 at 12:56 AM, in message 5244673f.4000...@redhat.com, Paolo
Bonzini pbonz...@redhat.com wrote: 
 Il 26/09/2013 12:30, Chunyan Liu ha scritto: 
   
   
   
  2013/9/26 Paolo Bonzini pbonz...@redhat.com mailto:pbonz...@redhat.com 
   
  Il 26/09/2013 09:58, Stefan Hajnoczi ha scritto: 
   On Wed, Sep 25, 2013 at 02:38:36PM +0800, Chunyan Liu wrote: 
   Btrfs has terrible performance when hosting VM images, even more 
  when the 
   guest in those VM are also using btrfs as file system. 
   One way to mitigate this bad performance would be to turn off COW 
   attributes on VM files (since having copy on write for this kind 
  of data is 
   not useful). We could improve qemu-img to ensure they flag newly 
  created 
   images as nocow. For those who want to use Copy-on-write (for 
   snapshotting, to share snapshots across VM, etc..) could be able 
  to change 
   this behaviour by 'chattr', either globally or per VM. 
   
   The full implications of the NOCOW attribute aren't clear to me.  
  Does 
   it really mean the file cannot be snapshotted?  Or is it purely a 
  data 
   integrity issue where overwriting data in-place puts that data at 
  risk 
   in case of hardware/power failure? 
   
   I wonder could we add a patch to improve qemu-img create, to set 
  'nocow' 
   flag by default on newly created images? 
   
   I think that would be fine.  It's a ioctl(FS_IOC_SETFLAGS, 
  FS_NOCOW_FL) 
   call so not even too btrfs-specific. 
   
  I'm not sure...  I have some questions: 
   
  1) Does btrfs cow mean that one could run with cache=unsafe, for 
  example?  If we create the image with nocow, this would not be true. 
   
  I don't know if I understand correctly. I think you mentioned 
  cache=unsafe here, due to the snapshot function? cache=unsafe could 
  enhance snapshot performance. But btrfs snapshot (btrfs subvolume 
  snapshot xx xx) and qemu snapshot function are two different levels. 
  With cow attribute, btrfs snapshot could be achieved very easily. With 
  nocow attribute, the btrfs snapshot function should be not working on 
  the file. 
  
 Does COW preserve the order of writes even after a power loss (i.e. you 
 might lose a write, but then you will always lose all the ones that come 
 after it)? 

Yes, I think so. COW could make sure at any time its FS tree points to a valid 
root (has all data in a consistent status), if due to the power loss, write 
task is not completed, it still points to the older root; if write task is 
completed, it will points to a new root. No matter in which case, it is a 
consistent status.

 If so, you could run QEMU with cache=unsafe and have
 basically the same data safety guarantees as cache=writeback on every 
 other file system. 

cache=unsafe means it never calls fsync() ? If so, it seems to be not proper 
to use this option to disk image of a running VM. In case someone has run the 
VM for a very long time and made many changes already on the disk image, but 
all those are in cache (?) Then due to a power off, all these changes are lost. 
Although the disk image is still in a consistent data status, but the data is 
maybe too old.

- Chunyan
  
 Similarly, you could use cache.no-flush=true,cache.direct=true instead 
 of cache=none. 
  
 Paolo 
  
  




Re: [Qemu-devel] [PATCH] spapr: Add support for hwrng when available

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 10:36, Michael Ellerman ha scritto:
 So have the host kernel read from the hwrng, export it to userspace via
 a char device, which is then read by qemu, which then copies it back
 into the host kernel, which can then give it to the guest.
 
 Or from the guest perspective, instead of a cheap switch to host real
 mode and back - a full switch to kernel virtual, then to user, back to
 kernel, back to user, back to kernel, back to guest.
 
 Frankly I can't see why that is a superior option?

Because this is not a fast path at all.  Doing things in QEMU lets
people test and configure the paravirtualized hwrng even if they do not
have a hwrng in the host, and even if they are running with emulation
(TCG) instead of KVM.

But as I mentioned in the kernel thread, perhaps you do not need the
hypercall at all if virtio-rng is enough (it should be for Linux guests).

Paolo



Re: [Qemu-devel] [PATCH v3] kvm: add set_one_reg/get_one_reg helpers

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 10:02, Alexey Kardashevskiy ha scritto:
 On 09/19/2013 12:45 PM, Alexey Kardashevskiy wrote:
 This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.
 
 Ping?
 
 

 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
 Changes:
 v3:
 * changed comments

 v2:
 * added Doc Comments
 * removed error_print
 ---
  include/sysemu/kvm.h | 21 +
  kvm-all.c| 18 ++
  2 files changed, 39 insertions(+)

 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index c7bc07b..9080ffe 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -319,4 +319,25 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, 
 EventNotifier *n, int virq);
  void kvm_pc_gsi_handler(void *opaque, int n, int level);
  void kvm_pc_setup_irq_routing(bool pci_enabled);
  void kvm_init_irq_routing(KVMState *s);
 +
 +/**
 + * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
 +/**
 + * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
  #endif
 diff --git a/kvm-all.c b/kvm-all.c
 index ded7fc8..cdc32ec 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -2049,3 +2049,21 @@ int kvm_on_sigbus(int code, void *addr)
  {
  return kvm_arch_on_sigbus(code, addr);
  }
 +
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
 +}
 +
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
 +}

 
 

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

Include it with the acked-by together with the first patch that needs
it.  Alex can pick it up.

Paolo



Re: [Qemu-devel] qemu-img create: set nocow flag to solve performance issue on btrfs

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 10:58, Chun Yan Liu ha scritto:
 If so, you could run QEMU with cache=unsafe and have
 basically the same data safety guarantees as cache=writeback on
 every other file system.
 cache=unsafe means it never calls fsync() ?

Yes.  However, metadata writes are still done and ordered correctly with
respect to data writes.

 If so, it seems to be
 not proper to use this option to disk image of a running VM. In case
 someone has run the VM for a very long time and made many changes
 already on the disk image, but all those are in cache (?) Then due to
 a power off, all these changes are lost. Although the disk image is
 still in a consistent data status, but the data is maybe too old.

Perhaps for btrfs-cow a different strategy is better, with fsyncs
coalesced and issued by QEMU every N seconds.

Paolo



Re: [Qemu-devel] [PATCH v3] kvm: add set_one_reg/get_one_reg helpers

2013-09-27 Thread Alexey Kardashevskiy
On 09/27/2013 06:59 PM, Paolo Bonzini wrote:
 Il 27/09/2013 10:02, Alexey Kardashevskiy ha scritto:
 On 09/19/2013 12:45 PM, Alexey Kardashevskiy wrote:
 This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

 Ping?



 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
 Changes:
 v3:
 * changed comments

 v2:
 * added Doc Comments
 * removed error_print
 ---
  include/sysemu/kvm.h | 21 +
  kvm-all.c| 18 ++
  2 files changed, 39 insertions(+)

 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index c7bc07b..9080ffe 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -319,4 +319,25 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, 
 EventNotifier *n, int virq);
  void kvm_pc_gsi_handler(void *opaque, int n, int level);
  void kvm_pc_setup_irq_routing(bool pci_enabled);
  void kvm_init_irq_routing(KVMState *s);
 +
 +/**
 + * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
 +/**
 + * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG 
 ioctl
 + * @id: The register ID
 + * @addr: The pointer to a value must point to a variable of the correct
 + * type/size for the register being accessed.
 + *
 + * Returns: 0 on success, or a negative errno on failure.
 + */
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);
 +
  #endif
 diff --git a/kvm-all.c b/kvm-all.c
 index ded7fc8..cdc32ec 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -2049,3 +2049,21 @@ int kvm_on_sigbus(int code, void *addr)
  {
  return kvm_arch_on_sigbus(code, addr);
  }
 +
 +int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
 +}
 +
 +int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
 +}



 
 Acked-by: Paolo Bonzini pbonz...@redhat.com
 
 Include it with the acked-by together with the first patch that needs
 it.  Alex can pick it up.


Why to wait?

Alex, please pick it up.

The first patch which needs it is [PATCH] spapr: add compat machine
option, posted earlier today.



-- 
Alexey



Re: [Qemu-devel] [PATCH] coroutine: add ./configure --disable-coroutine-pool

2013-09-27 Thread Stefan Hajnoczi
On Fri, Sep 27, 2013 at 07:20:21AM +0200, Stefan Weil wrote:
 Am 11.09.2013 16:42, schrieb Stefan Hajnoczi:
  The 'gthread' coroutine backend was written before the freelist (aka
  pool) existed in qemu-coroutine.c.
 
  This means that every thread is expected to exit when its coroutine
  terminates.  It is not possible to reuse threads from a pool.
 
  This patch automatically disables the pool when 'gthread' is used.  This
  allows the 'gthread' backend to work again (for example,
  tests/test-coroutine completes successfully instead of hanging).
 
  I considered implementing thread reuse but I don't want quirks like CPU
  affinity differences due to coroutine threads being recycled.  The
  'gthread' backend is a reference backend and it's therefore okay to skip
  the pool optimization.
 
  Note this patch also makes it easy to toggle the pool for benchmarking
  purposes:
 
./configure --with-coroutine-backend=ucontext \
--disable-coroutine-pool
 
  Reported-by: Gabriel Kerneis gabr...@kerneis.info
  Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
  ---
   configure| 24 
   qemu-coroutine.c | 34 +++---
   2 files changed, 43 insertions(+), 15 deletions(-)
 
 
 This patch is important for QEMU 1.5 as well, but needs some
 modifications there.
 A recent bug report for MinGW shows that the win32 coroutine needs it, too.

coroutine-win32.c is designed to support reuse:

static void CALLBACK coroutine_trampoline(void *co_)
{
Coroutine *co = co_;

while (true) {
co-entry(co-entry_arg);
qemu_coroutine_switch(co, co-caller, COROUTINE_TERMINATE);
}
}

We return from qemu_coroutine_switch() when the fiber is reused and
simply run another iteration of the while loop.

Why do you say win32 coroutines should disable the pool?

Stefan



Re: [Qemu-devel] [PATCH v3 2/3] block: qemu-iotests for vhdx, read sample dynamic image

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 14:12 hat Jeff Cody geschrieben:
 This adds the VHDX format to the qemu-iotests format, and adds
 a read test.  The test reads from an existing sample image, that
 was created with Hyper-V under Windwos Server 2012.
 
 The image file is a 1GB dynamic image, with 32MB blocks.
 
 The pattern 0xa5 exists from 0MB-33MB (past a block size boundary)
 
 The pattern 0x96 exists from 33MB-66MB (past another block boundary,
 and leaving a partial blank block)
 
 From 66MB-1024MB, all reads should return 0.
 
 Although 1GB dynamic image with 66MB of data, the bzip2'ed image
 file size is only 874 bytes.
 
 Signed-off-by: Jeff Cody jc...@redhat.com
 Reviewed-by: Stefan Hajnoczi stefa...@redhat.com

 diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
 new file mode 100644
 index 000..b9e8e4a
 --- /dev/null
 +++ b/tests/qemu-iotests/064.out
 @@ -0,0 +1,14 @@
 +QA output created by 064
 +
 +=== Verify pattern 0xa5, 0 - 33MB ===
 +read 34603008/34603008 bytes at offset 0
 +33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +
 +=== Verify pattern 0x96, 33M - 66M ===
 +read 34603008/34603008 bytes at offset 34603008
 +33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +
 +=== Verify pattern 0x00, 66M - 1024M ===
 +read 1004535808/1004535808 bytes at offset 69206016
 +958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +*** done

Doesn't work for me. Am I missing patches that need to be applied first?

064 1s ...[11:09:58] [11:09:59] - output mismatch (see 064.out.bad)
--- 064.out 2013-09-27 11:00:37.077677734 +0200
+++ 064.out.bad 2013-09-27 11:09:59.704298133 +0200
@@ -1,14 +1,14 @@
 QA output created by 064
 
 === Verify pattern 0xa5, 0 - 33MB ===
-read 34603008/34603008 bytes at offset 0
-33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-io: can't open device 
/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
Could not open 
'/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
Operation not supported
+no file open, try 'help open'
 
 === Verify pattern 0x96, 33M - 66M ===
-read 34603008/34603008 bytes at offset 34603008
-33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-io: can't open device 
/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
Could not open 
'/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
Operation not supported
+no file open, try 'help open'
 
 === Verify pattern 0x00, 66M - 1024M ===
-read 1004535808/1004535808 bytes at offset 69206016
-958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-io: can't open device 
/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
Could not open 
'/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
Operation not supported
+no file open, try 'help open'
 *** done

Kevin



Re: [Qemu-devel] [PATCH v3 0/3] qemu-iotests with sample images, vhdx test, cleanup

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 14:12 hat Jeff Cody geschrieben:
 Changes in v3:
 One line in patch 3, for test 043: $TEST_IMG.[123].base instead of
 $TEST_IMG.[123].base.  Thanks Stefan.
 
 Added Stefan's Reviewed-by to the patches.
 
 Changes in v2:
 
 Patch 1: MANIFEST file dropped.  Instead of bunzip2, use bzcat.  Check error
  return of bzcat.  Don't attempt to remove $SAMPLE_IMG_FILE if the
  variable is blank.
 
 Patch 2: MANIFEST file dropped.
 
 Patch 3: New patch.  This adds some cleanup in the format of quotations around
  filenames and paths in the io tests.
 
 This provides:
 
 Patch 1/3:  A basic framework for using sample image files.  This is intended
 to be sample images created with the image format native tool; 
 e.g.
 a VHDX image created with Hyper-V.
 
 Patch 2/3:  VHDX read test on a sample image created with Hyper-V.
 
 Patch 3/3:  Quote around usage of $TEST_IMG and $TEST_DIR, so that pathnames
 and filenames with spaces can safely be used.

Thanks, applied patches 1 and 3.

Kevin



Re: [Qemu-devel] [PATCH 0/2] Correct bitmap size in zero cluster expansion

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 12:07 hat Max Reitz geschrieben:
 The current version of the zero cluster expansion uses the guest disk
 size for determining the size of the expanded_clusters bitmap, however,
 it is addressed using host offsets. This leads to an assertion failing if
 the host image size exceeds the guest disk size. This is fixed by using
 the host image size instead for allocating the bitmap.
 
 This however uncovers another problem: If the host image is growable, it
 may grow during the zero cluster expansion due to cluster allocations. If
 this happens, the bitmap has to be resized accordingly.
 
 Max Reitz (2):
   qcow2: Correct bitmap size in zero expansion
   qemu-iotests: Preallocated zero clusters in 061
 
  block/qcow2-cluster.c  | 38 +++---
  tests/qemu-iotests/061 |  9 +
  tests/qemu-iotests/061.out | 11 +++
  3 files changed, 47 insertions(+), 11 deletions(-)

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH] qcow2: count_contiguous_clusters and compression

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 17:47 hat Max Reitz geschrieben:
 The function is not intended to be used on compressed clusters and will
 not work correctly, if used anyway, since L2E_OFFSET_MASK is not the
 right mask for determining the offset of compressed clusters. Therefore,
 assert that the first cluster is not compressed and always include the
 compression flag in the mask of significant flags, i.e., stop the search
 as soon as a compressed cluster occurs.
 
 Signed-off-by: Max Reitz mre...@redhat.com

This is supposed to be a cleanup patch with no functional change, right?
How about removing explicit QCOW_OFLAG_COMPRESSED arguments from
callers?

Kevin



Re: [Qemu-devel] [PATCH v5 00/23] qemu: generate acpi tables for the guest

2013-09-27 Thread Gerd Hoffmann
  Hi,

 ACPI gives a way to do this: supply PBlockLength = 0.
 
 I applied the following: though this means bytecode
 is not 1:1 identical to what we have with seabios,
 so I will keep it as a separate commit.

Sure.

Retested -- works fine now with both seabios + coreboot.
Glad to see this finally working out nicely.

cheers,
  Gerd






Re: [Qemu-devel] [PATCH v3] kvm: add set_one_reg/get_one_reg helpers

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 11:08, Alexey Kardashevskiy ha scritto:
  Include it with the acked-by together with the first patch that needs
  it.  Alex can pick it up.
 
 Why to wait?
 
 Alex, please pick it up.
 
 The first patch which needs it is [PATCH] spapr: add compat machine
 option, posted earlier today.

Perfect.  I just didn't want to force Alex to wait for the next pull
request from me or Gleb.

Paolo



Re: [Qemu-devel] [PATCH 0/3] qcow2: Small error path fixes for l2_allocate

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 16:37 hat Max Reitz geschrieben:
 Errors in l2_allocate should always go down the error path. If this path
 is taken, the newly allocated L2 cluster is abandoned and should thus be
 freed. The L2 table on the other hand should only be put back into the
 cache if it was taken from it before.
 
 Max Reitz (3):
   qcow2: Don't put invalid L2 table into cache
   qcow2: Free allocated L2 cluster on error
   qcow2: Always use error path in l2_allocate
 
  block/qcow2-cluster.c | 15 +++
  1 file changed, 11 insertions(+), 4 deletions(-)

Thanks, applied all to the block branch.

Kevin



Re: [Qemu-devel] [PATCH] qcow2: Free only newly allocated clusters on error

2013-09-27 Thread Kevin Wolf
Am 27.09.2013 um 10:21 hat Max Reitz geschrieben:
 In expand_zero_clusters_in_l1, a new cluster is only allocated if it was
 not already preallocated. On error, such preallocated clusters should
 not be freed, but only the newly allocated ones.
 
 Signed-off-by: Max Reitz mre...@redhat.com

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH V2] block: Add BlockDriver.bdrv_check_ext_snapshot.

2013-09-27 Thread Kevin Wolf
Am 26.09.2013 um 18:48 hat Jeff Cody geschrieben:
 On Thu, Sep 26, 2013 at 04:33:49PM +0200, Benoît Canet wrote:
  This field is used by blkverify to disable external snapshots creation.
  I will also be used by block filters like quorum to disable external 
  snapshots
  creation.
  
  Signed-off-by: Benoit Canet ben...@irqsave.net
  ---
   block.c   | 14 ++
   block/blkverify.c |  2 ++
   blockdev.c|  5 +
   include/block/block.h |  7 +++
   include/block/block_int.h |  8 
   5 files changed, 36 insertions(+)
  
  diff --git a/block.c b/block.c
  index 4833b37..4da6fd9 100644
  --- a/block.c
  +++ b/block.c
  @@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, 
  QEMUOptionParameter *options)
   }
   return bs-drv-bdrv_amend_options(bs, options);
   }
  +
  +bool bdrv_check_ext_snapshot(BlockDriverState *bs)
  +{
  +/* external snashots are enabled by defaults */
  +if (!bs-drv-bdrv_check_ext_snapshot) {
  +return true;
  +}
  +return bs-drv-bdrv_check_ext_snapshot(bs);
  +}
  +
  +bool bdrv_forbid_ext_snapshot(BlockDriverState *bs)
  +{
  +return false;
  +}
 
 The only problem I have with this now, is that
 bdrv_forbid_ext_snapshot() returns false, to indicate that forbid
 ext snapshot is true.  Looking at the function above, I would come to
 the opposite conclusion as to what it does.
 
 I understand why - you want the function name assigned to
 .bdrv_check_ext_snapshot to reflect the action, but then that causes
 the boolean return to be misleading.  Maybe returning an enum would be
 more natural?
 
 I apologize if this seems too pedantic.  :)

Perhaps rename the function to bdrv_check_ext_snapshot_forbidden() or
something like that?

Kevin



Re: [Qemu-devel] KVM call for agenda for 2013-10-01

2013-09-27 Thread Frederic Konrad

On 24/09/2013 16:09, Juan Quintela wrote:

Hi

Please, send any topic that you are interested in covering.

Last week I forgot to send the call for topics.  We still have a topic there.

Thanks, Juan.

Agenda so far:
- Talk about qemu reverse executing (1st description was done this week)
   How to handle IO when we want to do reverse execution.
   How this relate to Kemari needs?
   And to icount changes?


Hi Juan,

Just to confirm, both Mark and I will be present.

Thanks,
Fred


Call details:

10:00 AM to 11:00 AM EDT
Every two weeks

If you need phone number details,  contact me privately.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html





Re: [Qemu-devel] [RFC V8 03/13] quorum: Add quorum_aio_writev and its dependencies.

2013-09-27 Thread Kevin Wolf
Am 26.09.2013 um 18:16 hat Benoît Canet geschrieben:
   +static void quorum_aio_bh(void *opaque)
   +{
   +QuorumAIOCB *acb = opaque;
   +BDRVQuorumState *s = acb-bqs;
   +int ret;
   +
   +ret = s-threshold = acb-success_count ? 0 : -EIO;
  
  It would be very much preferable if you stored the actual error code
  instead of turning everything into -EIO.
 
 I am turning everything into -EIO because multiple errors can happen at the 
 same
 time.

Picking simply the first error code seems better than throwing all
information away. In the common case, I guess, you only have one error
at a time anyway. And if you do have multiple errors, you can still fix
one after another.

Kevin



Re: [Qemu-devel] [PATCH] eepro100: fix simplified mode

2013-09-27 Thread Paolo Bonzini
Il 24/07/2012 09:49, christian schilling ha scritto:
 On Mon, Jul 23, 2012 at 6:28 PM, Stefan Weil s...@weilnetz.de wrote:
 Am 23.07.2012 11:25, schrieb initcr...@gmail.com:

 A driver using simplified mode that works on real hardware
 did not work in qemu.

 Signed-off-by: Christian Schilling initcr...@gmail.com
 ---
   hw/eepro100.c |7 +++
   1 files changed, 7 insertions(+), 0 deletions(-)



 Do you really think that's a trivial patch?
 It's only three lines plus comments, but ok small != trivial.
 

 I have a different fix for simplified mode in my QEMU tree:

 http://repo.or.cz/w/qemu/ar7.git/blob/HEAD:/hw/eepro100.c

 That version is implemented according to the Intel specifications
 and avoids hacks for specific guest drivers.
 My fix isn't a hack for a specific guest driver, but is also in
 accordance with the
 intel specs.
 

 Maybe you can give it a try.
 I have, it does work.
 Overall the code look better to me, but one thing irritates me:
 The comment on line 821 contradicts the trace on 830 and 833.
 in fact i don't understand the code from 820 to 340. It seems to me it should
 handle extended flexible TCBs, but if it does what does the code
 following line 855 do?

Anything new about this one-year-old patch?

Paolo



Re: [Qemu-devel] [RFC V8 03/13] quorum: Add quorum_aio_writev and its dependencies.

2013-09-27 Thread Kevin Wolf
Am 26.09.2013 um 18:29 hat Benoît Canet geschrieben:
 Le Friday 08 Feb 2013 à 11:38:38 (+0100), Kevin Wolf a écrit :
  Am 28.01.2013 18:07, schrieb Benoît Canet:
   Signed-off-by: Benoit Canet ben...@irqsave.net
   ---
block/quorum.c |  111 
   
1 file changed, 111 insertions(+)
   
   diff --git a/block/quorum.c b/block/quorum.c
   index d8fffbe..5d8470b 100644
   --- a/block/quorum.c
   +++ b/block/quorum.c
   @@ -52,11 +52,122 @@ struct QuorumAIOCB {
int vote_ret;
};

   +static void quorum_aio_cancel(BlockDriverAIOCB *blockacb)
   +{
   +QuorumAIOCB *acb = container_of(blockacb, QuorumAIOCB, common);
   +bool finished = false;
   +
   +/* Wait for the request to finish */
   +acb-finished = finished;
   +while (!finished) {
   +qemu_aio_wait();
   +}
   +}
   +
   +static AIOCBInfo quorum_aiocb_info = {
   +.aiocb_size = sizeof(QuorumAIOCB),
   +.cancel = quorum_aio_cancel,
   +};
   +
   +static void quorum_aio_bh(void *opaque)
   +{
   +QuorumAIOCB *acb = opaque;
   +BDRVQuorumState *s = acb-bqs;
   +int ret;
   +
   +ret = s-threshold = acb-success_count ? 0 : -EIO;
  
  It would be very much preferable if you stored the actual error code
  instead of turning everything into -EIO.
  
   +
   +qemu_bh_delete(acb-bh);
   +acb-common.cb(acb-common.opaque, ret);
   +if (acb-finished) {
   +*acb-finished = true;
   +}
   +g_free(acb-aios);
   +qemu_aio_release(acb);
   +}
  
  Move this down so that it's next to the function using the bottom half.
  
   +
   +static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
   +   BlockDriverState *bs,
   +   QEMUIOVector *qiov,
   +   uint64_t sector_num,
   +   int nb_sectors,
   +   BlockDriverCompletionFunc *cb,
   +   void *opaque)
   +{
   +QuorumAIOCB *acb = qemu_aio_get(quorum_aiocb_info, bs, cb, opaque);
   +int i;
   +
   +acb-aios = g_new0(QuorumSingleAIOCB, s-total);
   +
   +acb-bqs = s;
   +acb-qiov = qiov;
   +acb-bh = NULL;
   +acb-count = 0;
   +acb-success_count = 0;
   +acb-sector_num = sector_num;
   +acb-nb_sectors = nb_sectors;
   +acb-vote = NULL;
   +acb-vote_ret = 0;
   +acb-finished = NULL;
   +
   +for (i = 0; i  s-total; i++) {
   +acb-aios[i].buf = NULL;
   +acb-aios[i].ret = 0;
   +acb-aios[i].parent = acb;
   +}
  
  Would you mind to reorder the initialisation of the fields according to
  the order that is used in the struct definition?
  
   +
   +return acb;
   +}
   +
   +static void quorum_aio_cb(void *opaque, int ret)
   +{
   +QuorumSingleAIOCB *sacb = opaque;
   +QuorumAIOCB *acb = sacb-parent;
   +BDRVQuorumState *s = acb-bqs;
   +
   +sacb-ret = ret;
   +acb-count++;
   +if (ret == 0) {
   +acb-success_count++;
   +}
   +assert(acb-count = s-total);
   +assert(acb-success_count = s-total);
   +if (acb-count  s-total) {
   +return;
   +}
   +
   +acb-bh = qemu_bh_new(quorum_aio_bh, acb);
   +qemu_bh_schedule(acb-bh);
  
  What's the reason for using a bottom half here? Worth a comment?
  
  multiwrite_cb() in block.c doesn't use one to achieve something similar.
  Is it buggy when you need one here?
  
 
 I tried the code without bh and it doesn't work.

It's long ago tbat I wrote that comment, but the remark about
multiwrite_cb() concerns me. Do you know _why_ it doesn't work without
the BH, and whether the same problem affects multiwrite_cb()? I'd prefer
if we understood what we're doing over just basing the code on
experiments.

Kevin



Re: [Qemu-devel] [RFC V8 06/13] quorum: Add quorum mechanism.

2013-09-27 Thread Kevin Wolf
Am 26.09.2013 um 18:46 hat Benoît Canet geschrieben:
 Le Friday 08 Feb 2013 à 13:07:03 (+0100), Kevin Wolf a écrit :
  Am 28.01.2013 18:07, schrieb Benoît Canet:
   Use gnutls's SHA-256 to compare versions.
   
   Signed-off-by: Benoit Canet ben...@irqsave.net
   ---
block/quorum.c |  303 
   +++-
configure  |   22 
2 files changed, 324 insertions(+), 1 deletion(-)

   +static bool quorum_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
   +{
   +int i;
   +int result;
   +
   +assert(a-niov == b-niov);
   +for (i = 0; i  a-niov; i++) {
   +assert(a-iov[i].iov_len == b-iov[i].iov_len);
   +result = memcmp(a-iov[i].iov_base,
   +b-iov[i].iov_base,
   +a-iov[i].iov_len);
   +if (result) {
   +return false;
   +}
   +}
   +
   +return true;
   +}
  
  qemu_iovec_compare() seems to do exactly the same, except that this
  doesn't return the offset of the first difference.
  
  Why is it a good idea to duplicate the code?
 
 Quorum need speed: qemu_iovec_compare will do byte level comparison whereas
 memcmp will use SSE on large block.

Fair enough.

   +/* we have a winner: copy it */
   +quorum_copy_qiov(acb-qiov, acb-aios[winner-index].qiov);
   +
   +/* some versions are bad print them */
   +quorum_print_bad_versions(acb, winner-value);
  
  Same here. Is this driver meant to be used in production or only for
  debugging? Maybe it should have a debug mode that must explicitly be
  enabled and messages are only printed in this mode?
 
 Quorum needs to communicate some event to the user for maintainance.
 Would thowing QMP events be better ?

Yes, absolutely. Error messages on stderr end up in a log file at best
and can only be read by human administrators. Using QMP enables
management tools to take action.

Kevin



[Qemu-devel] [PATCH v3 01/11] ARM: arm64 kvm headers from kernel arm64-kvm tree

2013-09-27 Thread Mian M. Hamayun
From: John Rigby john.ri...@linaro.org

Also add the KVM_REG_ARM64 register type to linux/kvm header file.

Signed-off-by: John Rigby john.ri...@linaro.org
Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 linux-headers/asm-arm64/kvm.h  | 168 +
 linux-headers/asm-arm64/kvm_para.h |   1 +
 linux-headers/linux/kvm.h  |   1 +
 3 files changed, 170 insertions(+)
 create mode 100644 linux-headers/asm-arm64/kvm.h
 create mode 100644 linux-headers/asm-arm64/kvm_para.h

diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
new file mode 100644
index 000..5031f42
--- /dev/null
+++ b/linux-headers/asm-arm64/kvm.h
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2012,2013 - ARM Ltd
+ * Author: Marc Zyngier marc.zyng...@arm.com
+ *
+ * Derived from arch/arm/include/uapi/asm/kvm.h:
+ * Copyright (C) 2012 - Virtual Open Systems and Columbia University
+ * Author: Christoffer Dall c.d...@virtualopensystems.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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/.
+ */
+
+#ifndef __ARM_KVM_H__
+#define __ARM_KVM_H__
+
+#define KVM_SPSR_EL1   0
+#define KVM_SPSR_SVC   KVM_SPSR_EL1
+#define KVM_SPSR_ABT   1
+#define KVM_SPSR_UND   2
+#define KVM_SPSR_IRQ   3
+#define KVM_SPSR_FIQ   4
+#define KVM_NR_SPSR5
+
+#ifndef __ASSEMBLY__
+#include asm/types.h
+#include asm/ptrace.h
+
+#define __KVM_HAVE_GUEST_DEBUG
+#define __KVM_HAVE_IRQ_LINE
+
+#define KVM_REG_SIZE(id)   \
+   (1U  (((id)  KVM_REG_SIZE_MASK)  KVM_REG_SIZE_SHIFT))
+
+struct kvm_regs {
+   struct user_pt_regs regs;   /* sp = sp_el0 */
+
+   __u64   sp_el1;
+   __u64   elr_el1;
+
+   __u64   spsr[KVM_NR_SPSR];
+
+   struct user_fpsimd_state fp_regs;
+};
+
+/* Supported Processor Types */
+#define KVM_ARM_TARGET_AEM_V8  0
+#define KVM_ARM_TARGET_FOUNDATION_V8   1
+#define KVM_ARM_TARGET_CORTEX_A57  2
+
+#define KVM_ARM_NUM_TARGETS3
+
+/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */
+#define KVM_ARM_DEVICE_TYPE_SHIFT  0
+#define KVM_ARM_DEVICE_TYPE_MASK   (0x  KVM_ARM_DEVICE_TYPE_SHIFT)
+#define KVM_ARM_DEVICE_ID_SHIFT16
+#define KVM_ARM_DEVICE_ID_MASK (0x  KVM_ARM_DEVICE_ID_SHIFT)
+
+/* Supported device IDs */
+#define KVM_ARM_DEVICE_VGIC_V2 0
+
+/* Supported VGIC address types  */
+#define KVM_VGIC_V2_ADDR_TYPE_DIST 0
+#define KVM_VGIC_V2_ADDR_TYPE_CPU  1
+
+#define KVM_VGIC_V2_DIST_SIZE  0x1000
+#define KVM_VGIC_V2_CPU_SIZE   0x2000
+
+#define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */
+#define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */
+
+struct kvm_vcpu_init {
+   __u32 target;
+   __u32 features[7];
+};
+
+struct kvm_sregs {
+};
+
+struct kvm_fpu {
+};
+
+struct kvm_guest_debug_arch {
+};
+
+struct kvm_debug_exit_arch {
+};
+
+struct kvm_sync_regs {
+};
+
+struct kvm_arch_memory_slot {
+};
+
+/* If you need to interpret the index values, here is the key: */
+#define KVM_REG_ARM_COPROC_MASK0x0FFF
+#define KVM_REG_ARM_COPROC_SHIFT   16
+
+/* Normal registers are mapped as coprocessor 16. */
+#define KVM_REG_ARM_CORE   (0x0010  KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / 
sizeof(__u32))
+
+/* Some registers need more space to represent values. */
+#define KVM_REG_ARM_DEMUX  (0x0011  KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_DEMUX_ID_MASK  0xFF00
+#define KVM_REG_ARM_DEMUX_ID_SHIFT 8
+#define KVM_REG_ARM_DEMUX_ID_CCSIDR(0x00  KVM_REG_ARM_DEMUX_ID_SHIFT)
+#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00FF
+#define KVM_REG_ARM_DEMUX_VAL_SHIFT0
+
+/* AArch64 system registers */
+#define KVM_REG_ARM64_SYSREG   (0x0013  KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM64_SYSREG_OP0_MASK  0xc000
+#define KVM_REG_ARM64_SYSREG_OP0_SHIFT 14
+#define KVM_REG_ARM64_SYSREG_OP1_MASK  0x3800
+#define KVM_REG_ARM64_SYSREG_OP1_SHIFT 11
+#define KVM_REG_ARM64_SYSREG_CRN_MASK  0x0780
+#define KVM_REG_ARM64_SYSREG_CRN_SHIFT 7
+#define KVM_REG_ARM64_SYSREG_CRM_MASK  0x0078
+#define KVM_REG_ARM64_SYSREG_CRM_SHIFT 3
+#define KVM_REG_ARM64_SYSREG_OP2_MASK  0x0007
+#define KVM_REG_ARM64_SYSREG_OP2_SHIFT 0
+
+/* KVM_IRQ_LINE irq field index values 

[Qemu-devel] [PATCH v3 11/11] AARCH64: Add 32-bit mode selection parameter

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This commit introduces a commandline argument to select the
AARCH64 or AARCH32 mode for processor initilization.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 qemu-options.hx  | 8 
 target-arm/cpu.c | 9 +++--
 vl.c | 4 
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 5dc8b75..a2dab99 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -72,6 +72,14 @@ STEXI
 Select CPU model (@code{-cpu help} for list and additional feature selection)
 ETEXI
 
+DEF(aarch32-mode, 0, QEMU_OPTION_aarch32_mode, \
+-aarch32-mode   enable aarch32 mode support on aarch64\n, QEMU_ARCH_ARM)
+STEXI
+@item -aarch32-mode
+@findex -aarch32-mode
+Enable aarch32 guest support on aarch64.
+ETEXI
+
 DEF(smp, HAS_ARG, QEMU_OPTION_smp,
 -smp 
[cpus=]n[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets]\n
 set the number of CPUs to 'n' [default=1]\n
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 5d811b9..56e8e56 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -27,6 +27,8 @@
 #include sysemu/sysemu.h
 #include sysemu/kvm.h
 
+extern int aarch32_mode;
+
 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
 {
 ARMCPU *cpu = ARM_CPU(cs);
@@ -85,8 +87,11 @@ static void arm_cpu_reset(CPUState *s)
 }
 
 if (arm_feature(env, ARM_FEATURE_AARCH64)) {
-/* 64 bit CPUs always start in 64 bit mode */
-env-aarch64 = 1;
+if(aarch32_mode) {
+env-aarch64 = 0;  /* Boot a 32-bit Guest */
+} else {
+env-aarch64 = 1;  /* Boot a 64-bit Guest */
+}
 }
 
 #if defined(CONFIG_USER_ONLY)
diff --git a/vl.c b/vl.c
index 4e709d5..e0f2cf3 100644
--- a/vl.c
+++ b/vl.c
@@ -207,6 +207,7 @@ CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
 CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int singlestep = 0;
+int aarch32_mode = 0;
 int smp_cpus = 1;
 int max_cpus = 0;
 int smp_cores = 1;
@@ -3113,6 +3114,9 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_dtb:
 qemu_opts_set(qemu_find_opts(machine), 0, dtb, optarg);
 break;
+case QEMU_OPTION_aarch32_mode:
+aarch32_mode = 1;
+break;
 case QEMU_OPTION_cdrom:
 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
 break;
-- 
1.8.1.2




[Qemu-devel] [PATCH v3 07/11] AARCH64: Add boot support for aarch64 processor

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This commit adds support for booting a single AArch64 CPU by setting
appropriate registers. The bootloader includes placehoders for Board-ID
that are used to implement uniform indexing across different bootloaders.
We also introduce Cortex-A57 to virt platform.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 hw/arm/boot.c | 57 +
 hw/arm/virt.c |  8 
 2 files changed, 65 insertions(+)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 4c1170e..0471eb8 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -19,6 +19,23 @@
 
 #define KERNEL_ARGS_ADDR 0x100
 
+#ifdef TARGET_AARCH64
+static uint32_t bootloader_arm64[] = {
+0x58c0,/* ldr  x0, 18 ; Load the lower 32-bits of DTB */
+0xaa1f03e1,/* mov  x1, xzr */
+0xaa1f03e2,/* mov  x2, xzr */
+0xaa1f03e3,/* mov  x3, xzr */
+0x5884,/* ldr  x4, 20 ; Load the lower 32-bits of kernel entry 
*/
+0xd61f0080,/* br   x4 ; Jump to the kernel entry point */
+0x,/* .word @DTB Lower 32-bits */
+0x,/* .word @DTB Higher 32-bits */
+0x,/* .word @Kernel Entry Lower 32-bits */
+0x,/* .word @Kernel Entry Higher 32-bits */
+0x,/* .word @Board ID Lower 32-bits -- Placeholder */
+0x /* .word @Board ID Higher 32-bits -- Placeholder */
+};
+#endif
+
 /* The worlds second smallest bootloader.  Set r0-r2, then jump to kernel.  */
 static uint32_t bootloader_arm32[] = {
   0xe3a0, /* mov r0, #0 */
@@ -103,11 +120,37 @@ static void setup_boot_env_32(void)
 return;
 }
 
+#ifdef TARGET_AARCH64
+static void setup_boot_env_64(void)
+{
+bootloader = bootloader_arm64;
+bootloader_array_size = ARRAY_SIZE(bootloader_arm64);
+
+kernel_args_index= bootloader_array_size - 6;
+kernel_entry_index   = bootloader_array_size - 4;
+kernel_boardid_index = bootloader_array_size - 2;
+return;
+}
+#endif
+
 static void setup_boot_env(ARMCPU *cpu)
 {
+#ifdef TARGET_AARCH64
+CPUARMState *env = cpu-env;
+if(env-aarch64) {
+/* AARCH64 Mode */
+kernel_load_addr = 0x0008;
+setup_boot_env_64();
+}
+else {
+/* AARCH32 Mode */
+/* TODO: Specify Kernel Load Address for AARCH32 */
+}
+#else
 /* ARMv7 */
 kernel_load_addr = 0x0001;
 setup_boot_env_32();
+#endif
 return;
 }
 
@@ -380,8 +423,22 @@ static void do_cpu_reset(void *opaque)
 env-regs[15] = info-entry  0xfffe;
 env-thumb = info-entry  1;
 } else {
+#ifdef TARGET_AARCH64
+if(env-aarch64) {
+env-pstate = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | 
PSR_MODE_EL1h;
+} else {
+hw_error(AArch32 mode is currently not supported\n);
+}
+env-xregs[0] =  0;
+env-xregs[1] = -1;
+#endif
 if (CPU(cpu) == first_cpu) {
+#ifdef TARGET_AARCH64
+env-xregs[2] = bootloader[kernel_args_index];
+env-pc = info-loader_start;
+#else
 env-regs[15] = info-loader_start;
+#endif
 if (!info-dtb_filename) {
 if (old_param) {
 set_kernel_args_old(info);
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 448a0e5..8043fd4 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -118,6 +118,14 @@ static VirtBoardInfo machines[] = {
 .memmap = a15memmap,
 .irqmap = a15irqmap,
 },
+{
+.cpu_model = cortex-a57,
+.cpu_compatible = arm,arm-v8,
+.qdevname = a57mpcore_priv,
+.gic_compatible = arm,cortex-a15-gic,
+.memmap = a15memmap,
+.irqmap = a15irqmap,
+},
 };
 
 static VirtBoardInfo *find_machine_info(const char *cpu)
-- 
1.8.1.2




[Qemu-devel] [PATCH v3 06/11] target-arm: Parameterize the bootloader selection and setup mechanism

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This commit replaces the constant indices used in bootloaders, such as for
specifying the Board ID and kernel arguments with variable parameters.
This change is used as mechanism to minimize code changes for different
bootloaders, for example different bootloaders will be used for different
architectures (ARMv7 vs. ARMv8).

Similary pointers are introduced to select appropriate bootloaders for boot
and secondary cpus.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 hw/arm/boot.c | 81 ---
 1 file changed, 66 insertions(+), 15 deletions(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 967397b..4c1170e 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -18,10 +18,9 @@
 #include qemu/config-file.h
 
 #define KERNEL_ARGS_ADDR 0x100
-#define KERNEL_LOAD_ADDR 0x0001
 
 /* The worlds second smallest bootloader.  Set r0-r2, then jump to kernel.  */
-static uint32_t bootloader[] = {
+static uint32_t bootloader_arm32[] = {
   0xe3a0, /* mov r0, #0 */
   0xe59f1004, /* ldr r1, [pc, #4] */
   0xe59f2004, /* ldr r2, [pc, #4] */
@@ -48,7 +47,7 @@ static uint32_t bootloader[] = {
 #define DSB_INSN 0xf57ff04f
 #define CP15_DSB_INSN 0xee070f9a /* mcr cp15, 0, r0, c7, c10, 4 */
 
-static uint32_t smpboot[] = {
+static uint32_t smpboot_arm32[] = {
   0xe59f2028, /* ldr r2, gic_cpu_if */
   0xe59f0028, /* ldr r0, startaddr */
   0xe3a01001, /* mov r1, #1 */
@@ -65,13 +64,60 @@ static uint32_t smpboot[] = {
   0   /* bootreg: Boot register address is held here */
 };
 
+/*
+ * The bootloaders to be used are referenced by the following pointers
+ * An appropriate bootloader is selected depending on the architecture
+ * i.e. ARMv7, ARMv8 (AARCH64 and AARCH32)
+ */
+static uint32_t *bootloader = NULL;
+static uint32_t  bootloader_array_size = 0;
+
+static uint32_t *smpboot = NULL;
+static uint32_t  smpboot_array_size = 0;
+
+/*
+ * An index gives the location in the bootloader array, where we put the board
+ * ID, kernel arguments and kernel entry addresses. These are different for
+ * ARMv7 and ARMv8 bootloaders defined above.
+ */
+static uint32_t kernel_boardid_index = 0;
+static uint32_t kernel_args_index= 0;
+static uint32_t kernel_entry_index   = 0;
+
+/*
+ * Similarly, the kernel loading address also depends on the architecture,
+ * i.e. its different for ARMv7, ARMv8 (AARCH64 and AARCH32)
+ */
+static uint32_t kernel_load_addr = 0x0;
+
+static void setup_boot_env_32(void)
+{
+bootloader = bootloader_arm32;
+bootloader_array_size = ARRAY_SIZE(bootloader_arm32);
+smpboot = smpboot_arm32;
+smpboot_array_size = ARRAY_SIZE(smpboot_arm32);
+
+kernel_boardid_index = bootloader_array_size - 3;
+kernel_args_index= bootloader_array_size - 2;
+kernel_entry_index   = bootloader_array_size - 1;
+return;
+}
+
+static void setup_boot_env(ARMCPU *cpu)
+{
+/* ARMv7 */
+kernel_load_addr = 0x0001;
+setup_boot_env_32();
+return;
+}
+
 static void default_write_secondary(ARMCPU *cpu,
 const struct arm_boot_info *info)
 {
 int n;
-smpboot[ARRAY_SIZE(smpboot) - 1] = info-smp_bootreg_addr;
-smpboot[ARRAY_SIZE(smpboot) - 2] = info-gic_cpu_if_addr;
-for (n = 0; n  ARRAY_SIZE(smpboot); n++) {
+smpboot[smpboot_array_size - 1] = info-smp_bootreg_addr;
+smpboot[smpboot_array_size - 2] = info-gic_cpu_if_addr;
+for (n = 0; n  smpboot_array_size; n++) {
 /* Replace DSB with the pre-v7 DSB if necessary. */
 if (!arm_feature(cpu-env, ARM_FEATURE_V7) 
 smpboot[n] == DSB_INSN) {
@@ -79,7 +125,8 @@ static void default_write_secondary(ARMCPU *cpu,
 }
 smpboot[n] = tswap32(smpboot[n]);
 }
-rom_add_blob_fixed(smpboot, smpboot, sizeof(smpboot),
+rom_add_blob_fixed(smpboot, smpboot,
+   smpboot_array_size * sizeof(uint32_t),
info-smp_loader_start);
 }
 
@@ -360,6 +407,9 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info 
*info)
 hwaddr entry;
 int big_endian;
 
+/* Select the bootloader to use and setup array indices, kernel entry etc 
*/
+setup_boot_env(cpu);
+
 /* Load the kernel.  */
 if (!info-kernel_filename) {
 fprintf(stderr, Kernel image must be specified\n);
@@ -406,9 +456,9 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info 
*info)
   is_linux);
 }
 if (kernel_size  0) {
-entry = info-loader_start + KERNEL_LOAD_ADDR;
+entry = info-loader_start + kernel_load_addr;
 kernel_size = load_image_targphys(info-kernel_filename, entry,
-  info-ram_size - KERNEL_LOAD_ADDR);
+  info-ram_size - kernel_load_addr);
 is_linux = 1;
 }
 if (kernel_size  0) {
@@ -439,7 +489,7 @@ void 

[Qemu-devel] [PATCH v3 08/11] AARCH64: Enable SMP support for aarch64 processors using PSCI method

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

We enable SMP support for aarch64 processors using the PSCI method,
by setting the appropriate CPU feature flags at initilializtion time.

Secondary boot code for non-aarch64 processors is disabled in case
of compilation for aarch64.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 hw/arm/boot.c   | 4 
 target-arm/kvm_64.c | 7 +++
 2 files changed, 11 insertions(+)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 0471eb8..ddafd3b 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -157,6 +157,7 @@ static void setup_boot_env(ARMCPU *cpu)
 static void default_write_secondary(ARMCPU *cpu,
 const struct arm_boot_info *info)
 {
+#ifndef TARGET_AARCH64
 int n;
 smpboot[smpboot_array_size - 1] = info-smp_bootreg_addr;
 smpboot[smpboot_array_size - 2] = info-gic_cpu_if_addr;
@@ -171,15 +172,18 @@ static void default_write_secondary(ARMCPU *cpu,
 rom_add_blob_fixed(smpboot, smpboot,
smpboot_array_size * sizeof(uint32_t),
info-smp_loader_start);
+#endif
 }
 
 static void default_reset_secondary(ARMCPU *cpu,
 const struct arm_boot_info *info)
 {
+#ifndef TARGET_AARCH64
 CPUARMState *env = cpu-env;
 
 stl_phys_notdirty(info-smp_bootreg_addr, 0);
 env-regs[15] = info-smp_loader_start;
+#endif
 }
 
 #define WRITE_WORD(p, value) do { \
diff --git a/target-arm/kvm_64.c b/target-arm/kvm_64.c
index 9685727..146b7c4 100644
--- a/target-arm/kvm_64.c
+++ b/target-arm/kvm_64.c
@@ -27,12 +27,19 @@ static uint32_t kvm_arm_targets[KVM_ARM_NUM_TARGETS] = {
 KVM_ARM_TARGET_CORTEX_A57
 };
 
+#define ARM_VCPU_FEATURE_FLAGS(cpuid, is_aarch32)  \
+((!!(cpuid)  KVM_ARM_VCPU_POWER_OFF) | (is_aarch32  
KVM_ARM_VCPU_EL1_32BIT))
+
 int kvm_arch_init_vcpu(CPUState *cs)
 {
 struct kvm_vcpu_init init;
 int ret, i;
 
+ARMCPU *cpu = ARM_CPU(cs);
+CPUARMState *env = cpu-env;
+
 memset(init.features, 0, sizeof(init.features));
+init.features[0] = ARM_VCPU_FEATURE_FLAGS(cs-cpu_index, !env-aarch64);
 /* Find an appropriate target CPU type.
  * KVM does not provide means to detect the host CPU type on aarch64,
  * and simply refuses to initialize, if the CPU type mis-matches;
-- 
1.8.1.2




[Qemu-devel] [PATCH v2 0/2] qcow2: count_contiguous_clusters and compression

2013-09-27 Thread Max Reitz
Compressed clusters can never be contiguous and count_contiguous_clusters
will not even work correctly for them. Therefore, those cluster should
always be treated as non-contiguous.

This series makes count_contiguous_clusters always stop at compressed
clusters and removes the corresponding flag from its function calls.

v2:
 - added patch 2 (following Kevin's proposal)
 - patch 1 remains unmodified

Max Reitz (2):
  qcow2: count_contiguous_clusters and compression
  qcow2: COMPRESSED on count_contiguous_clusters

 block/qcow2-cluster.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH v3 09/11] AARCH64: Enable configure support for 32-bit guests on AARCH64

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 configure | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure b/configure
index 7298b69..dbaf56f 100755
--- a/configure
+++ b/configure
@@ -4485,6 +4485,7 @@ case $target_name in
 # Make sure the target and host cpus are compatible
 if test $kvm = yes -a $target_softmmu = yes -a \
   \( $target_name = $cpu -o \
+  \( $target_name = arm -a $cpu = aarch64 \) -o \
   \( $target_name = ppcemb -a $cpu = ppc \) -o \
   \( $target_name = ppc64  -a $cpu = ppc \) -o \
   \( $target_name = ppc-a $cpu = ppc64 \) -o \
-- 
1.8.1.2




[Qemu-devel] [PATCH v2 2/2] qcow2: COMPRESSED on count_contiguous_clusters

2013-09-27 Thread Max Reitz
Compressed clusters can never be contiguous, therefore the corresponding
flag does not need to be given explicitly to count_contiguous_clusters.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2-cluster.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index a62ef42..145fa18 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -490,8 +490,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t 
offset,
 return -EIO;
 }
 c = count_contiguous_clusters(nb_clusters, s-cluster_size,
-l2_table[l2_index], 0,
-QCOW_OFLAG_COMPRESSED | QCOW_OFLAG_ZERO);
+l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
 *cluster_offset = 0;
 break;
 case QCOW2_CLUSTER_UNALLOCATED:
@@ -502,8 +501,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t 
offset,
 case QCOW2_CLUSTER_NORMAL:
 /* how many allocated clusters ? */
 c = count_contiguous_clusters(nb_clusters, s-cluster_size,
-l2_table[l2_index], 0,
-QCOW_OFLAG_COMPRESSED | QCOW_OFLAG_ZERO);
+l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
 *cluster_offset = L2E_OFFSET_MASK;
 break;
 default:
-- 
1.8.3.1




[Qemu-devel] [PATCH v2 1/2] qcow2: count_contiguous_clusters and compression

2013-09-27 Thread Max Reitz
The function is not intended to be used on compressed clusters and will
not work correctly, if used anyway, since L2E_OFFSET_MASK is not the
right mask for determining the offset of compressed clusters. Therefore,
assert that the first cluster is not compressed and always include the
compression flag in the mask of significant flags, i.e., stop the search
as soon as a compressed cluster occurs.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2-cluster.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cab5f2e..a62ef42 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -281,12 +281,15 @@ static int count_contiguous_clusters(uint64_t 
nb_clusters, int cluster_size,
 uint64_t *l2_table, uint64_t start, uint64_t stop_flags)
 {
 int i;
-uint64_t mask = stop_flags | L2E_OFFSET_MASK;
-uint64_t offset = be64_to_cpu(l2_table[0])  mask;
+uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED;
+uint64_t first_entry = be64_to_cpu(l2_table[0]);
+uint64_t offset = first_entry  mask;
 
 if (!offset)
 return 0;
 
+assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED);
+
 for (i = start; i  start + nb_clusters; i++) {
 uint64_t l2_entry = be64_to_cpu(l2_table[i])  mask;
 if (offset + (uint64_t) i * cluster_size != l2_entry) {
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 10/11] AARCH64: Add flags and boot parameters for 32-bit guests on AARCH64

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This commit adds the necessary flags and kernel load address to enable
booting of 32-bit guests on AArch64 processors.

The actual enable/disable mechanism is not included in this commit,
which should tweak the value of env-aarch64 variable for this purpose.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 hw/arm/boot.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index ddafd3b..2cfa9bf 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -20,6 +20,10 @@
 #define KERNEL_ARGS_ADDR 0x100
 
 #ifdef TARGET_AARCH64
+#define COMPAT_PSR_F_BIT0x0040
+#define COMPAT_PSR_I_BIT0x0080
+#define COMPAT_PSR_MODE_SVC 0x0013
+
 static uint32_t bootloader_arm64[] = {
 0x58c0,/* ldr  x0, 18 ; Load the lower 32-bits of DTB */
 0xaa1f03e1,/* mov  x1, xzr */
@@ -144,7 +148,8 @@ static void setup_boot_env(ARMCPU *cpu)
 }
 else {
 /* AARCH32 Mode */
-/* TODO: Specify Kernel Load Address for AARCH32 */
+kernel_load_addr = 0x8000;
+setup_boot_env_32();
 }
 #else
 /* ARMv7 */
@@ -431,7 +436,7 @@ static void do_cpu_reset(void *opaque)
 if(env-aarch64) {
 env-pstate = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | 
PSR_MODE_EL1h;
 } else {
-hw_error(AArch32 mode is currently not supported\n);
+env-pstate = COMPAT_PSR_I_BIT | COMPAT_PSR_F_BIT | 
COMPAT_PSR_MODE_SVC;
 }
 env-xregs[0] =  0;
 env-xregs[1] = -1;
-- 
1.8.1.2




[Qemu-devel] 答复: Cross-Platform KVM

2013-09-27 Thread Wincy Van
I'm sorry for replying this mail for so long. 
I named the 'Cross-Platform KVM'  fvm  ('f'is the beginning of my name 
:)).

The kernel module is based on kvm-kmod 3.4, and the qemu (version 1.1~1.6) can 
be patched easily for fvm.
I named the kernel module vmmr0 (VMM in Ring0).
Not like the 'WinKVM' by Kazushi Takahashi, fvm is easy to compile and use. The 
build environment for windows is mingw-w64.

I will sum up the internals of fvm, and release the docs and codes on github 
later.
The code of vmmr0 is disordered, so I will reorganize it before releasing.

Before this, I commited a binary package for windows on github:

https://github.com/fanwenyi0529/fvm-release


to use the fvm for windows, we should follow these steps:

you should have a computer which installed 64-bit windows 7 or higher.

1. enable  'Lock pages in memory' of current user in gpedit.msc:
http://msdn.microsoft.com/en-us/library/ms190730.aspx
fvm use awe memory in order to lock guest 's page. Windows kernel do 
not have anything like mmu_notifier:( 

2.windows x64 needs driver signing, so enable testmode.

bcdedit -set testsigning on

3.reboot your computer.

4.install the vmmr0.sys kernel module as service named 'vmmr0' and start it.

execute in cmd:

sc create vmmr0 binpath=(path to vmmr0.sys) type=kernel start=demand
net start vmmr0

5. all done! Let 's run kvm on windows.

eg:

create a bat file , and type this in the target blank:

(path to fvm-x86_64w.exe)  -drive 
file=D:\vm\linux-0.2.img,cache=writeback -machine accel=kvm,kernel_irqchip=off 
-cpu qemu64,-vmx -smp sockets=1,cores=1 -m 128 -soundhw hda -net 
nic,model=e1000 -net user -rtc base=localtime -vga vmware

Save and run this bat as admin.


Known problems:
1. I have not implement the kernel_irqchip, so please disable the kirqchip 
support in cmdline like this:

-machine accel=kvm,kernel_irqchip=off

2. the performance of windows x64 guests is pr, I have not found the reason.

3. do not use vmware vga card if the guest is Ubuntu 12.04, or the qemu 
(version 1.3 )would core, qemu-1.6 is okay.

4. The mouse auto switching while running linux guests (Ubuntu, etc.) can not 
work. And the qemu will lost  response. Please use vnc to run Ubuntu.

5. If your cpu do not support ept, please give the guest only 1vcpu if the 
guest is 64 bit. Or the guest will corrupt.



Regards,
Wincy

-邮件原件-
发件人: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org] 代表 Andreas 
F?rber
发送时间: 2013年8月22日 星期四 2:49
收件人: Wincy Van; Wincy Van
抄送: qemu-devel@nongnu.org; kvm; Stefan Weil; qemu-devel@nongnu.org; kvm; Stefan 
Weil
主题: Re: [Qemu-devel] Cross-Platform KVM

Hi,

Am 16.08.2013 09:41, schrieb Wincy Van:
 Hi,there:
 
I have implemented a version of cross-platform KVM. Now, it can 
 works on Linux and Windows(kernel version 7600-9200, amd64). Is it 
 useful? If so, I want make it as a branch of current KVM. Here are 
 some
 screenshots:

Let's CC the KVM mailing list.

More telling than screenshots would be some info about your code! Is there a 
public Git repository to look at? Is it based on a current kvm.git or some 
older Win32 KVM fork on SourceForge? If so, how invasive are your changes? Or 
is it a clean-room implementation of your own against the header/ioctl 
interface? How does it work technically? etc.

Regards,
Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in the body of a 
message to majord...@vger.kernel.org More majordomo info at  
http://vger.kernel.org/majordomo-info.html



[Qemu-devel] [PATCH v3 00/11] AARCH64 support on machvirt machine model using KVM

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This is the v3 of patch series that implements KVM support in QEMU for the ARMv8
Cortex A57 CPU. It depends on the recently mainlined AArch64 preparation patch
series and machvirt patches version v7, and uses the already available KVM 
in-kernel GIC support. 
This implementation supports both 64-bit and 32-bit guests on AARCH64.

As a reference, KVM Tool and the AArch64 bootwrapper were used, as well as
public documentation from ARM. The following work has been tested with SMP
capabilities for both 64 and 32-bit guests, under ARMv8 Fast and Foundation 
Models (Open Embedded userspace with an emulated MMC).

The v1 of this patch series related to AArch64 CPU model for Versatile Express
was sponsored by Huawei, and developed in collaboration between Huawei
Technologies Duesseldorf GmbH - European Research Center Munich (ERC) and
Virtual Open Systems.

A working tree of this implementation is available on the kvm-aarch64-v3
branch of the following github repository.

https://github.com/virtualopensystems/qemu/tree/kvm-aarch64-v3

Summary of Changes:

Changes v2 - v3
 * Based on AArch64 Preparation Patchset (mainlined) and machvirt patch version 
v7
 * 32 and 64-bit KVM hooks have been separated into kvm_32.c and kvm_64.c, 
whereas
   common code resides in kvm.c
 * SMP support is now implemented using PSCI method instead of the boot 
injection
   mechanism, as implemented in the previous versions
 * 32-bit SMP guest support is now available

Changes v1 - v2
 * Based on AArch64 Preparation Patchset V5 and machvirt patches.
 * Implemented for Machvirt Machine Model.
 * Architecture-specific CPU initialization code improved. Removed hardcoding
   from register set/get loops and introduced CPU target type array to find
   appropriate ARMv8 CPU type supported by KVM.
 * Disable the PSCI method in case of AArch64 and use the spin-table method
   instead for booting secondary CPUs.
 * 32-bit guest support still missing

v1
 * Based on AArch64 Preparation Patchset V4
 * Implemented for Versatile Express Machine Model
 * Support for SMP using bootcode injection
 * No 32-bit guest support

John Rigby (2):
  ARM: arm64 kvm headers from kernel arm64-kvm tree
  AARCH64: add a57core

Mian M. Hamayun (9):
  AARCH64: Add A57 CPU to default AArch64 configuration and enable KVM
  AARCH64: Separate 32-bit specific code from common KVM hooks
  AARCH64: Add AARCH64 CPU initialization, get and put registers support
  target-arm: Parameterize the bootloader selection and setup mechanism
  AARCH64: Add boot support for aarch64 processor
  AARCH64: Enable SMP support for aarch64 processors using PSCI method
  AARCH64: Enable configure support for 32-bit guests on AARCH64
  AARCH64: Add flags and boot parameters for 32-bit guests on AARCH64
  AARCH64: Add 32-bit mode selection parameter

 configure   |   3 +-
 default-configs/aarch64-softmmu.mak |   1 +
 hw/arm/boot.c   | 147 --
 hw/arm/virt.c   |   8 +
 hw/cpu/Makefile.objs|   1 +
 hw/cpu/a57mpcore.c  | 122 
 linux-headers/asm-arm64/kvm.h   | 168 
 linux-headers/asm-arm64/kvm_para.h  |   1 +
 linux-headers/linux/kvm.h   |   1 +
 qemu-options.hx |   8 +
 target-arm/Makefile.objs|   5 +
 target-arm/cpu.c|  18 +-
 target-arm/kvm.c| 363 --
 target-arm/kvm_32.c | 382 
 target-arm/kvm_64.c | 146 ++
 vl.c|   4 +
 16 files changed, 997 insertions(+), 381 deletions(-)
 create mode 100644 hw/cpu/a57mpcore.c
 create mode 100644 linux-headers/asm-arm64/kvm.h
 create mode 100644 linux-headers/asm-arm64/kvm_para.h
 create mode 100644 target-arm/kvm_32.c
 create mode 100644 target-arm/kvm_64.c

-- 
1.8.1.2




[Qemu-devel] [PATCH v3 02/11] AARCH64: add a57core

2013-09-27 Thread Mian M. Hamayun
From: John Rigby john.ri...@linaro.org

Just an copy of a15 with a57 substituting a15 for now.

Signed-off-by: John Rigby john.ri...@linaro.org
Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 hw/cpu/Makefile.objs |   1 +
 hw/cpu/a57mpcore.c   | 122 +++
 target-arm/cpu.c |   9 
 3 files changed, 132 insertions(+)
 create mode 100644 hw/cpu/a57mpcore.c

diff --git a/hw/cpu/Makefile.objs b/hw/cpu/Makefile.objs
index df287c1..22e9567 100644
--- a/hw/cpu/Makefile.objs
+++ b/hw/cpu/Makefile.objs
@@ -1,5 +1,6 @@
 obj-$(CONFIG_ARM11MPCORE) += arm11mpcore.o
 obj-$(CONFIG_A9MPCORE) += a9mpcore.o
 obj-$(CONFIG_A15MPCORE) += a15mpcore.o
+obj-$(CONFIG_A57MPCORE) += a57mpcore.o
 obj-$(CONFIG_ICC_BUS) += icc_bus.o
 
diff --git a/hw/cpu/a57mpcore.c b/hw/cpu/a57mpcore.c
new file mode 100644
index 000..4be277f
--- /dev/null
+++ b/hw/cpu/a57mpcore.c
@@ -0,0 +1,122 @@
+/*
+ * Cortex-A57MPCore internal peripheral emulation.
+ *
+ * Copyright (c) 2012 Linaro Limited.
+ * Written by Peter Maydell.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see http://www.gnu.org/licenses/.
+ */
+
+#include hw/sysbus.h
+#include sysemu/kvm.h
+
+/* A57MP private memory region.  */
+
+#define TYPE_A57MPCORE_PRIV a57mpcore_priv
+#define A57MPCORE_PRIV(obj) \
+OBJECT_CHECK(A57MPPrivState, (obj), TYPE_A57MPCORE_PRIV)
+
+typedef struct A57MPPrivState {
+/* private */
+SysBusDevice parent_obj;
+/* public */
+
+uint32_t num_cpu;
+uint32_t num_irq;
+MemoryRegion container;
+DeviceState *gic;
+} A57MPPrivState;
+
+static void a57mp_priv_set_irq(void *opaque, int irq, int level)
+{
+A57MPPrivState *s = (A57MPPrivState *)opaque;
+qemu_set_irq(qdev_get_gpio_in(s-gic, irq), level);
+}
+
+static int a57mp_priv_init(SysBusDevice *dev)
+{
+A57MPPrivState *s = A57MPCORE_PRIV(dev);
+SysBusDevice *busdev;
+const char *gictype = arm_gic;
+
+if (kvm_irqchip_in_kernel()) {
+gictype = kvm-arm-gic;
+}
+
+s-gic = qdev_create(NULL, gictype);
+qdev_prop_set_uint32(s-gic, num-cpu, s-num_cpu);
+qdev_prop_set_uint32(s-gic, num-irq, s-num_irq);
+qdev_prop_set_uint32(s-gic, revision, 2);
+qdev_init_nofail(s-gic);
+busdev = SYS_BUS_DEVICE(s-gic);
+
+/* Pass through outbound IRQ lines from the GIC */
+sysbus_pass_irq(dev, busdev);
+
+/* Pass through inbound GPIO lines to the GIC */
+qdev_init_gpio_in(DEVICE(dev), a57mp_priv_set_irq, s-num_irq - 32);
+
+/* Memory map (addresses are offsets from PERIPHBASE):
+ *  0x-0x0fff -- reserved
+ *  0x1000-0x1fff -- GIC Distributor
+ *  0x2000-0x2fff -- GIC CPU interface
+ *  0x4000-0x4fff -- GIC virtual interface control (not modelled)
+ *  0x5000-0x5fff -- GIC virtual interface control (not modelled)
+ *  0x6000-0x7fff -- GIC virtual CPU interface (not modelled)
+ */
+memory_region_init(s-container, OBJECT(s),
+   a57mp-priv-container, 0x8000);
+memory_region_add_subregion(s-container, 0x1000,
+sysbus_mmio_get_region(busdev, 0));
+memory_region_add_subregion(s-container, 0x2000,
+sysbus_mmio_get_region(busdev, 1));
+
+sysbus_init_mmio(dev, s-container);
+return 0;
+}
+
+static Property a57mp_priv_properties[] = {
+DEFINE_PROP_UINT32(num-cpu, A57MPPrivState, num_cpu, 1),
+/* The Cortex-A57MP may have anything from 0 to 224 external interrupt
+ * IRQ lines (with another 32 internal). We default to 128+32, which
+ * is the number provided by the Cortex-A57MP test chip in the
+ * Versatile Express A57 development board.
+ * Other boards may differ and should set this property appropriately.
+ */
+DEFINE_PROP_UINT32(num-irq, A57MPPrivState, num_irq, 160),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void a57mp_priv_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+k-init = a57mp_priv_init;
+dc-props = a57mp_priv_properties;
+/* We currently have no savable state */
+}
+
+static const TypeInfo a57mp_priv_info = {
+.name  = TYPE_A57MPCORE_PRIV,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size  = sizeof(A57MPPrivState),
+.class_init = a57mp_priv_class_init,
+};
+
+static void 

[Qemu-devel] [PATCH v3 04/11] AARCH64: Separate 32-bit specific code from common KVM hooks

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

This commit separates the 32-bit (ARMv7) specific KVM hooks from
the common code. It also adds the stub functions for 64-bit (ARMv8).

The makefile objects are also tweaked accordingly to compile code
either of ARMv7 or ARMv8 depending on the AARCH64 variable.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 target-arm/Makefile.objs |   5 +
 target-arm/kvm.c | 363 
 target-arm/kvm_32.c  | 382 +++
 target-arm/kvm_64.c  |  39 +
 4 files changed, 426 insertions(+), 363 deletions(-)
 create mode 100644 target-arm/kvm_32.c
 create mode 100644 target-arm/kvm_64.c

diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs
index 6453f5c..4b37d29 100644
--- a/target-arm/Makefile.objs
+++ b/target-arm/Makefile.objs
@@ -1,6 +1,11 @@
 obj-y += arm-semi.o
 obj-$(CONFIG_SOFTMMU) += machine.o
 obj-$(CONFIG_KVM) += kvm.o
+ifeq ($(TARGET_AARCH64),y)
+obj-$(CONFIG_KVM) += kvm_64.o
+else
+obj-$(CONFIG_KVM) += kvm_32.o
+endif
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += neon_helper.o iwmmxt_helper.o
diff --git a/target-arm/kvm.c b/target-arm/kvm.c
index b92e00d..8e608c9 100644
--- a/target-arm/kvm.c
+++ b/target-arm/kvm.c
@@ -50,130 +50,6 @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu)
 return cpu-cpu_index;
 }
 
-static bool reg_syncs_via_tuple_list(uint64_t regidx)
-{
-/* Return true if the regidx is a register we should synchronize
- * via the cpreg_tuples array (ie is not a core reg we sync by
- * hand in kvm_arch_get/put_registers())
- */
-switch (regidx  KVM_REG_ARM_COPROC_MASK) {
-case KVM_REG_ARM_CORE:
-case KVM_REG_ARM_VFP:
-return false;
-default:
-return true;
-}
-}
-
-static int compare_u64(const void *a, const void *b)
-{
-return *(uint64_t *)a - *(uint64_t *)b;
-}
-
-int kvm_arch_init_vcpu(CPUState *cs)
-{
-struct kvm_vcpu_init init;
-int i, ret, arraylen;
-uint64_t v;
-struct kvm_one_reg r;
-struct kvm_reg_list rl;
-struct kvm_reg_list *rlp;
-ARMCPU *cpu = ARM_CPU(cs);
-
-init.target = KVM_ARM_TARGET_CORTEX_A15;
-memset(init.features, 0, sizeof(init.features));
-ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, init);
-if (ret) {
-return ret;
-}
-/* Query the kernel to make sure it supports 32 VFP
- * registers: QEMU's cortex-a15 CPU is always a
- * VFP-D32 core. The simplest way to do this is just
- * to attempt to read register d31.
- */
-r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP | 31;
-r.addr = (uintptr_t)(v);
-ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, r);
-if (ret == -ENOENT) {
-return -EINVAL;
-}
-
-/* Populate the cpreg list based on the kernel's idea
- * of what registers exist (and throw away the TCG-created list).
- */
-rl.n = 0;
-ret = kvm_vcpu_ioctl(cs, KVM_GET_REG_LIST, rl);
-if (ret != -E2BIG) {
-return ret;
-}
-rlp = g_malloc(sizeof(struct kvm_reg_list) + rl.n * sizeof(uint64_t));
-rlp-n = rl.n;
-ret = kvm_vcpu_ioctl(cs, KVM_GET_REG_LIST, rlp);
-if (ret) {
-goto out;
-}
-/* Sort the list we get back from the kernel, since cpreg_tuples
- * must be in strictly ascending order.
- */
-qsort(rlp-reg, rlp-n, sizeof(rlp-reg[0]), compare_u64);
-
-for (i = 0, arraylen = 0; i  rlp-n; i++) {
-if (!reg_syncs_via_tuple_list(rlp-reg[i])) {
-continue;
-}
-switch (rlp-reg[i]  KVM_REG_SIZE_MASK) {
-case KVM_REG_SIZE_U32:
-case KVM_REG_SIZE_U64:
-break;
-default:
-fprintf(stderr, Can't handle size of register in kernel list\n);
-ret = -EINVAL;
-goto out;
-}
-
-arraylen++;
-}
-
-cpu-cpreg_indexes = g_renew(uint64_t, cpu-cpreg_indexes, arraylen);
-cpu-cpreg_values = g_renew(uint64_t, cpu-cpreg_values, arraylen);
-cpu-cpreg_vmstate_indexes = g_renew(uint64_t, cpu-cpreg_vmstate_indexes,
- arraylen);
-cpu-cpreg_vmstate_values = g_renew(uint64_t, cpu-cpreg_vmstate_values,
-arraylen);
-cpu-cpreg_array_len = arraylen;
-cpu-cpreg_vmstate_array_len = arraylen;
-
-for (i = 0, arraylen = 0; i  rlp-n; i++) {
-uint64_t regidx = rlp-reg[i];
-if (!reg_syncs_via_tuple_list(regidx)) {
-continue;
-}
-cpu-cpreg_indexes[arraylen] = regidx;
-arraylen++;
-}
-assert(cpu-cpreg_array_len == arraylen);
-
-if (!write_kvmstate_to_list(cpu)) {
-/* Shouldn't happen unless kernel is inconsistent about
- * what registers exist.
- */
-fprintf(stderr, Initial read of kernel register state failed\n);
-ret = -EINVAL;
-

Re: [Qemu-devel] [PATCH 00/60] AArch64 TCG emulation support

2013-09-27 Thread Alexander Graf

On 27.09.2013, at 04:30, Peter Maydell wrote:

 On 27 September 2013 10:02, Alexander Graf ag...@suse.de wrote:
 On 27.09.2013, at 02:47, Alexander Graf wrote:
 This is the first batch of patches to implement AArch64 instruction
 emulation in QEMU. It implements enough to execute simple AArch64
 programs in linux-user mode.
 
 Ah, one important thing I forgot to mention is that this patch set is based
 on Peter Maydell's aarch64 branch
 
 What's not in mainline that you need? I committed the preparation-patchset
 so your tcg patches wouldn't need to depend on not-in-mainline stuff...

You're right. I had a stale tree registered as origin and didn't realize it 
:). I've rebased the patches on top of upstream/master now (which was conflict 
free) keeping the linux-user .mak patch from you in. I also fixed a few TCGv 
i32/64/ptr hickups that were still left in the tree.

Considering the minimal amount of changes this incurred, I will refrain from 
reposting a giant 60-patches patch set and instead just pushed it to a new 
branch on github:

  git://github.com/agraf/qemu.git aarch64-tcg-batch1-v2


In a nutshell the changes from v1 - v2 are:

New: 0001-default-configs-Add-config-for-aarch64-linux-user.patch

0016-AArch64-Add-add-instruction-family-emulation.patch:v1 - v2:
0016-AArch64-Add-add-instruction-family-emulation.patch-
0016-AArch64-Add-add-instruction-family-emulation.patch-  - Fix TCG i32/i64 
misusage for pstate
--
0051-AArch64-Add-Floating-point-fixed-point-conversions-c.patch:v1 - v2:
0051-AArch64-Add-Floating-point-fixed-point-conversions-c.patch-
0051-AArch64-Add-Floating-point-fixed-point-conversions-c.patch-  - use 
TCGv_ptr for fpstatus
0051-AArch64-Add-Floating-point-fixed-point-conversions-c.patch-  - use 
TCGv_i32 for single temporary
--
0054-AArch64-Add-Floating-point-compare-instruction-famil.patch:v1 - v2:
0054-AArch64-Add-Floating-point-compare-instruction-famil.patch-
0054-AArch64-Add-Floating-point-compare-instruction-famil.patch-  - Use 
TCGv_i64 for 64bit variables
--
0055-AArch64-Add-Floating-point-data-processing-1-source-.patch:v1 - v2:
0055-AArch64-Add-Floating-point-data-processing-1-source-.patch-
0055-AArch64-Add-Floating-point-data-processing-1-source-.patch-  - Fix i32/i64 
misusage on extu
--
0056-AArch64-Add-Floating-point-data-processing-1-source-.patch:v1 - v2:
0056-AArch64-Add-Floating-point-data-processing-1-source-.patch-
0056-AArch64-Add-Floating-point-data-processing-1-source-.patch-  - Fix TCGv 
i32/i64 misusage
--
0057-AArch64-Add-Floating-point-data-processing-2-source-.patch:v1 - v2:
0057-AArch64-Add-Floating-point-data-processing-2-source-.patch-
0057-AArch64-Add-Floating-point-data-processing-2-source-.patch-  - Fix i32/i64 
misusage on extu
--
0060-AArch64-Add-Floating-point-data-processing-3-source-.patch:v1 - v2:
0060-AArch64-Add-Floating-point-data-processing-3-source-.patch-
0060-AArch64-Add-Floating-point-data-processing-3-source-.patch-  - Fix i32/i64 
misusage on extu


Alex




Re: [Qemu-devel] Capture SIGSEGV to track pc.ram page access

2013-09-27 Thread Stefan Hajnoczi
On Thu, Sep 26, 2013 at 02:53:54PM +0200, Thomas Knauth wrote:
 As far as I understand the dirty logging infrastructure will only
 record writes. I want to track reads as well.
 
 A better way to express what I would like to do is trace all guest
 physical addresses that are accessed. Again, I am unsure whether qemu
 supports this out-of-the box and where I would have to add/modify the
 source to do so.

If you want to continue with the original SIGSEGV handler approach,
check signals masks for the vcpu threads.  Make sure the signal actually
gets delivered to a thread that has the signal unblocked and a signal
handler installed.

Regarding dirty logging, you could try modifying the KVM dirty logging
code to also trap reads.

Also take a look at /proc/PID/pagemap and documentation on accessing
this page table info.  It can be used for tracking dirty pages
(soft-dirty) but I'm not sure if it reports accessed pages.

Stefan



[Qemu-devel] [PATCH v3 05/11] AARCH64: Add AARCH64 CPU initialization, get and put registers support

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

The cpu init function tries to initialize with all possible cpu types, as
KVM does not provide a means to detect the real cpu type and simply refuses
to initialize on cpu type mis-match. By using the loop based init function,
we avoid the need to modify code if the underlying platform is different,
such as Fast Models instead of Foundation Models.

Get and Put Registers deal with the basic state of AARCH64 CPUs.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 target-arm/kvm_64.c | 106 ++--
 1 file changed, 103 insertions(+), 3 deletions(-)

diff --git a/target-arm/kvm_64.c b/target-arm/kvm_64.c
index a6af968..9685727 100644
--- a/target-arm/kvm_64.c
+++ b/target-arm/kvm_64.c
@@ -18,19 +18,119 @@
 #include sysemu/kvm.h
 #include kvm_arm.h
 
+#define AARCH64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
+KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
+
+static uint32_t kvm_arm_targets[KVM_ARM_NUM_TARGETS] = {
+KVM_ARM_TARGET_AEM_V8,
+KVM_ARM_TARGET_FOUNDATION_V8,
+KVM_ARM_TARGET_CORTEX_A57
+};
+
 int kvm_arch_init_vcpu(CPUState *cs)
 {
-return 0;
+struct kvm_vcpu_init init;
+int ret, i;
+
+memset(init.features, 0, sizeof(init.features));
+/* Find an appropriate target CPU type.
+ * KVM does not provide means to detect the host CPU type on aarch64,
+ * and simply refuses to initialize, if the CPU type mis-matches;
+ * so we try each possible CPU type on aarch64 before giving up! */
+for (i = 0; i  KVM_ARM_NUM_TARGETS; ++i) {
+init.target = kvm_arm_targets[i];
+ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, init);
+if (!ret)
+break;
+}
+
+return ret;
 }
 
 int kvm_arch_put_registers(CPUState *cs, int level)
 {
-return 0;
+struct kvm_one_reg reg;
+int i;
+int ret;
+
+ARMCPU *cpu = ARM_CPU(cs);
+CPUARMState *env = cpu-env;
+
+for (i = 0; i  ARRAY_SIZE(env-xregs); i++) {
+reg.id = AARCH64_CORE_REG(regs.regs[i]);
+reg.addr = (uintptr_t) env-xregs[i];
+ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+}
+
+reg.id = AARCH64_CORE_REG(regs.sp);
+reg.addr = (uintptr_t) env-xregs[31];
+ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+reg.id = AARCH64_CORE_REG(regs.pstate);
+reg.addr = (uintptr_t) env-pstate;
+ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+reg.id = AARCH64_CORE_REG(regs.pc);
+reg.addr = (uintptr_t) env-pc;
+ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+/* TODO: Set Rest of Registers */
+return ret;
 }
 
 int kvm_arch_get_registers(CPUState *cs)
 {
-return 0;
+struct kvm_one_reg reg;
+int i;
+int ret;
+
+ARMCPU *cpu = ARM_CPU(cs);
+CPUARMState *env = cpu-env;
+
+for (i = 0; i  ARRAY_SIZE(env-xregs); i++) {
+reg.id = AARCH64_CORE_REG(regs.regs[i]);
+reg.addr = (uintptr_t) env-xregs[i];
+ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+}
+
+reg.id = AARCH64_CORE_REG(regs.sp);
+reg.addr = (uintptr_t) env-xregs[31];
+ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+reg.id = AARCH64_CORE_REG(regs.pstate);
+reg.addr = (uintptr_t) env-pstate;
+ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+reg.id = AARCH64_CORE_REG(regs.pc);
+reg.addr = (uintptr_t) env-pc;
+ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, reg);
+if (ret) {
+return ret;
+}
+
+/* TODO: Set Rest of Registers */
+return ret;
 }
 
 void kvm_arch_reset_vcpu(CPUState *cs)
-- 
1.8.1.2




[Qemu-devel] [PATCH v3 03/11] AARCH64: Add A57 CPU to default AArch64 configuration and enable KVM

2013-09-27 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

Introduce the A57 cpu to the default AArch64 configuration and enable KVM for
64-bit guests only.

Signed-off-by: Mian M. Hamayun m.hama...@virtualopensystems.com
---
 configure   | 2 +-
 default-configs/aarch64-softmmu.mak | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 2b83936..7298b69 100755
--- a/configure
+++ b/configure
@@ -4481,7 +4481,7 @@ case $target_name in
   *)
 esac
 case $target_name in
-  arm|i386|x86_64|ppcemb|ppc|ppc64|s390x)
+  arm|aarch64|i386|x86_64|ppcemb|ppc|ppc64|s390x)
 # Make sure the target and host cpus are compatible
 if test $kvm = yes -a $target_softmmu = yes -a \
   \( $target_name = $cpu -o \
diff --git a/default-configs/aarch64-softmmu.mak 
b/default-configs/aarch64-softmmu.mak
index 175362f..0eb3d96 100644
--- a/default-configs/aarch64-softmmu.mak
+++ b/default-configs/aarch64-softmmu.mak
@@ -37,6 +37,7 @@ CONFIG_USB_MUSB=y
 CONFIG_ARM11MPCORE=y
 CONFIG_A9MPCORE=y
 CONFIG_A15MPCORE=y
+CONFIG_A57MPCORE=y
 
 CONFIG_ARM_GIC=y
 CONFIG_ARM_GIC_KVM=$(CONFIG_KVM)
-- 
1.8.1.2




Re: [Qemu-devel] [PATCH] qemu-xen: make use of xenstore relative paths

2013-09-27 Thread Anthony PERARD
On Thu, Sep 26, 2013 at 07:20:31PM +0200, Roger Pau Monné wrote:
 On 26/09/13 18:46, Anthony PERARD wrote:
  On Wed, Sep 18, 2013 at 09:50:58PM +0200, Roger Pau Monne wrote:
  Qemu has several hardcoded xenstore paths that are only valid on Dom0.
  Attempts to launch a Qemu instance (to act as a userspace backend for
  PV disks) will fail because Qemu is not able to access those paths
  when running on a domain different than Dom0.
 
  Instead make the xenstore paths relative to the domain where Qemu is
  actually running.
 
  Signed-off-by: Roger Pau Monné roger@citrix.com
  Cc: xen-de...@lists.xenproject.org
  Cc: Anthony PERARD anthony.per...@citrix.com
  Cc: Stefano Stabellini stefano.stabell...@eu.citrix.com
  
  This look fine. One issue with the patch: the file xen_backend.c have
  been moved to hw/xen/xen_backend.c.
 
 Thanks, this is based on the stable Qemu version in Xen tree, I should
 have done the change on top of the main qemu.git repo.
 
  I've also tryied it in a stubdomain, and it does not boot anymore
  because the qemu in the stubdom can not read the state.  I have tried
  again without the change in xen-all.c, and the stubdom does not complain
  anymore. So in the change in xenstore_record_dm_state() needed as well?
 
 Yes, if we run a Qemu instance inside a driver domain it wouldn't make
 much sense IMHO to write the state of that Qemu instance on a xenstore
 path that belongs to the Dom0, and also we would need to give the driver
 domain permissions to write on a xenstore path that's inside the Dom0
 xenstore path, which doesn't seem like a good idea.
 
 To make Qemu work on a domain different than Dom0 you will also need the
 following patch from my driver domain series:
 
 http://marc.info/?l=xen-develm=137993233817018
 
 If not the guest is unable to create the device-model/domid/state
 xenstore entry. For stubdomains would it be really hard to change the
 Dom0 to check for /local/domain/stubdom_id/device-model/domid/state
 instead of /local/domain/0/device-model/domid/state?

I have tried with the patch applied to libxl, and stubdom work fine with
the changes to the xenstore paths. So, once the xen_backend.c file is in
the new path, you can add my:
Reviewed-by: Anthony PERARD anthony.per...@citrix.com

-- 
Anthony PERARD



Re: [Qemu-devel] [v2 30/71] hw/ide/Kconfig: Add Kconfig file

2013-09-27 Thread Stefan Hajnoczi
On Fri, Sep 27, 2013 at 04:30:51AM +0200, Ákos Kovács wrote:
 diff --git a/hw/net/Kconfig b/hw/net/Kconfig
 new file mode 100644
 index 000..19ca549
 --- /dev/null
 +++ b/hw/net/Kconfig

This should be a separate patch.

 @@ -0,0 +1,74 @@
 +menu Network devices
 +config DP8393X
 +bool
 +
 +config XEN_BACKEND
 +bool

Should all devices have a depends on $BUS so they can only be
configured if the bus is also configured?



Re: [Qemu-devel] [v2 33/71] hw/isa/Kconfig: Add Kconfig file

2013-09-27 Thread Stefan Hajnoczi
On Fri, Sep 27, 2013 at 04:30:54AM +0200, Ákos Kovács wrote:
 Signed-off-by: Ákos Kovács akoskov...@gmx.com
 ---
  hw/isa/Kconfig | 39 +++
  1 file changed, 39 insertions(+)
  create mode 100644 hw/isa/Kconfig
 
 diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
 new file mode 100644
 index 000..8f4beda
 --- /dev/null
 +++ b/hw/isa/Kconfig
 @@ -0,0 +1,39 @@
 +#config ISA
 +#   bool

Why is ISA commented out and all depends on ISA are also commented
out?



Re: [Qemu-devel] [v2 22/71] hw/block/Kconfig: Add Kconfig file

2013-09-27 Thread Stefan Hajnoczi
On Fri, Sep 27, 2013 at 04:30:43AM +0200, Ákos Kovács wrote:
 Signed-off-by: Ákos Kovács akoskov...@gmx.com
 ---
  hw/block/Kconfig | 31 +++
  1 file changed, 31 insertions(+)
  create mode 100644 hw/block/Kconfig
 
 diff --git a/hw/block/Kconfig b/hw/block/Kconfig
 new file mode 100644
 index 000..d7a7e61
 --- /dev/null
 +++ b/hw/block/Kconfig
 @@ -0,0 +1,31 @@
 +config FDC
 +bool
 +select I8257 if !SUN4M
 +#depends on ISA
 +
 +config SSI_M25P80
 +bool
 +depends on SSI
 +
 +config NAND
 +bool
 +
 +config PFLASH_CFI01
 +bool
 +
 +config PFLASH_CFI02
 +bool
 +
 +config ECC
 +bool
 +
 +config ONENAND
 +bool
 +
 +config PC_SYSFW
 +bool
 +#depends on ISA
 +
 +config NVME_PCI
 +bool
 +depends on PCI
 -- 
 1.8.1.2

Where is virtio-blk?

Stefan



Re: [Qemu-devel] [v2 22/71] hw/block/Kconfig: Add Kconfig file

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 13:14, Stefan Hajnoczi ha scritto:
 On Fri, Sep 27, 2013 at 04:30:43AM +0200, Ákos Kovács wrote:
 Signed-off-by: Ákos Kovács akoskov...@gmx.com
 ---
  hw/block/Kconfig | 31 +++
  1 file changed, 31 insertions(+)
  create mode 100644 hw/block/Kconfig

 diff --git a/hw/block/Kconfig b/hw/block/Kconfig
 new file mode 100644
 index 000..d7a7e61
 --- /dev/null
 +++ b/hw/block/Kconfig
 @@ -0,0 +1,31 @@
 +config FDC
 +bool
 +select I8257 if !SUN4M
 +#depends on ISA
 +
 +config SSI_M25P80
 +bool
 +depends on SSI
 +
 +config NAND
 +bool
 +
 +config PFLASH_CFI01
 +bool
 +
 +config PFLASH_CFI02
 +bool
 +
 +config ECC
 +bool
 +
 +config ONENAND
 +bool
 +
 +config PC_SYSFW
 +bool
 +#depends on ISA
 +
 +config NVME_PCI
 +bool
 +depends on PCI
 -- 
 1.8.1.2
 
 Where is virtio-blk?

Because of the proxy virtio-*-pci devices that are all defined in a
single file, all virtio devices are currently keyed by a single
CONFIG_VIRTIO symbol.  It could be indeed possible to split it and use
select dependencies, though.

Paolo



Re: [Qemu-devel] [v2 30/71] hw/ide/Kconfig: Add Kconfig file

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 13:11, Stefan Hajnoczi ha scritto:
 On Fri, Sep 27, 2013 at 04:30:51AM +0200, Ákos Kovács wrote:
 diff --git a/hw/net/Kconfig b/hw/net/Kconfig
 new file mode 100644
 index 000..19ca549
 --- /dev/null
 +++ b/hw/net/Kconfig
 
 This should be a separate patch.
 
 @@ -0,0 +1,74 @@
 +menu Network devices
 +config DP8393X
 +bool
 +
 +config XEN_BACKEND
 +bool
 
 Should all devices have a depends on $BUS so they can only be
 configured if the bus is also configured?

Yes, but DP8393X is not qdevified.

That said, XEN_BACKEND should be in hw/xen, not here.

Paolo



Re: [Qemu-devel] [v2 33/71] hw/isa/Kconfig: Add Kconfig file

2013-09-27 Thread Paolo Bonzini
Il 27/09/2013 13:13, Stefan Hajnoczi ha scritto:
 On Fri, Sep 27, 2013 at 04:30:54AM +0200, Ákos Kovács wrote:
 Signed-off-by: Ákos Kovács akoskov...@gmx.com
 ---
  hw/isa/Kconfig | 39 +++
  1 file changed, 39 insertions(+)
  create mode 100644 hw/isa/Kconfig

 diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
 new file mode 100644
 index 000..8f4beda
 --- /dev/null
 +++ b/hw/isa/Kconfig
 @@ -0,0 +1,39 @@
 +#config ISA
 +#   bool
 
 Why is ISA commented out and all depends on ISA are also commented
 out?
 
 

I've been asking Akos about that for about a month. :)

Paolo



Re: [Qemu-devel] [PATCH v3 2/3] block: qemu-iotests for vhdx, read sample dynamic image

2013-09-27 Thread Jeff Cody
On Fri, Sep 27, 2013 at 11:14:55AM +0200, Kevin Wolf wrote:
 Am 25.09.2013 um 14:12 hat Jeff Cody geschrieben:
  This adds the VHDX format to the qemu-iotests format, and adds
  a read test.  The test reads from an existing sample image, that
  was created with Hyper-V under Windwos Server 2012.
  
  The image file is a 1GB dynamic image, with 32MB blocks.
  
  The pattern 0xa5 exists from 0MB-33MB (past a block size boundary)
  
  The pattern 0x96 exists from 33MB-66MB (past another block boundary,
  and leaving a partial blank block)
  
  From 66MB-1024MB, all reads should return 0.
  
  Although 1GB dynamic image with 66MB of data, the bzip2'ed image
  file size is only 874 bytes.
  
  Signed-off-by: Jeff Cody jc...@redhat.com
  Reviewed-by: Stefan Hajnoczi stefa...@redhat.com
 
  diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
  new file mode 100644
  index 000..b9e8e4a
  --- /dev/null
  +++ b/tests/qemu-iotests/064.out
  @@ -0,0 +1,14 @@
  +QA output created by 064
  +
  +=== Verify pattern 0xa5, 0 - 33MB ===
  +read 34603008/34603008 bytes at offset 0
  +33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
  +
  +=== Verify pattern 0x96, 33M - 66M ===
  +read 34603008/34603008 bytes at offset 34603008
  +33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
  +
  +=== Verify pattern 0x00, 66M - 1024M ===
  +read 1004535808/1004535808 bytes at offset 69206016
  +958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
  +*** done
 
 Doesn't work for me. Am I missing patches that need to be applied first?


I need to add -r to the QEMU_IO arguments.  I had tested this on my
rebased vhdx branch, which has r/w support, so I missed that.  QEMU on
qemu/master will refuse to open a VHDX image r/w.

Submitting a v4 with this change (just this patch since you applied
the other two)


 064 1s ...[11:09:58] [11:09:59] - output mismatch (see 064.out.bad)
 --- 064.out 2013-09-27 11:00:37.077677734 +0200
 +++ 064.out.bad 2013-09-27 11:09:59.704298133 +0200
 @@ -1,14 +1,14 @@
  QA output created by 064
  
  === Verify pattern 0xa5, 0 - 33MB ===
 -read 34603008/34603008 bytes at offset 0
 -33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +qemu-io: can't open device 
 /home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
 Could not open 
 '/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
 Operation not supported
 +no file open, try 'help open'
  
  === Verify pattern 0x96, 33M - 66M ===
 -read 34603008/34603008 bytes at offset 34603008
 -33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +qemu-io: can't open device 
 /home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
 Could not open 
 '/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
 Operation not supported
 +no file open, try 'help open'
  
  === Verify pattern 0x00, 66M - 1024M ===
 -read 1004535808/1004535808 bytes at offset 69206016
 -958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +qemu-io: can't open device 
 /home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx: 
 Could not open 
 '/home/kwolf/source/qemu/tests/qemu-iotests/scratch/iotest-dynamic-1G.vhdx': 
 Operation not supported
 +no file open, try 'help open'
  *** done
 
 Kevin
 



Re: [Qemu-devel] [PATCH v2 0/2] qcow2: count_contiguous_clusters and compression

2013-09-27 Thread Kevin Wolf
Am 27.09.2013 um 12:14 hat Max Reitz geschrieben:
 Compressed clusters can never be contiguous and count_contiguous_clusters
 will not even work correctly for them. Therefore, those cluster should
 always be treated as non-contiguous.
 
 This series makes count_contiguous_clusters always stop at compressed
 clusters and removes the corresponding flag from its function calls.
 
 v2:
  - added patch 2 (following Kevin's proposal)
  - patch 1 remains unmodified

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PATCH] qcow2: Remove useless count_contiguous_clusters() parameter

2013-09-27 Thread Kevin Wolf
All callers pass start = 0, and it's doubtful if any other value would
actually do what you expect. Remove the parameter.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/qcow2-cluster.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 029c805..72cb573 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -285,7 +285,7 @@ fail:
  * cluster which may require a different handling)
  */
 static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
-uint64_t *l2_table, uint64_t start, uint64_t stop_flags)
+uint64_t *l2_table, uint64_t stop_flags)
 {
 int i;
 uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED;
@@ -297,14 +297,14 @@ static int count_contiguous_clusters(uint64_t 
nb_clusters, int cluster_size,
 
 assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED);
 
-for (i = start; i  start + nb_clusters; i++) {
+for (i = 0; i  nb_clusters; i++) {
 uint64_t l2_entry = be64_to_cpu(l2_table[i])  mask;
 if (offset + (uint64_t) i * cluster_size != l2_entry) {
 break;
 }
 }
 
-   return (i - start);
+   return i;
 }
 
 static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t 
*l2_table)
@@ -497,7 +497,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t 
offset,
 return -EIO;
 }
 c = count_contiguous_clusters(nb_clusters, s-cluster_size,
-l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
+l2_table[l2_index], QCOW_OFLAG_ZERO);
 *cluster_offset = 0;
 break;
 case QCOW2_CLUSTER_UNALLOCATED:
@@ -508,7 +508,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t 
offset,
 case QCOW2_CLUSTER_NORMAL:
 /* how many allocated clusters ? */
 c = count_contiguous_clusters(nb_clusters, s-cluster_size,
-l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
+l2_table[l2_index], QCOW_OFLAG_ZERO);
 *cluster_offset = L2E_OFFSET_MASK;
 break;
 default:
@@ -938,7 +938,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
guest_offset,
 /* We keep all QCOW_OFLAG_COPIED clusters */
 keep_clusters =
 count_contiguous_clusters(nb_clusters, s-cluster_size,
-  l2_table[l2_index], 0,
+  l2_table[l2_index],
   QCOW_OFLAG_COPIED | QCOW_OFLAG_ZERO);
 assert(keep_clusters = nb_clusters);
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 05/11] linux-user: allow use of TIOCGSID

2013-09-27 Thread riku . voipio
From: Laurent Vivier laur...@vivier.eu

Signed-off-by: Laurent Vivier laur...@vivier.eu
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/ioctls.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 439c2a9..7381012 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -20,6 +20,7 @@
  IOCTL(TIOCSCTTY, 0, TYPE_INT)
  IOCTL(TIOCGPGRP, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(TIOCSPGRP, IOC_W, MK_PTR(TYPE_INT))
+ IOCTL(TIOCGSID, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(TIOCOUTQ, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(TIOCSTI, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(TIOCMGET, IOC_R, MK_PTR(TYPE_INT))
-- 
1.8.1.2




[Qemu-devel] [PATCH 01/11] alpha-linux-user: Fix umount syscall numbers

2013-09-27 Thread riku . voipio
From: Richard Henderson r...@twiddle.net

It has been pointed out on LKML that the alpha umount syscall numbers
are named wrong, and a patch to rectify that has been posted for 3.11.

Glibc works around this by treating NR_umount as NR_umount2 if
NR_oldumount exists.  That's more complicated than we need in QEMU,
given that we control linux-user/*/syscall_nr.h.

This is the last instance of TARGET_NR_oldumount, so delete that from
the strace.list.

Signed-off-by: Richard Henderson r...@twiddle.net
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/alpha/syscall_nr.h | 4 ++--
 linux-user/strace.list| 3 ---
 linux-user/syscall.c  | 2 +-
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/linux-user/alpha/syscall_nr.h b/linux-user/alpha/syscall_nr.h
index ac2b6e2..d52d76e 100644
--- a/linux-user/alpha/syscall_nr.h
+++ b/linux-user/alpha/syscall_nr.h
@@ -20,7 +20,7 @@
 #define TARGET_NR_lseek 19
 #define TARGET_NR_getxpid   20
 #define TARGET_NR_osf_mount 21
-#define TARGET_NR_umount22
+#define TARGET_NR_umount2   22
 #define TARGET_NR_setuid23
 #define TARGET_NR_getxuid   24
 #define TARGET_NR_exec_with_loader  25 /* not implemented */
@@ -255,7 +255,7 @@
 #define TARGET_NR_sysinfo  318
 #define TARGET_NR__sysctl  319
 /* 320 was sys_idle.  */
-#define TARGET_NR_oldumount321
+#define TARGET_NR_umount   321
 #define TARGET_NR_swapon   322
 #define TARGET_NR_times323
 #define TARGET_NR_personality  324
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 08f115d..4f9c364 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -612,9 +612,6 @@
 #ifdef TARGET_NR_oldstat
 { TARGET_NR_oldstat, oldstat , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_oldumount
-{ TARGET_NR_oldumount, oldumount , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_olduname
 { TARGET_NR_olduname, olduname , NULL, NULL, NULL },
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c62d875..5c33e44 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5697,7 +5697,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 unlock_user(p, arg1, 0);
 }
 break;
-#ifdef TARGET_NR_umount2 /* not on alpha */
+#ifdef TARGET_NR_umount2
 case TARGET_NR_umount2:
 if (!(p = lock_user_string(arg1)))
 goto efault;
-- 
1.8.1.2




[Qemu-devel] [PATCH 04/11] linux-user: Add setsockopt(SO_ATTACH_FILTER)

2013-09-27 Thread riku . voipio
From: Laurent Vivier laur...@vivier.eu

This is needed to be able to run dhclient.

Signed-off-by: Laurent Vivier laur...@vivier.eu
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c  | 44 
 linux-user/syscall_defs.h | 12 
 2 files changed, 56 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 251c116..505031b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -106,6 +106,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include linux/dm-ioctl.h
 #include linux/reboot.h
 #include linux/route.h
+#include linux/filter.h
 #include linux_loop.h
 #include cpu-uname.h
 
@@ -1357,6 +1358,49 @@ set_timeout:
 case TARGET_SO_SNDTIMEO:
 optname = SO_SNDTIMEO;
 goto set_timeout;
+case TARGET_SO_ATTACH_FILTER:
+{
+struct target_sock_fprog *tfprog;
+struct target_sock_filter *tfilter;
+struct sock_fprog fprog;
+struct sock_filter *filter;
+int i;
+
+if (optlen != sizeof(*tfprog)) {
+return -TARGET_EINVAL;
+}
+if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)) {
+return -TARGET_EFAULT;
+}
+if (!lock_user_struct(VERIFY_READ, tfilter,
+  tswapal(tfprog-filter), 0)) {
+unlock_user_struct(tfprog, optval_addr, 1);
+return -TARGET_EFAULT;
+}
+
+fprog.len = tswap16(tfprog-len);
+filter = malloc(fprog.len * sizeof(*filter));
+if (filter == NULL) {
+unlock_user_struct(tfilter, tfprog-filter, 1);
+unlock_user_struct(tfprog, optval_addr, 1);
+return -TARGET_ENOMEM;
+}
+for (i = 0; i  fprog.len; i++) {
+filter[i].code = tswap16(tfilter[i].code);
+filter[i].jt = tfilter[i].jt;
+filter[i].jf = tfilter[i].jf;
+filter[i].k = tswap32(tfilter[i].k);
+}
+fprog.filter = filter;
+
+ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+SO_ATTACH_FILTER, fprog, sizeof(fprog)));
+free(filter);
+
+unlock_user_struct(tfilter, tfprog-filter, 1);
+unlock_user_struct(tfprog, optval_addr, 1);
+return ret;
+}
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
optname = SO_DEBUG;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 2ebe356..5f53a28 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -119,6 +119,18 @@ struct target_sockaddr {
 uint8_t sa_data[14];
 };
 
+struct target_sock_filter {
+abi_ushort code;
+uint8_t jt;
+uint8_t jf;
+abi_uint k;
+};
+
+struct target_sock_fprog {
+abi_ushort len;
+abi_ulong filter;
+};
+
 struct target_in_addr {
 uint32_t s_addr; /* big endian */
 };
-- 
1.8.1.2




[Qemu-devel] [PATCH 02/11] mips-linux-user: Adjust names in mips_syscall_args

2013-09-27 Thread riku . voipio
From: Richard Henderson r...@twiddle.net

The name field of MIPS_SYS isn't actually used; it's just documentation.
But adjust the umount entries to match mips/syscall_nr.h anyway.

Signed-off-by: Richard Henderson r...@twiddle.net
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 01e3cd4..3eed252 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1861,7 +1861,7 @@ static const uint8_t mips_syscall_args[] = {
MIPS_SYS(sys_lseek  , 3)
MIPS_SYS(sys_getpid , 0)/* 4020 */
MIPS_SYS(sys_mount  , 5)
-   MIPS_SYS(sys_oldumount  , 1)
+   MIPS_SYS(sys_umount , 1)
MIPS_SYS(sys_setuid , 1)
MIPS_SYS(sys_getuid , 0)
MIPS_SYS(sys_stime  , 1)/* 4025 */
@@ -1891,7 +1891,7 @@ static const uint8_t mips_syscall_args[] = {
MIPS_SYS(sys_geteuid, 0)
MIPS_SYS(sys_getegid, 0)/* 4050 */
MIPS_SYS(sys_acct   , 0)
-   MIPS_SYS(sys_umount , 2)
+   MIPS_SYS(sys_umount2, 2)
MIPS_SYS(sys_ni_syscall , 0)
MIPS_SYS(sys_ioctl  , 3)
MIPS_SYS(sys_fcntl  , 3)/* 4055 */
-- 
1.8.1.2




[Qemu-devel] [PATCH 03/11] linux-user: convert /proc/net/route when endianess differs

2013-09-27 Thread riku . voipio
From: Laurent Vivier laur...@vivier.eu

This patch allows to have IP addresses in correct order
in the case of netstat -nr when the endianess of the
guest differs from one of the host.

For instance, an m68k guest on an x86_64 host:

WITHOUT this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 1.3.0.100.0.0.0 UG0 0  0 eth0
0.3.0.100.0.0.0 0.255.255.255   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT

eth00103000A00030   0   0   
0   0   0
eth00003000A00010   0   0   
00FF0   0   0

WITH this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT
eth00a00030100030   0   0   
0   0   0
eth00a00030000010   0   0   
ff000   0   0

Signed-off-by: Laurent Vivier laur...@vivier.eu
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 58 +++-
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5c33e44..251c116 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5071,22 +5071,70 @@ static int is_proc_myself(const char *filename, const 
char *entry)
 return 0;
 }
 
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+static int is_proc(const char *filename, const char *entry)
+{
+return strcmp(filename, entry) == 0;
+}
+
+static int open_net_route(void *cpu_env, int fd)
+{
+FILE *fp;
+char *line = NULL;
+size_t len = 0;
+ssize_t read;
+
+fp = fopen(/proc/net/route, r);
+if (fp == NULL) {
+return -EACCES;
+}
+
+/* read header */
+
+read = getline(line, len, fp);
+dprintf(fd, %s, line);
+
+/* read routes */
+
+while ((read = getline(line, len, fp)) != -1) {
+char iface[16];
+uint32_t dest, gw, mask;
+unsigned int flags, refcnt, use, metric, mtu, window, irtt;
+sscanf(line, %s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n,
+ iface, dest, gw, flags, refcnt, use, metric,
+ mask, mtu, window, irtt);
+dprintf(fd, %s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n,
+iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
+metric, tswap32(mask), mtu, window, irtt);
+}
+
+free(line);
+fclose(fp);
+
+return 0;
+}
+#endif
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
 const char *filename;
 int (*fill)(void *cpu_env, int fd);
+int (*cmp)(const char *s1, const char *s2);
 };
 const struct fake_open *fake_open;
 static const struct fake_open fakes[] = {
-{ maps, open_self_maps },
-{ stat, open_self_stat },
-{ auxv, open_self_auxv },
-{ NULL, NULL }
+{ maps, open_self_maps, is_proc_myself },
+{ stat, open_self_stat, is_proc_myself },
+{ auxv, open_self_auxv, is_proc_myself },
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+{ /proc/net/route, open_net_route, is_proc },
+#endif
+{ NULL, NULL, NULL }
 };
 
 for (fake_open = fakes; fake_open-filename; fake_open++) {
-if (is_proc_myself(pathname, fake_open-filename)) {
+if (fake_open-cmp(pathname, fake_open-filename)) {
 break;
 }
 }
-- 
1.8.1.2




[Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates

2013-09-27 Thread riku . voipio
From: Riku Voipio riku.voi...@linaro.org

The following changes since commit f828a4c8faa118e0ebab3e353ac6840f3b2a0318:

  Merge remote-tracking branch 'stefanha/tracing' into staging (2013-09-23 
11:53:22 -0500)

are available in the git repository at:

  git://git.linaro.org/people/rikuvoipio/qemu.git linux-user-for-upstream

for you to fetch changes up to 53d09b761f032f50c4424e8649396a9041070bae:

  linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host (2013-09-24 
10:47:07 +0300)



Edgar E. Iglesias (1):
  linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host

Kwok Cheung Yeung (1):
  linux-user: Check type of microMIPS break instruction

Laurent Vivier (5):
  linux-user: convert /proc/net/route when endianess differs
  linux-user: Add setsockopt(SO_ATTACH_FILTER)
  linux-user: allow use of TIOCGSID
  linux-user: add some IPV6 commands in setsockop()
  linux-user: add support of binfmt_misc 'O' flag

Petar Jovanovic (1):
  linux-user: correct how SOL_SOCKET is converted from target to host
and back

Richard Henderson (2):
  alpha-linux-user: Fix umount syscall numbers
  mips-linux-user: Adjust names in mips_syscall_args

Riku Voipio (1):
  [v2] linux-user: implement m68k atomic syscalls

 linux-user/alpha/syscall_nr.h |   4 +-
 linux-user/ioctls.h   |   1 +
 linux-user/linuxload.c|   8 +-
 linux-user/main.c |  92 +-
 linux-user/qemu.h |   2 +-
 linux-user/strace.list|   9 +-
 linux-user/syscall.c  | 210 +++---
 linux-user/syscall_defs.h |  12 +++
 8 files changed, 288 insertions(+), 50 deletions(-)

-- 
1.8.1.2




[Qemu-devel] [PATCH 08/11] linux-user: correct how SOL_SOCKET is converted from target to host and back

2013-09-27 Thread riku . voipio
From: Petar Jovanovic petar.jovano...@imgtec.com

Previous implementation does not take into account that SOL_SOCKET constant
can be arch specific. This change fixes some issues with sendmsg/recvmsg.

Signed-off-by: Petar Jovanovic petar.jovano...@imgtec.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7a093ba..aebe36d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1150,11 +1150,15 @@ static inline abi_long target_to_host_cmsg(struct 
msghdr *msgh,
 break;
 }
 
-cmsg-cmsg_level = tswap32(target_cmsg-cmsg_level);
+if (tswap32(target_cmsg-cmsg_level) == TARGET_SOL_SOCKET) {
+cmsg-cmsg_level = SOL_SOCKET;
+} else {
+cmsg-cmsg_level = tswap32(target_cmsg-cmsg_level);
+}
 cmsg-cmsg_type = tswap32(target_cmsg-cmsg_type);
 cmsg-cmsg_len = CMSG_LEN(len);
 
-if (cmsg-cmsg_level != TARGET_SOL_SOCKET || cmsg-cmsg_type != 
SCM_RIGHTS) {
+if (cmsg-cmsg_level != SOL_SOCKET || cmsg-cmsg_type != SCM_RIGHTS) {
 gemu_log(Unsupported ancillary data: %d/%d\n, cmsg-cmsg_level, 
cmsg-cmsg_type);
 memcpy(data, target_data, len);
 } else {
@@ -1205,11 +1209,15 @@ static inline abi_long host_to_target_cmsg(struct 
target_msghdr *target_msgh,
 break;
 }
 
-target_cmsg-cmsg_level = tswap32(cmsg-cmsg_level);
+if (cmsg-cmsg_level == SOL_SOCKET) {
+target_cmsg-cmsg_level = tswap32(TARGET_SOL_SOCKET);
+} else {
+target_cmsg-cmsg_level = tswap32(cmsg-cmsg_level);
+}
 target_cmsg-cmsg_type = tswap32(cmsg-cmsg_type);
 target_cmsg-cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-if ((cmsg-cmsg_level == TARGET_SOL_SOCKET) 
+if ((cmsg-cmsg_level == SOL_SOCKET) 
 (cmsg-cmsg_type == SCM_RIGHTS)) {
 int *fd = (int *)data;
 int *target_fd = (int *)target_data;
@@ -1217,7 +1225,7 @@ static inline abi_long host_to_target_cmsg(struct 
target_msghdr *target_msgh,
 
 for (i = 0; i  numfds; i++)
 target_fd[i] = tswap32(fd[i]);
-} else if ((cmsg-cmsg_level == TARGET_SOL_SOCKET) 
+} else if ((cmsg-cmsg_level == SOL_SOCKET) 
 (cmsg-cmsg_type == SO_TIMESTAMP) 
 (len == sizeof(struct timeval))) {
 /* copy struct timeval to target */
-- 
1.8.1.2




[Qemu-devel] [PATCH 07/11] linux-user: add support of binfmt_misc 'O' flag

2013-09-27 Thread riku . voipio
From: Laurent Vivier laur...@vivier.eu

The binfmt_misc module can calculate the credentials and security
token according to the binary instead of to the interpreter if the
'C' flag is enabled.

To be able to execute non-readable binaries, this flag implies 'O'
flag. When 'O' flag is enabled, bintfmt_misc opens the file for
reading and pass the file descriptor to the interpreter.

References:
linux/Documentation/binfmt_misc.txt  ['O' and 'C' description]
linux/fs/binfmt_misc.c linux/fs/binfmt_elf.c [ AT_EXECFD usage ]

Signed-off-by: Laurent Vivier laur...@vivier.eu
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/linuxload.c |  8 ++--
 linux-user/main.c  | 32 +++-
 linux-user/qemu.h  |  2 +-
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 5cd6d91..a1fe5ed 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -131,7 +131,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong 
sp,
 return sp;
 }
 
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *bprm)
 {
@@ -140,11 +140,7 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
 
 bprm-p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
 memset(bprm-page, 0, sizeof(bprm-page));
-retval = open(filename, O_RDONLY);
-if (retval  0) {
-return -errno;
-}
-bprm-fd = retval;
+bprm-fd = fdexec;
 bprm-filename = (char *)filename;
 bprm-argc = count(argv);
 bprm-argv = argv;
diff --git a/linux-user/main.c b/linux-user/main.c
index 3eed252..016e2e1 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3618,6 +3618,26 @@ static int parse_args(int argc, char **argv)
 return optind;
 }
 
+static int get_execfd(char **envp)
+{
+typedef struct {
+long a_type;
+long a_val;
+} auxv_t;
+auxv_t *auxv;
+
+while (*envp++ != NULL) {
+;
+}
+
+for (auxv = (auxv_t *)envp; auxv-a_type != AT_NULL; auxv++) {
+if (auxv-a_type == AT_EXECFD) {
+return auxv-a_val;
+}
+}
+return -1;
+}
+
 int main(int argc, char **argv, char **envp)
 {
 struct target_pt_regs regs1, *regs = regs1;
@@ -3632,6 +3652,7 @@ int main(int argc, char **argv, char **envp)
 int target_argc;
 int i;
 int ret;
+int execfd;
 
 module_call_init(MODULE_INIT_QOM);
 
@@ -3809,7 +3830,16 @@ int main(int argc, char **argv, char **envp)
 env-opaque = ts;
 task_settid(ts);
 
-ret = loader_exec(filename, target_argv, target_environ, regs,
+execfd = get_execfd(envp);
+if (execfd  0) {
+execfd = open(filename, O_RDONLY);
+}
+if (execfd  0) {
+printf(Error while loading %s: %s\n, filename, strerror(-execfd));
+_exit(1);
+}
+
+ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
 info, bprm);
 if (ret != 0) {
 printf(Error while loading %s: %s\n, filename, strerror(-ret));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 617cac1..da64e87 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -174,7 +174,7 @@ struct linux_binprm {
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
   abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *);
 
-- 
1.8.1.2




[Qemu-devel] [PATCH 09/11] linux-user: Check type of microMIPS break instruction

2013-09-27 Thread riku . voipio
From: Kwok Cheung Yeung k...@codesourcery.com

microMIPS instructions that cause breakpoint exceptions come in
16-bit and 32-bit variants.  When handling exceptions caused by
such instructions, the instruction type needs to be taken into
account when extracting the break code.

The code has also been restructured for better clarity.

Signed-off-by: Kwok Cheung Yeung k...@codesourcery.com
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/main.c | 56 ++-
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 016e2e1..1561950 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2400,12 +2400,31 @@ done_syscall:
 if (env-hflags  MIPS_HFLAG_M16) {
 if (env-insn_flags  ASE_MICROMIPS) {
 /* microMIPS mode */
-abi_ulong instr[2];
-
-ret = get_user_u16(instr[0], env-active_tc.PC) ||
-  get_user_u16(instr[1], env-active_tc.PC + 2);
+ret = get_user_u16(trap_instr, env-active_tc.PC);
+if (ret != 0) {
+goto error;
+}
 
-trap_instr = (instr[0]  16) | instr[1];
+if ((trap_instr  10) == 0x11) {
+/* 16-bit instruction */
+code = trap_instr  0xf;
+} else {
+/* 32-bit instruction */
+abi_ulong instr_lo;
+
+ret = get_user_u16(instr_lo,
+   env-active_tc.PC + 2);
+if (ret != 0) {
+goto error;
+}
+trap_instr = (trap_instr  16) | instr_lo;
+code = ((trap_instr  6)  ((1  20) - 1));
+/* Unfortunately, microMIPS also suffers from
+   the old assembler bug...  */
+if (code = (1  10)) {
+code = 10;
+}
+}
 } else {
 /* MIPS16e mode */
 ret = get_user_u16(trap_instr, env-active_tc.PC);
@@ -2413,26 +2432,21 @@ done_syscall:
 goto error;
 }
 code = (trap_instr  6)  0x3f;
-if (do_break(env, info, code) != 0) {
-goto error;
-}
-break;
 }
 } else {
 ret = get_user_ual(trap_instr, env-active_tc.PC);
-}
-
-if (ret != 0) {
-goto error;
-}
+if (ret != 0) {
+goto error;
+}
 
-/* As described in the original Linux kernel code, the
- * below checks on 'code' are to work around an old
- * assembly bug.
- */
-code = ((trap_instr  6)  ((1  20) - 1));
-if (code = (1  10)) {
-code = 10;
+/* As described in the original Linux kernel code, the
+ * below checks on 'code' are to work around an old
+ * assembly bug.
+ */
+code = ((trap_instr  6)  ((1  20) - 1));
+if (code = (1  10)) {
+code = 10;
+}
 }
 
 if (do_break(env, info, code) != 0) {
-- 
1.8.1.2




[Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host

2013-09-27 Thread riku . voipio
From: Edgar E. Iglesias edgar.igles...@gmail.com

If the host lacks SOCK_CLOEXEC, bail out with -EINVAL.
If the host lacks SOCK_ONONBLOCK, try to emulate it with fcntl()
and O_NONBLOCK.

Signed-off-by: Edgar E. Iglesias edgar.igles...@gmail.com
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 40 +---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b3822b3..4a14a43 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1773,7 +1773,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong 
target_addr,
 free(vec);
 }
 
-static inline void target_to_host_sock_type(int *type)
+static inline int target_to_host_sock_type(int *type)
 {
 int host_type = 0;
 int target_type = *type;
@@ -1790,22 +1790,56 @@ static inline void target_to_host_sock_type(int *type)
 break;
 }
 if (target_type  TARGET_SOCK_CLOEXEC) {
+#if defined(SOCK_CLOEXEC)
 host_type |= SOCK_CLOEXEC;
+#else
+return -TARGET_EINVAL;
+#endif
 }
 if (target_type  TARGET_SOCK_NONBLOCK) {
+#if defined(SOCK_NONBLOCK)
 host_type |= SOCK_NONBLOCK;
+#elif !defined(O_NONBLOCK)
+return -TARGET_EINVAL;
+#endif
 }
 *type = host_type;
+return 0;
+}
+
+/* Try to emulate socket type flags after socket creation.  */
+static int sock_flags_fixup(int fd, int target_type)
+{
+#if !defined(SOCK_NONBLOCK)  defined(O_NONBLOCK)
+if (target_type  TARGET_SOCK_NONBLOCK) {
+int flags = fcntl(fd, F_GETFL);
+if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) {
+close(fd);
+return -TARGET_EINVAL;
+}
+}
+#endif
+return fd;
 }
 
 /* do_socket() Must return target values and target errnos. */
 static abi_long do_socket(int domain, int type, int protocol)
 {
-target_to_host_sock_type(type);
+int target_type = type;
+int ret;
+
+ret = target_to_host_sock_type(type);
+if (ret) {
+return ret;
+}
 
 if (domain == PF_NETLINK)
 return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
-return get_errno(socket(domain, type, protocol));
+ret = get_errno(socket(domain, type, protocol));
+if (ret = 0) {
+ret = sock_flags_fixup(ret, target_type);
+}
+return ret;
 }
 
 /* do_bind() Must return target values and target errnos. */
-- 
1.8.1.2




[Qemu-devel] [PATCH 06/11] linux-user: add some IPV6 commands in setsockop()

2013-09-27 Thread riku . voipio
From: Laurent Vivier laur...@vivier.eu

Signed-off-by: Laurent Vivier laur...@vivier.eu
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/syscall.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 505031b..7a093ba 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1315,6 +1315,26 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 goto unimplemented;
 }
 break;
+case SOL_IPV6:
+switch (optname) {
+case IPV6_MTU_DISCOVER:
+case IPV6_MTU:
+case IPV6_V6ONLY:
+case IPV6_RECVPKTINFO:
+val = 0;
+if (optlen  sizeof(uint32_t)) {
+return -TARGET_EINVAL;
+}
+if (get_user_u32(val, optval_addr)) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(setsockopt(sockfd, level, optname,
+   val, sizeof(val)));
+break;
+default:
+goto unimplemented;
+}
+break;
 case SOL_RAW:
 switch (optname) {
 case ICMP_FILTER:
-- 
1.8.1.2




[Qemu-devel] [PATCH 10/11] [v2] linux-user: implement m68k atomic syscalls

2013-09-27 Thread riku . voipio
From: Riku Voipio riku.voi...@linaro.org

With nptl enabled, atomic_cmpxchg_32 and atomic_barrier
system calls are needed. This patch enabled really dummy
versions of the system calls, modeled after the m68k
kernel code.

With this patch I am able to execute m68k binaries
with qemu linux-user (busybox compiled for coldfire).

[v2] que an segfault instead of returning a EFAULT
to keep in line with kernel code.

Cc: Laurent Vivier laur...@vivier.eu
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/strace.list |  6 ++
 linux-user/syscall.c   | 28 
 2 files changed, 34 insertions(+)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 4f9c364..cf5841a 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1521,3 +1521,9 @@
 #ifdef TARGET_NR_pipe2
 { TARGET_NR_pipe2, pipe2, NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_atomic_cmpxchg_32
+{ TARGET_NR_atomic_cmpxchg_32, atomic_cmpxchg_32, NULL, NULL, NULL },
+#endif
+#ifdef TARGET_NR_atomic_barrier
+{ TARGET_NR_atomic_barrier, atomic_barrier, NULL, NULL, NULL },
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index aebe36d..b3822b3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9133,6 +9133,34 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 }
 #endif
+#ifdef TARGET_NR_atomic_cmpxchg_32
+case TARGET_NR_atomic_cmpxchg_32:
+{
+/* should use start_exclusive from main.c */
+abi_ulong mem_value;
+if (get_user_u32(mem_value, arg6)) {
+target_siginfo_t info;
+info.si_signo = SIGSEGV;
+info.si_errno = 0;
+info.si_code = TARGET_SEGV_MAPERR;
+info._sifields._sigfault._addr = arg6;
+queue_signal((CPUArchState *)cpu_env, info.si_signo, info);
+ret = 0xdeadbeef;
+
+}
+if (mem_value == arg2)
+put_user_u32(arg1, arg6);
+ret = mem_value;
+break;
+}
+#endif
+#ifdef TARGET_NR_atomic_barrier
+case TARGET_NR_atomic_barrier:
+{
+/* Like the kernel implementation and the qemu arm barrier, no-op 
this? */
+break;
+}
+#endif
 default:
 unimplemented:
 gemu_log(qemu: Unsupported syscall: %d\n, num);
-- 
1.8.1.2




[Qemu-devel] [PATCH v4] block: qemu-iotests for vhdx, read sample dynamic image

2013-09-27 Thread Jeff Cody
This adds the VHDX format to the qemu-iotests format, and adds
a read test.  The test reads from an existing sample image, that
was created with Hyper-V under Windwos Server 2012.

The image file is a 1GB dynamic image, with 32MB blocks.

The pattern 0xa5 exists from 0MB-33MB (past a block size boundary)

The pattern 0x96 exists from 33MB-66MB (past another block boundary,
and leaving a partial blank block)

From 66MB-1024MB, all reads should return 0.

Although 1GB dynamic image with 66MB of data, the bzip2'ed image
file size is only 874 bytes.

This also adds in the IMGFMT_GENERIC flag, so r/o images can be
tested (e.g. ./check -vhdx) without failing tests that assume
r/w support.

Signed-off-by: Jeff Cody jc...@redhat.com
---
 tests/qemu-iotests/064 |  62 +
 tests/qemu-iotests/064.out |  14 +
 tests/qemu-iotests/common  |   8 +++
 tests/qemu-iotests/common.rc   |   2 +-
 tests/qemu-iotests/group   |   1 +
 .../sample_images/iotest-dynamic-1G.vhdx.bz2   | Bin 0 - 874 bytes
 6 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/064
 create mode 100644 tests/qemu-iotests/064.out
 create mode 100644 tests/qemu-iotests/sample_images/iotest-dynamic-1G.vhdx.bz2

diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
new file mode 100755
index 000..6789aa6
--- /dev/null
+++ b/tests/qemu-iotests/064
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Test VHDX read/write from a sample image created with Hyper-V
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+# creator
+owner=jc...@redhat.com
+
+seq=`basename $0`
+echo QA output created by $seq
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+
+_cleanup()
+{
+_cleanup_test_img
+}
+trap _cleanup; exit \$status 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt vhdx
+_supported_proto generic
+_supported_os Linux
+
+_use_sample_img iotest-dynamic-1G.vhdx.bz2
+
+echo
+echo === Verify pattern 0xa5, 0 - 33MB ===
+$QEMU_IO -r -c read -pP 0xa5 0 33M $TEST_IMG | _filter_qemu_io
+
+echo
+echo === Verify pattern 0x96, 33M - 66M ===
+$QEMU_IO -r -c read -pP 0x96 33M 33M $TEST_IMG | _filter_qemu_io
+
+echo
+echo === Verify pattern 0x00, 66M - 1024M ===
+$QEMU_IO -r -c read -pP 0x00 66M 958M $TEST_IMG | _filter_qemu_io
+
+# success, all done
+echo *** done
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
new file mode 100644
index 000..b9e8e4a
--- /dev/null
+++ b/tests/qemu-iotests/064.out
@@ -0,0 +1,14 @@
+QA output created by 064
+
+=== Verify pattern 0xa5, 0 - 33MB ===
+read 34603008/34603008 bytes at offset 0
+33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify pattern 0x96, 33M - 66M ===
+read 34603008/34603008 bytes at offset 34603008
+33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify pattern 0x00, 66M - 1024M ===
+read 1004535808/1004535808 bytes at offset 69206016
+958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+*** done
diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common
index fecaf85..2932e14 100644
--- a/tests/qemu-iotests/common
+++ b/tests/qemu-iotests/common
@@ -45,6 +45,7 @@ valgrind=false
 rm -f $tmp.list $tmp.tmp $tmp.sed
 
 export IMGFMT=raw
+export IMGFMT_GENERIC=true
 export IMGPROTO=file
 export IMGOPTS=
 export QEMU_IO_OPTIONS=
@@ -133,6 +134,7 @@ check options
 -qedtest qed
 -vditest vdi
 -vpctest vpc
+-vhdx   test vhdx
 -vmdk   test vmdk
 -rbdtest rbd
 -sheepdog   test sheepdog
@@ -195,6 +197,12 @@ testlist options
 xpand=false
 ;;
 
+-vhdx)
+IMGFMT=vhdx
+xpand=false
+IMGFMT_GENERIC=false
+;;
+
 -rbd)
 IMGPROTO=rbd
 xpand=false
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 6730955..d3ed152 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -321,7 +321,7 @@ _fail()
 _supported_fmt()
 {
 for f; do
-if [ $f = $IMGFMT -o $f = generic ]; then
+

Re: [Qemu-devel] [PATCH v6 20/20] block: qemu-iotests for vhdx, add write test support

2013-09-27 Thread Jeff Cody
This patch should be replaced, because of the vhdx r/o test
patch posted upstream:
[PATCH v4] block: qemu-iotests for vhdx, read sample dynamic image

This patch should be:

---

This removes the IMGFMT_GENERIC blocker for read-only, so existing
iotests run read/write tests for vhdx images created by qemu-img (e.g.
tests 001, 002, 003).

In addition, this updates the sample image test for the Hyper-V
created image, to verify we can write it as well.

Signed-off-by: Jeff Cody jc...@redhat.com
---
 tests/qemu-iotests/064 | 11 +++
 tests/qemu-iotests/064.out | 14 ++
 tests/qemu-iotests/common  |  1 -
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
index 6789aa6..1c74c31 100755
--- a/tests/qemu-iotests/064
+++ b/tests/qemu-iotests/064
@@ -56,6 +56,17 @@ echo
 echo === Verify pattern 0x00, 66M - 1024M ===
 $QEMU_IO -r -c read -pP 0x00 66M 958M $TEST_IMG | _filter_qemu_io
 
+echo
+echo === Verify pattern write, 0xc3 99M-157M ===
+$QEMU_IO -c write -pP 0xc3 99M 58M $TEST_IMG | _filter_qemu_io
+# first verify we didn't write where we should not have
+$QEMU_IO -c read -pP 0xa5 0 33M $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c read -pP 0x96 33M 33M $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c read -pP 0x00 66M 33M $TEST_IMG | _filter_qemu_io
+$QEMU_IO -c read -pP 0x00 157MM 867MM $TEST_IMG | _filter_qemu_io
+# now verify what we should have actually written
+$QEMU_IO -c read -pP 0xc3 99M 58M $TEST_IMG | _filter_qemu_io
+
 # success, all done
 echo *** done
 rm -f $seq.full
diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
index b9e8e4a..5346a4e 100644
--- a/tests/qemu-iotests/064.out
+++ b/tests/qemu-iotests/064.out
@@ -11,4 +11,18 @@ read 34603008/34603008 bytes at offset 34603008
 === Verify pattern 0x00, 66M - 1024M ===
 read 1004535808/1004535808 bytes at offset 69206016
 958 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify pattern write, 0xc3 99M-157M ===
+wrote 60817408/60817408 bytes at offset 103809024
+58 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 34603008/34603008 bytes at offset 0
+33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 34603008/34603008 bytes at offset 34603008
+33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 34603008/34603008 bytes at offset 69206016
+33 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 909115392/909115392 bytes at offset 164626432
+867 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 60817408/60817408 bytes at offset 103809024
+58 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 *** done
diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common
index 2932e14..8cde7f1 100644
--- a/tests/qemu-iotests/common
+++ b/tests/qemu-iotests/common
@@ -200,7 +200,6 @@ testlist options
 -vhdx)
 IMGFMT=vhdx
 xpand=false
-IMGFMT_GENERIC=false
 ;;
 
 -rbd)
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v6 18/20] block: qemu-iotests for vhdx, read sample dynamic image

2013-09-27 Thread Jeff Cody
On Wed, Sep 25, 2013 at 05:03:03PM -0400, Jeff Cody wrote:
 This adds the VHDX format to the qemu-iotests format, and adds
 a read test.  The test reads from an existing sample image, that
 was created with Hyper-V under Windwos Server 2012.
 
 The image file is a 1GB dynamic image, with 32MB blocks.
 
 The pattern 0xa5 exists from 0MB-33MB (past a block size boundary)
 
 The pattern 0x96 exists from 33MB-66MB (past another block boundary,
 and leaving a partial blank block)
 
 From 66MB-1024MB, all reads should return 0.
 
 Although 1GB dynamic image with 66MB of data, the bzip2'ed image
 file size is only 874 bytes.
 
 Signed-off-by: Jeff Cody jc...@redhat.com

This has been superseded by this stand-alone patch:

[PATCH v4] block: qemu-iotests for vhdx, read sample dynamic image



Re: [Qemu-devel] Qxl problem with xen domU, is xen spice and/or qemu bugs?

2013-09-27 Thread Fabio Fantoni

Il 27/09/2013 10:51, Gerd Hoffmann ha scritto:

   Hi,


#2 When using f19 try without X11 first.  You should have a working
 framebuffer console on qxldrmfb before trying to get X11 going.

I tried on Fedora19 minimal installation and with qxl the text console
is working and lsmod show also qxl.

Good, so the kernel driver is running fine.


Is this your intended?

Yes.


#3 qxl has a bunch of tracepoints.  Enable them, then compare xen
 results with kvm/tcg results to see where things start going wrong.

I enabled qxl debug with these qemu paramters:
-global qxl-vga.debug=1 -global qxl-vga.guestdebug=20

debug=1 doesn't do much, most is in tracepoints these days.  I'm using
the stderr tracer most of the time (enable it using configure).  Then
you can turn on qxl_* either in monitor (trace-events command) or via
-trace events=file-with-event-names.


Thanks for reply, I used trace of qxl_* instead of -global debug options 
(is it right or must I maintain also global qxl debug option?).

On attachment the new qemu log of windows 7 test with qxl vga.
The test was made as for below:
I tried also W7 domU on xen with spice-guest-tools-0.65.exe and qxl: 
domU starts, loads correctly the DE, vdagent and mouse are both 
working, but screen refreshing is very lagging (also only open of 
start menu). 


Can you check the log to see if there are strange things to fix also on 
spice and/or qemu?

Thanks for any reply.


I tried to test Fedora19 on debian sid kvm host same qemu version
(1.6) on both sides but with qxl fails to start the DE, also in
fallback mode. Probably there are also regression on qemu and/or spice
about qxl.

I'm not aware of any regressions.
I'd suggest to try latest spice-server release.


I double checked and is already to latest version:
http://packages.debian.org/sid/libspice-server1



HTH,
   Gerd







qemu-dm-W7.7z
Description: Binary data


Re: [Qemu-devel] [PATCH] qcow2: Remove useless count_contiguous_clusters() parameter

2013-09-27 Thread Jeff Cody
On Fri, Sep 27, 2013 at 01:51:10PM +0200, Kevin Wolf wrote:
 All callers pass start = 0, and it's doubtful if any other value would
 actually do what you expect. Remove the parameter.
 
 Signed-off-by: Kevin Wolf kw...@redhat.com

Reviewed-by: Jeff Cody jc...@redhat.com

 ---
  block/qcow2-cluster.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)
 
 diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
 index 029c805..72cb573 100644
 --- a/block/qcow2-cluster.c
 +++ b/block/qcow2-cluster.c
 @@ -285,7 +285,7 @@ fail:
   * cluster which may require a different handling)
   */
  static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
 -uint64_t *l2_table, uint64_t start, uint64_t stop_flags)
 +uint64_t *l2_table, uint64_t stop_flags)
  {
  int i;
  uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED;
 @@ -297,14 +297,14 @@ static int count_contiguous_clusters(uint64_t 
 nb_clusters, int cluster_size,
  
  assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED);
  
 -for (i = start; i  start + nb_clusters; i++) {
 +for (i = 0; i  nb_clusters; i++) {
  uint64_t l2_entry = be64_to_cpu(l2_table[i])  mask;
  if (offset + (uint64_t) i * cluster_size != l2_entry) {
  break;
  }
  }
  
 - return (i - start);
 + return i;
  }
  
  static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t 
 *l2_table)
 @@ -497,7 +497,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, 
 uint64_t offset,
  return -EIO;
  }
  c = count_contiguous_clusters(nb_clusters, s-cluster_size,
 -l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
 +l2_table[l2_index], QCOW_OFLAG_ZERO);
  *cluster_offset = 0;
  break;
  case QCOW2_CLUSTER_UNALLOCATED:
 @@ -508,7 +508,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, 
 uint64_t offset,
  case QCOW2_CLUSTER_NORMAL:
  /* how many allocated clusters ? */
  c = count_contiguous_clusters(nb_clusters, s-cluster_size,
 -l2_table[l2_index], 0, QCOW_OFLAG_ZERO);
 +l2_table[l2_index], QCOW_OFLAG_ZERO);
  *cluster_offset = L2E_OFFSET_MASK;
  break;
  default:
 @@ -938,7 +938,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
 guest_offset,
  /* We keep all QCOW_OFLAG_COPIED clusters */
  keep_clusters =
  count_contiguous_clusters(nb_clusters, s-cluster_size,
 -  l2_table[l2_index], 0,
 +  l2_table[l2_index],
QCOW_OFLAG_COPIED | QCOW_OFLAG_ZERO);
  assert(keep_clusters = nb_clusters);
  
 -- 
 1.8.1.4
 
 



Re: [Qemu-devel] [PATCH 03/60] arm: Split VFP cmp from FPSCR setting

2013-09-27 Thread Richard Henderson
On 09/26/2013 05:47 PM, Alexander Graf wrote:
 -DEF_HELPER_3(vfp_cmps, void, f32, f32, env)
 -DEF_HELPER_3(vfp_cmpd, void, f64, f64, env)
 -DEF_HELPER_3(vfp_cmpes, void, f32, f32, env)
 -DEF_HELPER_3(vfp_cmped, void, f64, f64, env)
 +DEF_HELPER_3(vfp_fpscr_cmps, void, f32, f32, env)
 +DEF_HELPER_3(vfp_fpscr_cmpd, void, f64, f64, env)
 +DEF_HELPER_3(vfp_fpscr_cmpes, void, f32, f32, env)
 +DEF_HELPER_3(vfp_fpscr_cmped, void, f64, f64, env)
 +DEF_HELPER_3(vfp_cmps, i32, f32, f32, env)
 +DEF_HELPER_3(vfp_cmpd, i32, f64, f64, env)
 +DEF_HELPER_3(vfp_cmpes, i32, f32, f32, env)
 +DEF_HELPER_3(vfp_cmped, i32, f64, f64, env)

While you're changing these, please change them to use DEF_HELPER_FLAGS_*.
For the fpscr helpers, TCG_CALL_NO_RWG (since they have the side effect of
setting the fpscr); for the new helpers, TCG_CALL_NO_RWG_SE since there are
no side effects at all.


r~



Re: [Qemu-devel] [PATCH 04/60] arm: Add AArch64 disassembler stub

2013-09-27 Thread Richard Henderson
On 09/26/2013 05:47 PM, Alexander Graf wrote:
 While we don't have a working disassembler for AArch64 yet, we still
 don't want AArch64 code be disassembled through the old AArch32
 disassembler.
 
 So add a small disassembler stub that declares every instruction as
 unsupported. This should be a good enough base to plug in a real one
 later.
 
 Signed-off-by: Alexander Graf ag...@suse.de

Relic from before print_insn_objdump?


r~



Re: [Qemu-devel] [PATCH 1/6] kvm: Add KVM_GET_EMULATED_CPUID

2013-09-27 Thread Eduardo Habkost
On Thu, Sep 26, 2013 at 10:32:06PM +0200, Borislav Petkov wrote:
 On Thu, Sep 26, 2013 at 04:20:59PM -0300, Eduardo Habkost wrote:
  Please point me to the code that does this, because I don't see it on
  patch 6/6.
 
 @@ -1850,7 +1850,14 @@ static void filter_features_for_kvm(X86CPU *cpu)
   wi-cpuid_ecx,
   wi-cpuid_reg);
  uint32_t requested_features = env-features[w];
 +
 +uint32_t emul_features = kvm_arch_get_emulated_cpuid(s, 
 wi-cpuid_eax,
 +
 wi-cpuid_ecx,
 +
 wi-cpuid_reg);
 +
  env-features[w] = host_feat;
 +env-features[w] |= (requested_features  emul_features);
 
 Basically we give the requested_features a second chance here.
 
 If we don't request an emulated feature, it won't get enabled.

The problem here is that requested_features doesn't include just the
explicit +flag flags, but any flag included in the CPU model
definition. See the -cpu n270 example below.

 
   If you start with -cpu Haswell, MOVBE
   will be already set in the host CPUID.
   
   Or am I missing something?
  
  In the Haswell example, it is unlikely but possible in theory: you would
  need a CPU that supported all features from Haswell except movbe. But
  what will happen if you are using -cpu n270,enforce on a SandyBridge
  host?
 
 That's an interesting question: AFAICT, it will fail because MOVBE is
 not available on the host, right?

It should, but your patch will make it stop failing because of MOVBE, as
now it can be emulated[1].

 
 And if so, then this is correct behavior IMHO, or how exactly is the
 enforce thing supposed to work? Enforce host CPUID?

enforce makes sure all features are really being enabled. It makes
QEMU abort if there's any feature that can't be enabled on that host.


[1] Maybe one source of confusion is that the existing code have two
feature-filtering functions doing basically the same thing:
filter_features_for_kvm() and kvm_check_features_against_host().  That's
something we must clean up, and they should be unified. enforce should
become synonymous to make sure filtered_features is all zeroes.  This
way, libvirt can emulate what 'enforce does while being able to collect
detailed error information (which is not easy to do if QEMU simply
aborts).


 
  Also, we don't know anything about future CPUs or future features
  that will end up on EMULATED_CPUID. The current code doesn't have
  anything to differentiate features that were already included in the
  CPU definition and ones explicitly enabled in the command-line (and I
  would like to keep it that way).
 
 Ok.
 
  And just because a feature was explicitly enabled in the command-line,
  that doesn't mean the user believe it is acceptable to get it running
  in emulated mode. That's why I propose a new emulate flag, to allow
  features to be enabled in emulated mode.
 
 And I think, saying -cpu ...,+movbe is an explicit statement enough to
 say that yes, I am starting this guest and I want MOVBE emulation.

Not necessarily. libvirt has some code that will translate its own CPU
model definition to a -cpu Model,+flag,+flag,+flag,-flag command-line
when necessary. It is by design that there is no difference between
explicit +flag options and existing flags from the CPU model
definition. 

 
  Well, x2apic is emulated by KVM, and it is on SUPPORTED_CPUID. Ditto
  for tsc-deadline. Or are you talking specifically about instruction
  emulation?
 
 Basically, I'm viewing this from a very practical standpoint - if I
 build a kernel which requires MOVBE support but I cannot boot it in kvm
 because it doesn't emulate MOVBE (TCG does now but it didn't before)
 I'd like to be able to address that shortcoming by emulating that
 instruction, if possible.
 
 And the whole discussion grew out from the standpoint of being able to
 emulate stuff so that you can do quick and dirty booting of kernels but
 not show that emulation capability to the wide audience since it is slow
 and it shouldn't be used and then migration has issues, etc, etc.
 
 But hey, I don't really care all that much if I have to also say
 -emulate in order to get my functionality.

OK, I undestand your use case, now. Thanks for your explanation.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 09/60] AArch64: Add b and bl handling

2013-09-27 Thread Claudio Fontana
Hi Alex,

On 09/27/13 02:48, Alexander Graf wrote:
 This adds handling for the b and bl instructions.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  target-arm/translate-a64.c | 61 
 ++
  1 file changed, 61 insertions(+)
 
 diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
 index 73ccade..267fd4d 100644
 --- a/target-arm/translate-a64.c
 +++ b/target-arm/translate-a64.c
 @@ -133,6 +133,58 @@ static void real_unallocated_encoding(DisasContext *s)
  real_unallocated_encoding(s); \
  } while (0)
  
 +static int get_bits(uint32_t inst, int start, int len)
 +{
 +return (inst  start)  ((1  len) - 1);
 +}
 +

do you think it makes sense to reuse extract32 from bitops here?

 +static int get_sbits(uint32_t inst, int start, int len)
 +{
 +int r = get_bits(inst, start, len);
 +if (r  (1  (len - 1))) {
 +/* Extend the MSB 1 to the higher bits */
 +r |= -1  ~((1ULL  len) - 1);
 +}
 +return r;
 +}
 +

sextract32?

 +static TCGv_i64 cpu_reg(int reg)
 +{
 +if (reg == 31) {
 +/* XXX leaks temps */
 +return tcg_const_i64(0);

...

 +} else {
 +return cpu_X[reg];
 +}
 +}
 +
 +static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
 +{
 +TranslationBlock *tb;
 +
 +tb = s-tb;
 +if ((tb-pc  TARGET_PAGE_MASK) == (dest  TARGET_PAGE_MASK)) {
 +tcg_gen_goto_tb(n);
 +gen_a64_set_pc_im(dest);
 +tcg_gen_exit_tb((tcg_target_long)tb + n);
 +} else {
 +gen_a64_set_pc_im(dest);
 +tcg_gen_exit_tb(0);
 +}
 +}
 +
 +static void handle_b(DisasContext *s, uint32_t insn)
 +{
 +uint64_t addr = s-pc - 4 + (get_sbits(insn, 0, 26)  2);
 +
 +if (get_bits(insn, 31, 1)) {
 +/* BL */
 +tcg_gen_movi_i64(cpu_reg(30), s-pc);
 +}
 +gen_goto_tb(s, 0, addr);
 +s-is_jmp = DISAS_TB_JUMP;
 +}
 +
  void disas_a64_insn(CPUARMState *env, DisasContext *s)
  {
  uint32_t insn;
 @@ -141,12 +193,21 @@ void disas_a64_insn(CPUARMState *env, DisasContext *s)
  s-insn = insn;
  s-pc += 4;
  
 +/* One-off branch instruction layout */
 +switch (insn  26) {
 +case 0x25:
 +case 0x5:
 +handle_b(s, insn);
 +goto insn_done;
 +}
 +
  switch ((insn  24)  0x1f) {
  default:
  unallocated_encoding(s);
  break;
  }
  
 +insn_done:
  if (unlikely(s-singlestep_enabled)  (s-is_jmp == DISAS_TB_JUMP)) {
  /* go through the main loop for single step */
  s-is_jmp = DISAS_JUMP;
 

Ciao,

Claudio




Re: [Qemu-devel] [PATCH 09/60] AArch64: Add b and bl handling

2013-09-27 Thread Richard Henderson
On 09/26/2013 05:48 PM, Alexander Graf wrote:
 +static int get_bits(uint32_t inst, int start, int len)
 +{
 +return (inst  start)  ((1  len) - 1);
 +}
 +
 +static int get_sbits(uint32_t inst, int start, int len)
 +{
 +int r = get_bits(inst, start, len);
 +if (r  (1  (len - 1))) {
 +/* Extend the MSB 1 to the higher bits */
 +r |= -1  ~((1ULL  len) - 1);
 +}
 +return r;
 +}

extract32 and sextract32 please.

 +static TCGv_i64 cpu_reg(int reg)
 +{
 +if (reg == 31) {
 +/* XXX leaks temps */
 +return tcg_const_i64(0);
 +} else {
 +return cpu_X[reg];
 +}
 +}

See how we treat temporaries in the sparc translator.
We record them in the DisasContext to be freed at the
end of the insn.

 +tb = s-tb;
 +if ((tb-pc  TARGET_PAGE_MASK) == (dest  TARGET_PAGE_MASK)) {

Not the only conditions you need to check.  In
particular, no single-stepping or tb-flags  CF_LAST_IO.
C.f. target-alpha's use_goto_tb function.


r~



Re: [Qemu-devel] [PATCH 10/60] AArch64: Add handling for br instructions

2013-09-27 Thread Richard Henderson
On 09/26/2013 05:48 PM, Alexander Graf wrote:
 +static void handle_br(DisasContext *s, uint32_t insn)
 +{
 +int branch_type = get_bits(insn, 21, 2);
 +int source = get_bits(insn, 5, 5);
 +
 +switch (branch_type) {
 +case 0: /* JMP */
 +break;
 +case 1: /* CALL */
 +tcg_gen_movi_i64(cpu_reg(30), s-pc);
 +break;
 +case 2: /* RET */
 +source = 30;
 +break;

This is incorrect.  One can RET from any register; the only difference between
JMP and RET is a branch prediction hint irrelevant to QEMU.


r~



Re: [Qemu-devel] [PATCH 2/3] qcow2: Free allocated L2 cluster on error

2013-09-27 Thread Kevin Wolf
Am 25.09.2013 um 16:37 hat Max Reitz geschrieben:
 If an error occurs in l2_allocate, the allocated (but unused) L2 cluster
 should be freed.
 
 Signed-off-by: Max Reitz mre...@redhat.com
 ---
  block/qcow2-cluster.c | 4 
  1 file changed, 4 insertions(+)

This needs an update of the reference output for test case 026 (both for
-nocache and writethrough).

Most of the changes look expected and good, like cluster leaks
disappearing. With -nocache, however, there are a few cases that failed
previously and result in successful writes now. It would be interesting
to see the explanation for these before we merge the patch.

Kevin



Re: [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates

2013-09-27 Thread Edgar E. Iglesias
On Fri, Sep 27, 2013 at 03:09:55PM +0300, riku.voi...@linaro.org wrote:
 From: Riku Voipio riku.voi...@linaro.org
 
 The following changes since commit f828a4c8faa118e0ebab3e353ac6840f3b2a0318:
 
   Merge remote-tracking branch 'stefanha/tracing' into staging (2013-09-23 
 11:53:22 -0500)
 
 are available in the git repository at:
 
   git://git.linaro.org/people/rikuvoipio/qemu.git linux-user-for-upstream
 
 for you to fetch changes up to 53d09b761f032f50c4424e8649396a9041070bae:
 
   linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host (2013-09-24 
 10:47:07 +0300)


Pulled, thanks Riku.

Cheers,
Edgar


 
 
 
 Edgar E. Iglesias (1):
   linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host
 
 Kwok Cheung Yeung (1):
   linux-user: Check type of microMIPS break instruction
 
 Laurent Vivier (5):
   linux-user: convert /proc/net/route when endianess differs
   linux-user: Add setsockopt(SO_ATTACH_FILTER)
   linux-user: allow use of TIOCGSID
   linux-user: add some IPV6 commands in setsockop()
   linux-user: add support of binfmt_misc 'O' flag
 
 Petar Jovanovic (1):
   linux-user: correct how SOL_SOCKET is converted from target to host
 and back
 
 Richard Henderson (2):
   alpha-linux-user: Fix umount syscall numbers
   mips-linux-user: Adjust names in mips_syscall_args
 
 Riku Voipio (1):
   [v2] linux-user: implement m68k atomic syscalls
 
  linux-user/alpha/syscall_nr.h |   4 +-
  linux-user/ioctls.h   |   1 +
  linux-user/linuxload.c|   8 +-
  linux-user/main.c |  92 +-
  linux-user/qemu.h |   2 +-
  linux-user/strace.list|   9 +-
  linux-user/syscall.c  | 210 
 +++---
  linux-user/syscall_defs.h |  12 +++
  8 files changed, 288 insertions(+), 50 deletions(-)
 
 -- 
 1.8.1.2
 
 



[Qemu-devel] [PATCH v2] qemu/xen: make use of xenstore relative paths

2013-09-27 Thread Roger Pau Monne
Qemu has several hardcoded xenstore paths that are only valid on Dom0.
Attempts to launch a Qemu instance (to act as a userspace backend for
PV disks) will fail because Qemu is not able to access those paths
when running on a domain different than Dom0.

Instead make the xenstore paths relative to the domain where Qemu is
actually running.

Signed-off-by: Roger Pau Monné roger@citrix.com
Reviewed-by: Anthony PERARD anthony.per...@citrix.com
Cc: xen-de...@lists.xenproject.org
Cc: Anthony PERARD anthony.per...@citrix.com
Cc: Stefano Stabellini stefano.stabell...@eu.citrix.com
---
Changes since v1:
 * Update paths to match upstream Qemu.
---
 hw/xen/xen_backend.c |   19 ++-
 xen-all.c|2 +-
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index d82ce5d..197795f 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -205,7 +205,6 @@ static struct XenDevice *xen_be_get_xendev(const char 
*type, int dom, int dev,
struct XenDevOps *ops)
 {
 struct XenDevice *xendev;
-char *dom0;
 
 xendev = xen_be_find_xendev(type, dom, dev);
 if (xendev) {
@@ -219,12 +218,10 @@ static struct XenDevice *xen_be_get_xendev(const char 
*type, int dom, int dev,
 xendev-dev   = dev;
 xendev-ops   = ops;
 
-dom0 = xs_get_domain_path(xenstore, 0);
-snprintf(xendev-be, sizeof(xendev-be), %s/backend/%s/%d/%d,
- dom0, xendev-type, xendev-dom, xendev-dev);
+snprintf(xendev-be, sizeof(xendev-be), backend/%s/%d/%d,
+ xendev-type, xendev-dom, xendev-dev);
 snprintf(xendev-name, sizeof(xendev-name), %s-%d,
  xendev-type, xendev-dev);
-free(dom0);
 
 xendev-debug  = debug;
 xendev-local_port = -1;
@@ -570,14 +567,12 @@ static int xenstore_scan(const char *type, int dom, 
struct XenDevOps *ops)
 {
 struct XenDevice *xendev;
 char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
-char **dev = NULL, *dom0;
+char **dev = NULL;
 unsigned int cdev, j;
 
 /* setup watch */
-dom0 = xs_get_domain_path(xenstore, 0);
 snprintf(token, sizeof(token), be:%p:%d:%p, type, dom, ops);
-snprintf(path, sizeof(path), %s/backend/%s/%d, dom0, type, dom);
-free(dom0);
+snprintf(path, sizeof(path), backend/%s/%d, type, dom);
 if (!xs_watch(xenstore, path, token)) {
 xen_be_printf(NULL, 0, xen be: watching backend path (%s) failed\n, 
path);
 return -1;
@@ -603,12 +598,10 @@ static void xenstore_update_be(char *watch, char *type, 
int dom,
struct XenDevOps *ops)
 {
 struct XenDevice *xendev;
-char path[XEN_BUFSIZE], *dom0, *bepath;
+char path[XEN_BUFSIZE], *bepath;
 unsigned int len, dev;
 
-dom0 = xs_get_domain_path(xenstore, 0);
-len = snprintf(path, sizeof(path), %s/backend/%s/%d, dom0, type, dom);
-free(dom0);
+len = snprintf(path, sizeof(path), backend/%s/%d, type, dom);
 if (strncmp(path, watch, len) != 0) {
 return;
 }
diff --git a/xen-all.c b/xen-all.c
index 839f14f..0504c45 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -948,7 +948,7 @@ static void xenstore_record_dm_state(struct xs_handle *xs, 
const char *state)
 exit(1);
 }
 
-snprintf(path, sizeof (path), /local/domain/0/device-model/%u/state, 
xen_domid);
+snprintf(path, sizeof (path), device-model/%u/state, xen_domid);
 if (!xs_write(xs, XBT_NULL, path, state, strlen(state))) {
 fprintf(stderr, error recording dm state\n);
 exit(1);
-- 
1.7.7.5 (Apple Git-26)




[Qemu-devel] [PULL 00/30] Block patches

2013-09-27 Thread Kevin Wolf
The following changes since commit f828a4c8faa118e0ebab3e353ac6840f3b2a0318:

  Merge remote-tracking branch 'stefanha/tracing' into staging (2013-09-23 
11:53:22 -0500)

are available in the git repository at:


  git://repo.or.cz/qemu/kevin.git for-anthony

for you to fetch changes up to 61653008adad45026464f962759112995802fe01:

  qcow2: Remove useless count_contiguous_clusters() parameter (2013-09-27 
17:22:43 +0200)


Benoît Canet (2):
  block: introduce BlockDriver.bdrv_needs_filename to enable some drivers.
  qdict: Extract qdict_extract_subqdict

Fam Zheng (7):
  block: fix backing file overriding
  qemu-iotests: add test for backing file overriding
  vmdk: fix cluster size check for flat extents
  qemu-iotests: fix test case 059
  qemu-iotests: add monolithicFlat creation test to 059
  block: use DIV_ROUND_UP in bdrv_co_do_readv
  qemu-iotests: fix qmp.py search path

Jeff Cody (6):
  block: vdi - use QEMU_PACKED for on-disk structures
  block: vpc - use QEMU_PACKED for on-disk structures
  block: qcow2 - used QEMU_PACKED for on-disk structures
  block: qed - use QEMU_PACKED for on-disk structures
  qemu-iotests: Add basic ability to use binary sample images
  qemu-iotests: Quote $TEST_IMG* and $TEST_DIR usage

Kevin Wolf (1):
  qcow2: Remove useless count_contiguous_clusters() parameter

Max Reitz (10):
  qemu-iotests: Do not execute 052 with -nocache
  qcow2: Don't shadow return value
  qcow2: Assert against currently impossible overflow
  qcow2: Correct bitmap size in zero expansion
  qemu-iotests: Preallocated zero clusters in 061
  qcow2: Don't put invalid L2 table into cache
  qcow2: Always use error path in l2_allocate
  qcow2: Free only newly allocated clusters on error
  qcow2: count_contiguous_clusters and compression
  qcow2: COMPRESSED on count_contiguous_clusters

Peter Lieven (2):
  block/get_block_status: set *pnum = 0 on error
  block/get_block_status: avoid segfault if there is no backing_hd

Stefan Hajnoczi (1):
  rbd: avoid qemu_rbd_snap_list() memory leaks

Stefan Weil (1):
  block: Fix compiler warning (-Werror=uninitialized)

 block.c | 39 +--
 block/gluster.c |  4 ++
 block/iscsi.c   |  1 +
 block/qcow2-cluster.c   | 87 +
 block/qcow2-refcount.c  |  1 -
 block/qcow2.c   |  2 +-
 block/qcow2.h   |  2 +-
 block/qed.h |  2 +-
 block/raw-posix.c   |  5 ++
 block/raw-win32.c   |  2 +
 block/rbd.c |  4 +-
 block/sheepdog.c|  3 ++
 block/stream.c  |  5 +-
 block/vdi.c |  2 +-
 block/vmdk.c|  6 +--
 block/vpc.c | 28 +--
 include/block/block_int.h   |  6 +++
 include/qapi/qmp/qdict.h|  2 +
 qobject/qdict.c | 21 
 tests/qemu-iotests/001  |  6 +--
 tests/qemu-iotests/002  | 36 +++---
 tests/qemu-iotests/003  | 10 ++--
 tests/qemu-iotests/004  | 24 -
 tests/qemu-iotests/005  |  4 +-
 tests/qemu-iotests/007  |  2 +-
 tests/qemu-iotests/008  |  6 +--
 tests/qemu-iotests/009  |  2 +-
 tests/qemu-iotests/010  |  2 +-
 tests/qemu-iotests/011  |  2 +-
 tests/qemu-iotests/012  |  4 +-
 tests/qemu-iotests/013  |  4 +-
 tests/qemu-iotests/014  |  2 +-
 tests/qemu-iotests/015  | 16 +++---
 tests/qemu-iotests/016  | 12 ++---
 tests/qemu-iotests/018  |  6 +--
 tests/qemu-iotests/019  | 12 ++---
 tests/qemu-iotests/020  | 12 ++---
 tests/qemu-iotests/021  |  2 +-
 tests/qemu-iotests/023  |  4 +-
 tests/qemu-iotests/024  | 12 ++---
 tests/qemu-iotests/025  |  4 +-
 tests/qemu-iotests/026  | 20 
 tests/qemu-iotests/027  | 10 ++--
 tests/qemu-iotests/028  |  6 +--
 tests/qemu-iotests/029  | 12 ++---
 tests/qemu-iotests/031  | 12 ++---
 tests/qemu-iotests/032  |  4 +-
 tests/qemu-iotests/033  | 18 +++
 tests/qemu-iotests/034  | 64 
 tests/qemu-iotests/035  |  2 +-
 tests/qemu-iotests/036  |  6 +--
 tests/qemu-iotests/037  | 62 +++
 

[Qemu-devel] [PULL 01/30] block: fix backing file overriding

2013-09-27 Thread Kevin Wolf
From: Fam Zheng f...@redhat.com

Providing backing.file.filename doesn't override backing file as expected:

$ x86_64-softmmu/qemu-system-x86_64 -drive \
file=/tmp/child.qcow2,backing.file.filename=/tmp/fake.qcow2

qemu-system-x86_64: -drive \
file=/tmp/child.qcow2,backing.file.filename=/tmp/fake.qcow2: could not
open disk image /tmp/child.qcow2: Can't specify 'file' and 'filename'
options at the same time

With

$ qemu-img info /tmp/child.qcow2
image: /tmp/child.qcow2
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 196K
cluster_size: 65536
backing file: /tmp/fake.qcow2

This fixes it by calling bdrv_get_full_backing_filename only if
backing.file.filename is not provided. Also save the backing file name
to bs-backing_file so the information is correct with HMP info block.

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index ea4956d..b383b72 100644
--- a/block.c
+++ b/block.c
@@ -978,11 +978,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 } else if (bs-backing_file[0] == '\0'  qdict_size(options) == 0) {
 QDECREF(options);
 return 0;
+} else {
+bdrv_get_full_backing_filename(bs, backing_filename,
+   sizeof(backing_filename));
 }
 
 bs-backing_hd = bdrv_new();
-bdrv_get_full_backing_filename(bs, backing_filename,
-   sizeof(backing_filename));
 
 if (bs-backing_format[0] != '\0') {
 back_drv = bdrv_find_format(bs-backing_format);
@@ -994,6 +995,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 ret = bdrv_open(bs-backing_hd,
 *backing_filename ? backing_filename : NULL, options,
 back_flags, back_drv, local_err);
+pstrcpy(bs-backing_file, sizeof(bs-backing_file),
+bs-backing_hd-file-filename);
 if (ret  0) {
 bdrv_unref(bs-backing_hd);
 bs-backing_hd = NULL;
-- 
1.8.1.4




[Qemu-devel] [PULL 05/30] block/get_block_status: set *pnum = 0 on error

2013-09-27 Thread Kevin Wolf
From: Peter Lieven p...@kamp.de

if the call is invoked through bdrv_is_allocated the caller might
expect *pnum = 0 on error. however, a new implementation of
bdrv_get_block_status might only return a negative exit value on
error while keeping *pnum untouched.

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Peter Lieven p...@kamp.de
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block.c b/block.c
index b383b72..9b444b3 100644
--- a/block.c
+++ b/block.c
@@ -3162,6 +3162,7 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 
 ret = bs-drv-bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
 if (ret  0) {
+*pnum = 0;
 return ret;
 }
 
-- 
1.8.1.4




[Qemu-devel] [PULL 03/30] qemu-iotests: Do not execute 052 with -nocache

2013-09-27 Thread Kevin Wolf
From: Max Reitz mre...@redhat.com

Test 052 uses qemu-io -s which will result in bdrv_open trying to create
a temporary snapshot file in /tmp. However, since O_DIRECT and tmpfs
do not work well together, disable this test for -nocache.

Signed-off-by: Max Reitz mre...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 tests/qemu-iotests/052 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052
index 14a5126..49810cb 100755
--- a/tests/qemu-iotests/052
+++ b/tests/qemu-iotests/052
@@ -41,6 +41,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 _supported_fmt generic
 _supported_proto generic
 _supported_os Linux
+_unsupported_qemu_io_options --nocache
 
 
 size=128M
-- 
1.8.1.4




[Qemu-devel] [PULL 12/30] qdict: Extract qdict_extract_subqdict

2013-09-27 Thread Kevin Wolf
From: Benoît Canet ben...@irqsave.net

Signed-off-by: Benoit Canet ben...@irqsave.net
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c  | 23 ++-
 include/qapi/qmp/qdict.h |  2 ++
 qobject/qdict.c  | 21 +
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/block.c b/block.c
index 4a98250..4833b37 100644
--- a/block.c
+++ b/block.c
@@ -1007,25 +1007,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 return 0;
 }
 
-static void extract_subqdict(QDict *src, QDict **dst, const char *start)
-{
-const QDictEntry *entry, *next;
-const char *p;
-
-*dst = qdict_new();
-entry = qdict_first(src);
-
-while (entry != NULL) {
-next = qdict_next(src, entry);
-if (strstart(entry-key, start, p)) {
-qobject_incref(entry-value);
-qdict_put_obj(*dst, p, entry-value);
-qdict_del(src, entry-key);
-}
-entry = next;
-}
-}
-
 /*
  * Opens a disk image (raw, qcow2, vmdk, ...)
  *
@@ -1131,7 +1112,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
QDict *options,
 flags |= BDRV_O_ALLOW_RDWR;
 }
 
-extract_subqdict(options, file_options, file.);
+qdict_extract_subqdict(options, file_options, file.);
 
 ret = bdrv_file_open(file, filename, file_options,
  bdrv_open_flags(bs, flags | BDRV_O_UNMAP), 
local_err);
@@ -1169,7 +1150,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
QDict *options,
 if ((flags  BDRV_O_NO_BACKING) == 0) {
 QDict *backing_options;
 
-extract_subqdict(options, backing_options, backing.);
+qdict_extract_subqdict(options, backing_options, backing.);
 ret = bdrv_open_backing_file(bs, backing_options, local_err);
 if (ret  0) {
 goto close_and_fail;
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index d6855d1..5cefd80 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -67,4 +67,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char 
*key);
 QDict *qdict_clone_shallow(const QDict *src);
 void qdict_flatten(QDict *qdict);
 
+void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start);
+
 #endif /* QDICT_H */
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 472f106..0f3e0a6 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -527,3 +527,24 @@ void qdict_flatten(QDict *qdict)
 {
 qdict_do_flatten(qdict, qdict, NULL);
 }
+
+/* extract all the src QDict entries starting by start into dst */
+void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start)
+
+{
+const QDictEntry *entry, *next;
+const char *p;
+
+*dst = qdict_new();
+entry = qdict_first(src);
+
+while (entry != NULL) {
+next = qdict_next(src, entry);
+if (strstart(entry-key, start, p)) {
+qobject_incref(entry-value);
+qdict_put_obj(*dst, p, entry-value);
+qdict_del(src, entry-key);
+}
+entry = next;
+}
+}
-- 
1.8.1.4




[Qemu-devel] [PULL 02/30] qemu-iotests: add test for backing file overriding

2013-09-27 Thread Kevin Wolf
From: Fam Zheng f...@redhat.com

Test that backing.file.filename option can be parsed and override the
backing file from image (backing file reflected with info block).

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 tests/qemu-iotests/051 | 17 -
 tests/qemu-iotests/051.out | 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
index 1f39c6a..78e1182 100755
--- a/tests/qemu-iotests/051
+++ b/tests/qemu-iotests/051
@@ -45,7 +45,14 @@ _supported_os Linux
 function do_run_qemu()
 {
 echo Testing: $@
-echo quit | $QEMU -nographic -monitor stdio -serial none $@
+(
+if ! test -t 0; then
+while read cmd; do
+echo $cmd
+done
+fi
+echo quit
+) | $QEMU -nographic -monitor stdio -serial none $@
 echo
 }
 
@@ -57,6 +64,9 @@ function run_qemu()
 size=128M
 
 _make_test_img $size
+cp $TEST_IMG $TEST_IMG.orig
+mv $TEST_IMG $TEST_IMG.base
+_make_test_img -b $TEST_IMG.base $size
 
 echo
 echo === Unknown option ===
@@ -67,6 +77,11 @@ run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=on
 run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=1234
 run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=foo
 
+echo
+echo === Overriding backing file ===
+echo
+
+echo info block | run_qemu -drive 
file=$TEST_IMG,driver=qcow2,backing.file.filename=$TEST_IMG.orig -nodefaults
 
 echo
 echo === Enable and disable lazy refcounting on the command line, plus some 
invalid values ===
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index 88e8fa7..04bb236 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -1,5 +1,6 @@
 QA output created by 051
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
backing_file='TEST_DIR/t.IMGFMT.base' 
 
 === Unknown option ===
 
@@ -16,6 +17,16 @@ Testing: -drive 
file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo: could 
not open disk image TEST_DIR/t.qcow2: Block format 'qcow2' used by device 
'ide0-hd0' doesn't support the option 'unknown_opt'
 
 
+=== Overriding backing file ===
+
+Testing: -drive 
file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DIR/t.qcow2.orig 
-nodefaults
+QEMU X.Y.Z monitor - type 'help' for more information
+(qemu) iininfinfoinfo 
info binfo 
blinfo bloinfo 
blocinfo block
+ide0-hd0: TEST_DIR/t.qcow2 (qcow2)
+Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1)
+ [not inserted](qemu) qququiquit
+
+
 === Enable and disable lazy refcounting on the command line, plus some invalid 
values ===
 
 Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,lazy-refcounts=on
-- 
1.8.1.4




[Qemu-devel] [PULL 10/30] block: introduce BlockDriver.bdrv_needs_filename to enable some drivers.

2013-09-27 Thread Kevin Wolf
From: Benoît Canet ben...@irqsave.net

Some drivers will have driver specifics options but no filename.
This new bool allow the block layer to treat them correctly.

The .bdrv_needs_filename is set in drivers not having .bdrv_parse_filename and
not having .bdrv_open.

The first exception to this rule will be the quorum driver.

Signed-off-by: Benoit Canet ben...@irqsave.net
Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c   | 4 ++--
 block/gluster.c   | 4 
 block/iscsi.c | 1 +
 block/raw-posix.c | 5 +
 block/raw-win32.c | 2 ++
 block/rbd.c   | 1 +
 block/sheepdog.c  | 3 +++
 include/block/block_int.h | 6 ++
 8 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 3366017..4a98250 100644
--- a/block.c
+++ b/block.c
@@ -792,7 +792,7 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockDriverState *file,
 /* Open the image, either directly or using a protocol */
 if (drv-bdrv_file_open) {
 assert(file == NULL);
-assert(drv-bdrv_parse_filename || filename != NULL);
+assert(!drv-bdrv_needs_filename || filename != NULL);
 ret = drv-bdrv_file_open(bs, options, open_flags, local_err);
 } else {
 if (file == NULL) {
@@ -911,7 +911,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char 
*filename,
 goto fail;
 }
 qdict_del(options, filename);
-} else if (!drv-bdrv_parse_filename  !filename) {
+} else if (drv-bdrv_needs_filename  !filename) {
 error_setg(errp, The '%s' block driver requires a file name,
drv-format_name);
 ret = -EINVAL;
diff --git a/block/gluster.c b/block/gluster.c
index 256de10..877686a 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -611,6 +611,7 @@ static BlockDriver bdrv_gluster = {
 .format_name  = gluster,
 .protocol_name= gluster,
 .instance_size= sizeof(BDRVGlusterState),
+.bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
 .bdrv_create  = qemu_gluster_create,
@@ -631,6 +632,7 @@ static BlockDriver bdrv_gluster_tcp = {
 .format_name  = gluster,
 .protocol_name= gluster+tcp,
 .instance_size= sizeof(BDRVGlusterState),
+.bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
 .bdrv_create  = qemu_gluster_create,
@@ -651,6 +653,7 @@ static BlockDriver bdrv_gluster_unix = {
 .format_name  = gluster,
 .protocol_name= gluster+unix,
 .instance_size= sizeof(BDRVGlusterState),
+.bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
 .bdrv_create  = qemu_gluster_create,
@@ -671,6 +674,7 @@ static BlockDriver bdrv_gluster_rdma = {
 .format_name  = gluster,
 .protocol_name= gluster+rdma,
 .instance_size= sizeof(BDRVGlusterState),
+.bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
 .bdrv_create  = qemu_gluster_create,
diff --git a/block/iscsi.c b/block/iscsi.c
index 4460382..6152ef1 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1520,6 +1520,7 @@ static BlockDriver bdrv_iscsi = {
 .protocol_name   = iscsi,
 
 .instance_size   = sizeof(IscsiLun),
+.bdrv_needs_filename = true,
 .bdrv_file_open  = iscsi_open,
 .bdrv_close  = iscsi_close,
 .bdrv_create = iscsi_create,
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 3ee5b62..f7f102d 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1200,6 +1200,7 @@ static BlockDriver bdrv_file = {
 .format_name = file,
 .protocol_name = file,
 .instance_size = sizeof(BDRVRawState),
+.bdrv_needs_filename = true,
 .bdrv_probe = NULL, /* no probe for protocols */
 .bdrv_file_open = raw_open,
 .bdrv_reopen_prepare = raw_reopen_prepare,
@@ -1542,6 +1543,7 @@ static BlockDriver bdrv_host_device = {
 .format_name= host_device,
 .protocol_name= host_device,
 .instance_size  = sizeof(BDRVRawState),
+.bdrv_needs_filename = true,
 .bdrv_probe_device  = hdev_probe_device,
 .bdrv_file_open = hdev_open,
 .bdrv_close = raw_close,
@@ -1667,6 +1669,7 @@ static BlockDriver bdrv_host_floppy = {
 .format_name= host_floppy,
 .protocol_name  = host_floppy,
 .instance_size  = sizeof(BDRVRawState),
+

[Qemu-devel] [PULL 06/30] block/get_block_status: avoid segfault if there is no backing_hd

2013-09-27 Thread Kevin Wolf
From: Peter Lieven p...@kamp.de

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Peter Lieven p...@kamp.de
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 9b444b3..3366017 100644
--- a/block.c
+++ b/block.c
@@ -3169,7 +3169,7 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 if (!(ret  BDRV_BLOCK_DATA)) {
 if (bdrv_has_zero_init(bs)) {
 ret |= BDRV_BLOCK_ZERO;
-} else {
+} else if (bs-backing_hd) {
 BlockDriverState *bs2 = bs-backing_hd;
 int64_t length2 = bdrv_getlength(bs2);
 if (length2 = 0  sector_num = (length2  BDRV_SECTOR_BITS)) {
-- 
1.8.1.4




  1   2   >