Re: [Qemu-devel] [PATCH 06/16] dimm: implement dimm device abstraction

2013-07-24 Thread Hu Tao
On Tue, Jul 23, 2013 at 06:23:02PM +0200, Igor Mammedov wrote:
> From: Vasilis Liaskovitis 

<...>

> +
> +/**
> + * DimmBus:

DimmDevice

> + * @start: starting physical address, where @DimmDevice is mapped.
> + * @size: amount of memory mapped at @start.
> + * @node: numa node to which @DimmDevice is attached.
> + * @slot: slot number into which @DimmDevice is plugged in.
> + */
> +typedef struct DimmDevice {
> +DeviceState qdev;
> +ram_addr_t start;
> +ram_addr_t size;
> +uint32_t node;
> +int32_t slot;
> +MemoryRegion mr;
> +} DimmDevice;
> +
> +typedef struct DimmDeviceClass {
> +DeviceClass parent_class;
> +} DimmDeviceClass;
> +
> +#define TYPE_DIMM_BUS "dimmbus"
> +#define DIMM_BUS(obj) OBJECT_CHECK(DimmBus, (obj), TYPE_DIMM_BUS)
> +#define DIMM_BUS_CLASS(klass) \
> +OBJECT_CLASS_CHECK(DimmBusClass, (klass), TYPE_DIMM_BUS)
> +#define DIMM_BUS_GET_CLASS(obj) \
> +OBJECT_GET_CLASS(DimmBusClass, (obj), TYPE_DIMM_BUS)
> +
> +/**
> + * DimmBus:
> + */
> +typedef struct DimmBus {
> +BusState qbus;
> +} DimmBus;
> +
> +#endif
> -- 
> 1.7.1



Re: [Qemu-devel] [PATCH 1/1] cpu: Correct cpu-hotplug failure

2013-07-24 Thread chenfan
On Thu, 2013-07-25 at 14:27 +0800, Chen Fan wrote:
> When useing x86_64-softmmu --enable-kvm boot qemu, cpu-add command fails to 
> add a vcpu,
> there show (KVM: setting VAPIC address failed).
> 
> The reason is that we use an uninitialized cpu->kvm-fd to ioctl.
> so we move realizing apic to the back of qemu_init_vcpu.
> 
> Signed-off-by: Chen Fan 

This is regression is caused by commit c643bed99.

> ---
>  include/qom/cpu.h |  2 ++
>  qom/cpu.c | 13 +
>  target-i386/cpu.c | 10 --
>  3 files changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index daf1835..487a808 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -80,6 +80,7 @@ struct TranslationBlock;
>   * @synchronize_from_tb: Callback for synchronizing state from a TCG
>   * #TranslationBlock.
>   * @get_phys_page_debug: Callback for obtaining a physical address.
> + * @apic_realize: Callback for realizing apic.
>   * @vmsd: State description for migration.
>   *
>   * Represents a CPU family or model.
> @@ -108,6 +109,7 @@ typedef struct CPUClass {
>  void (*set_pc)(CPUState *cpu, vaddr value);
>  void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
>  hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
> +void (*apic_realize)(CPUState *cpu, Error **errp);
>  
>  const struct VMStateDescription *vmsd;
>  int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 5c45ab5..88c6028 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -213,12 +213,25 @@ static ObjectClass *cpu_common_class_by_name(const char 
> *cpu_model)
>  return NULL;
>  }
>  
> +static void cpu_apic_realize(CPUState *cpu, Error **errp)
> +{
> +CPUClass *cc = CPU_GET_CLASS(cpu);
> +if (cc->apic_realize != NULL) {
> +(*cc->apic_realize)(cpu, errp);
> +}
> +}
> +
>  static void cpu_common_realizefn(DeviceState *dev, Error **errp)
>  {
>  CPUState *cpu = CPU(dev);
>  
>  qemu_init_vcpu(cpu);
>  
> +cpu_apic_realize(cpu, errp);
> +if (error_is_set(errp)) {
> +return;
> +}
> +
>  if (dev->hotplugged) {
>  cpu_synchronize_post_init(cpu);
>  notifier_list_notify(&cpu_added_notifiers, dev);
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index cd350cb..916d69e 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2311,8 +2311,9 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error 
> **errp)
>  apic->cpu = cpu;
>  }
>  
> -static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
> +static void x86_cpu_apic_realize(CPUState *s, Error **errp)
>  {
> +X86CPU *cpu = X86_CPU(s);
>  CPUX86State *env = &cpu->env;
>  
>  if (env->apic_state == NULL) {
> @@ -2326,7 +2327,7 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error 
> **errp)
>  }
>  }
>  #else
> -static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
> +static void x86_cpu_apic_realize(CPUState *s, Error **errp)
>  {
>  }
>  #endif
> @@ -2388,10 +2389,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
> **errp)
>  
>  mce_init(cpu);
>  
> -x86_cpu_apic_realize(cpu, &local_err);
> -if (local_err != NULL) {
> -goto out;
> -}
>  cpu_reset(CPU(cpu));
>  
>  xcc->parent_realize(dev, &local_err);
> @@ -2540,6 +2537,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
> void *data)
>  cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
>  cc->get_arch_id = x86_cpu_get_arch_id;
>  cc->get_paging_enabled = x86_cpu_get_paging_enabled;
> +cc->apic_realize = x86_cpu_apic_realize;
>  #ifndef CONFIG_USER_ONLY
>  cc->get_memory_mapping = x86_cpu_get_memory_mapping;
>  cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;





Re: [Qemu-devel] [PATCH 04/16] qapi: make visit_type_size fallback to type_int

2013-07-24 Thread Hu Tao
On Tue, Jul 23, 2013 at 06:23:00PM +0200, Igor Mammedov wrote:
> From: Vasilis Liaskovitis 
> 
> Currently visit_type_size checks if the visitor's type_size function pointer 
> is
> NULL. If not, it calls it, otherwise it calls v->type_uint64(). But neither of
> these pointers are ever set. Fallback to calling v->type_int() in this third
> (default) case.
> 
> Signed-off-by: Vasilis Liaskovitis 
> Signed-off-by: Hu Tao 
> Signed-off-by: Igor Mammedov 
> ---
>  qapi/qapi-visit-core.c |   11 ++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index 401ee6e..fcacaff 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c
> @@ -238,8 +238,17 @@ void visit_type_int64(Visitor *v, int64_t *obj, const 
> char *name, Error **errp)
>  
>  void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error 
> **errp)
>  {
> +int64_t value;
>  if (!error_is_set(errp)) {
> -(v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
> +if (v->type_size) {
> +v->type_size(v, obj, name, errp);
> +} else if (v->type_uint64) {
> +v->type_uint64(v, obj, name, errp);
> +} else {
> +value = *obj;
> +v->type_int(v, &value, name, errp);
> +*obj = value;
> +}
>  }
>  }

This doesn't address comment from Michael Roth, quoted below:

---
I'd recommend just doing:

  if (v->type_size) {
  v->type_size(v, obj, name, errp);
  } else {
  visit_type_uint64(v, obj, name, errp);
  }

visit_type_uint64() already handles the fallback to visit_type_int() so no
need to duplicate.
---




[Qemu-devel] [PATCH 1/1] cpu: Correct cpu-hotplug failure

2013-07-24 Thread Chen Fan
When useing x86_64-softmmu --enable-kvm boot qemu, cpu-add command fails to add 
a vcpu,
there show (KVM: setting VAPIC address failed).

The reason is that we use an uninitialized cpu->kvm-fd to ioctl.
so we move realizing apic to the back of qemu_init_vcpu.

Signed-off-by: Chen Fan 
---
 include/qom/cpu.h |  2 ++
 qom/cpu.c | 13 +
 target-i386/cpu.c | 10 --
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index daf1835..487a808 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -80,6 +80,7 @@ struct TranslationBlock;
  * @synchronize_from_tb: Callback for synchronizing state from a TCG
  * #TranslationBlock.
  * @get_phys_page_debug: Callback for obtaining a physical address.
+ * @apic_realize: Callback for realizing apic.
  * @vmsd: State description for migration.
  *
  * Represents a CPU family or model.
@@ -108,6 +109,7 @@ typedef struct CPUClass {
 void (*set_pc)(CPUState *cpu, vaddr value);
 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
+void (*apic_realize)(CPUState *cpu, Error **errp);
 
 const struct VMStateDescription *vmsd;
 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
diff --git a/qom/cpu.c b/qom/cpu.c
index 5c45ab5..88c6028 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -213,12 +213,25 @@ static ObjectClass *cpu_common_class_by_name(const char 
*cpu_model)
 return NULL;
 }
 
+static void cpu_apic_realize(CPUState *cpu, Error **errp)
+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+if (cc->apic_realize != NULL) {
+(*cc->apic_realize)(cpu, errp);
+}
+}
+
 static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
 CPUState *cpu = CPU(dev);
 
 qemu_init_vcpu(cpu);
 
+cpu_apic_realize(cpu, errp);
+if (error_is_set(errp)) {
+return;
+}
+
 if (dev->hotplugged) {
 cpu_synchronize_post_init(cpu);
 notifier_list_notify(&cpu_added_notifiers, dev);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index cd350cb..916d69e 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2311,8 +2311,9 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 apic->cpu = cpu;
 }
 
-static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
+static void x86_cpu_apic_realize(CPUState *s, Error **errp)
 {
+X86CPU *cpu = X86_CPU(s);
 CPUX86State *env = &cpu->env;
 
 if (env->apic_state == NULL) {
@@ -2326,7 +2327,7 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error 
**errp)
 }
 }
 #else
-static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
+static void x86_cpu_apic_realize(CPUState *s, Error **errp)
 {
 }
 #endif
@@ -2388,10 +2389,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
**errp)
 
 mce_init(cpu);
 
-x86_cpu_apic_realize(cpu, &local_err);
-if (local_err != NULL) {
-goto out;
-}
 cpu_reset(CPU(cpu));
 
 xcc->parent_realize(dev, &local_err);
@@ -2540,6 +2537,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
 cc->get_arch_id = x86_cpu_get_arch_id;
 cc->get_paging_enabled = x86_cpu_get_paging_enabled;
+cc->apic_realize = x86_cpu_apic_realize;
 #ifndef CONFIG_USER_ONLY
 cc->get_memory_mapping = x86_cpu_get_memory_mapping;
 cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;
-- 
1.8.1.4




[Qemu-devel] windows guests: bad mouse responsiveness with gtk

2013-07-24 Thread Michael S. Tsirkin
I've recently tried experimenting with the gtk qemu frontend.
Unfortunately with gtk, mouse seems very unresponsive: sometimes I move
it and the pointer won't move, or it jumps around, or refuses to go to
some parts of the screen.

No issues if I supply -sdl.

I don't know much about how mouse works in QEMU -
any hints on debugging this?

-- 
MST



Re: [Qemu-devel] [Qemu-trivial] [PATCH] misc: Fix new typos in comments and strings

2013-07-24 Thread Michael Tokarev
24.07.2013 21:48, Stefan Weil wrote:
> All these typos were found by codespell.
> 
> sould -> should
> emperical -> empirical
> intialization -> initialization
> successfuly -> successfully
> gaurantee -> guarantee
> 
> Fix also another error (before before) in the same context.

Thanks, applied to the trivial patches queue.

/mjt



Re: [Qemu-devel] [Qemu-trivial] [PATCH] linux-user: correct argument number for sys_mremap and sys_splice

2013-07-24 Thread Michael Tokarev
23.07.2013 21:33, Peter Maydell wrote:
> On 23 July 2013 18:18, Michael Tokarev  wrote:
>> 23.07.2013 21:00, Petar Jovanovic wrote:
>>> From: Petar Jovanovic 
>>>
>>> sys_mremap missed 5th argument (new_address), which caused examples that
>>> remap to a specific address to fail.
>>> sys_splice missed 5th and 6th argument which caused different examples to
>>> fail.
>>> This change has an effect on MIPS target only.

Thanks, applied to the trivial patches queue.

/mjt



Re: [Qemu-devel] commit 08521e2 breaks SLOF usb boot

2013-07-24 Thread Nikunj A Dadhania
Paolo Bonzini  writes:

> Il 14/06/2013 12:32, Nikunj A Dadhania ha scritto:
>> Nikunj A Dadhania  writes:
>>> commit 08521e28c7e6e8cc1f53424a0f845f58d2ed9546
>>> Author: Paolo Bonzini 
>>> Date:   Fri May 24 12:54:01 2013 +0200
>>>
>>> memory: add big endian support to access_with_adjusted_size
>>> 
>>> This will be used to split 8-byte access down to two four-byte accesses.
>>> 
>>> Reviewed-by: Richard Henderson 
>>> Signed-off-by: Paolo Bonzini 
>>>
>>>
>>> If I hack the above funniness in my USB EHCI driver, somewhere down the
>>> qemu crashes at code introduced by this patch:
>>>
>>> Program received signal SIGSEGV, Segmentation fault.
>>> 0x in ?? ()
>>> (gdb) bt
>>> #0 0x in ?? ()
>>> #1 0x557a0ea4 in access_with_adjusted_size (addr=addr@entry=12, 
>>> value=value@entry=0x7fffd5a86680, size=size@entry=1, 
>>> access_size_min=, access_size_max=,
>>> access=0x557a1f80 , 
>>> opaque=0x567f8ab8) at /home/nikunj/work/power/code/qemu/memory.c:396
>>> #2 0x557a5ebb in memory_region_dispatch_write (size=1, data=0, 
>>> addr=12, mr=0x567f8ab8) at 
>>> /home/nikunj/work/power/code/qemu/memory.c:998
>>>
>>> Reverting this, I can safely boot using a usb-storage device put on ehci 
>>> controller.
>> 
>> Just reverting this patch does not help though, i will need to figure
>> which all commits are bad.
>
> Hi Nikunj,
>
> can you try the attached patch?
>
Sorry, for the late reply.

I tried your "iommu" branch at git://github.com/bonzini/qemu.git

Both ehci and ohci are working fine now in SLOF. I will do more testing and let
you know if there is any issues.

Thanks a lot.

Regards,
Nikunj




Re: [Qemu-devel] [PATCH v2 07/11] block: hold hard reference for backup/mirror target

2013-07-24 Thread Fam Zheng
On Tue, 07/23 11:52, Stefan Hajnoczi wrote:
> On Wed, Jul 17, 2013 at 05:42:12PM +0800, Fam Zheng wrote:
> > Signed-off-by: Fam Zheng 
> > ---
> >  block/backup.c | 3 ++-
> >  block/mirror.c | 4 ++--
> >  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> Should we update the blockjob.c in_use code instead of adding
> refcounting to specific block jobs?  This ought to be handled
> generically for all block jobs.

Target is not common in block jobs (e.g. doesn't apply to block-commit),
so it seems only specific block job knows about this.

-- 
Fam



Re: [Qemu-devel] [PATCH 00/28] Memory API for 1.6: fix I/O port endianness mess

2013-07-24 Thread Jan Kiszka
On 2013-07-25 07:47, Benjamin Herrenschmidt wrote:
> On Thu, 2013-07-25 at 15:26 +1000, Benjamin Herrenschmidt wrote:
>> On Mon, 2013-07-22 at 10:34 -0500, Anthony Liguori wrote:
>>>
>>> Really nice series.  I'd prefer we simply got rid of the endianness
>>> flag
>>> entirely but this is a good step.
>>>
>>> Reviewed-by: Anthony Liguori 
>>
>> Are you going to merge this ?
>>
>> Afaik (Alexey just told me), pretty much anything IO is broken for
>> powerpc upstream and has been for weeks now ! It looks like the only
>> thing that got reverted was the VGA problem but everything else is still
>> busted including virtio.
>>
>> Why hasn't the original breakage been reverted immediately instead ?
> 
> It's actually worse than I thought. Alexey is showing me that in fact,
> even PCI MMIO is busted, using EHCI causes qemu to segfault for example.

Can you be more specific? I suppose this is also on Power. Is it
unrelated to the endianness topic?

Jan




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [sheepdog] [PATCH v2 0/9] sheepdog: reconnect server after connection failure

2013-07-24 Thread Liu Yuan
On Thu, Jul 25, 2013 at 02:53:57PM +0900, MORITA Kazutaka wrote:
> At Thu, 25 Jul 2013 13:25:33 +0800,
> Liu Yuan wrote:
> > 
> > Hello Kazutaka,
> > 
> >I have two patches fixing the problems I found on my testing and they are
> > complementary patches. Please consider sending them on top of your patch 
> > set.
> 
> Thanks a lot for your comments and patches, but I've already prepared
> patches, which would be probably better fixes.  I'll send the v3
> series soon.  It'd be appreciated if you would give a review for it.
> 

Okay, no problem. Well, in my previous patches, patch 2/2 isn't correct, I did a
wrong manual rebase by hasty copy. Just FYI.

Thanks
Yuan



Re: [Qemu-devel] [sheepdog] [PATCH v2 0/9] sheepdog: reconnect server after connection failure

2013-07-24 Thread MORITA Kazutaka
At Thu, 25 Jul 2013 13:25:33 +0800,
Liu Yuan wrote:
> 
> Hello Kazutaka,
> 
>I have two patches fixing the problems I found on my testing and they are
> complementary patches. Please consider sending them on top of your patch set.

Thanks a lot for your comments and patches, but I've already prepared
patches, which would be probably better fixes.  I'll send the v3
series soon.  It'd be appreciated if you would give a review for it.

Thanks,

Kazutaka



Re: [Qemu-devel] [PATCH 00/28] Memory API for 1.6: fix I/O port endianness mess

2013-07-24 Thread Benjamin Herrenschmidt
On Thu, 2013-07-25 at 15:26 +1000, Benjamin Herrenschmidt wrote:
> On Mon, 2013-07-22 at 10:34 -0500, Anthony Liguori wrote:
> > 
> > Really nice series.  I'd prefer we simply got rid of the endianness
> > flag
> > entirely but this is a good step.
> > 
> > Reviewed-by: Anthony Liguori 
> 
> Are you going to merge this ?
> 
> Afaik (Alexey just told me), pretty much anything IO is broken for
> powerpc upstream and has been for weeks now ! It looks like the only
> thing that got reverted was the VGA problem but everything else is still
> busted including virtio.
> 
> Why hasn't the original breakage been reverted immediately instead ?

It's actually worse than I thought. Alexey is showing me that in fact,
even PCI MMIO is busted, using EHCI causes qemu to segfault for example.

This is a complete trainwreck. Why was that junk merged in the first
place and why wasn't it immediately reverted ?

Ben.





Re: [Qemu-devel] [PATCH v2 3/8] virtio: Add support for guest setting of queue size

2013-07-24 Thread Michael S. Tsirkin
On Fri, Jul 12, 2013 at 09:36:57PM +0100, Peter Maydell wrote:
> The MMIO virtio transport spec allows the guest to tell the host how
> large the queue size is. Add virtio_queue_set_num() function which
> implements this in the QEMU common virtio support code.
> 
> Signed-off-by: Peter Maydell 

Probably needs to go back to default value on reset?
Need to migrate?
Is the default value a max legal value? If yes probably a good
idea to enforce this.


> ---
>  hw/virtio/virtio.c |8 
>  include/hw/virtio/virtio.h |1 +
>  2 files changed, 9 insertions(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 8176c14..01b05f3 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -667,6 +667,14 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
>  return vdev->vq[n].pa;
>  }
>  
> +void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
> +{
> +if (num <= VIRTQUEUE_MAX_SIZE) {
> +vdev->vq[n].vring.num = num;
> +virtqueue_init(&vdev->vq[n]);
> +}
> +}
> +
>  int virtio_queue_get_num(VirtIODevice *vdev, int n)
>  {
>  return vdev->vq[n].vring.num;
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index a6c5c53..95c4772 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -198,6 +198,7 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t 
> addr, uint32_t data);
>  void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
>  void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
>  hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
> +void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
>  int virtio_queue_get_num(VirtIODevice *vdev, int n);
>  void virtio_queue_notify(VirtIODevice *vdev, int n);
>  uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
> -- 
> 1.7.9.5
> 



Re: [Qemu-devel] vhost acceleration broken?

2013-07-24 Thread Rusty Russell
Anthony Liguori  writes:
> On Wed, Jul 24, 2013 at 8:55 PM, Rusty Russell  wrote:
>> Hi all,
>>
>> Using latest kernel and master qemu, the following doesn't use
>> vhost acceleration:
>>
>> sudo qemu-system-x86_64 -machine pc,accel=kvm $ARGS -m 1024 -net 
>> tap,script=/home/rusty/bin/kvm-ifup,downscript=no,vhost=on -net 
>> nic,model=virtio -drive file=$QEMUIMAGE,index=0,media=disk,if=virtio -kernel 
>> arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"
>
> sudo qemu-system-x86_64 -enable-kvm $ARGS -m 1G -netdev
> tap,script=/home/rusty/bin/kvm-ifup,vhost=on,id=net0 -device
> virtio-net-pci,netdev=net0 -drive file=$QEMUIMAGE,if=virtio -kernel
> arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"
>
> We really ought to strongly deprecate -net because it's misleading.  I
> suspect we can reasonably add a warning for model=virtio saying
> "please don't use this" and eventually remove it entirely.

Thankyou, that works.

I'm sure you've thought more deeply about the qemu cmdline than I have,
so I won't comment.

Cheers,
Rusty.



Re: [Qemu-devel] [PATCH 00/28] Memory API for 1.6: fix I/O port endianness mess

2013-07-24 Thread Benjamin Herrenschmidt
On Mon, 2013-07-22 at 10:34 -0500, Anthony Liguori wrote:
> 
> Really nice series.  I'd prefer we simply got rid of the endianness
> flag
> entirely but this is a good step.
> 
> Reviewed-by: Anthony Liguori 

Are you going to merge this ?

Afaik (Alexey just told me), pretty much anything IO is broken for
powerpc upstream and has been for weeks now ! It looks like the only
thing that got reverted was the VGA problem but everything else is still
busted including virtio.

Why hasn't the original breakage been reverted immediately instead ?

Ben.





Re: [Qemu-devel] [PATCH v2 0/9] sheepdog: reconnect server after connection failure

2013-07-24 Thread Liu Yuan
Hello Kazutaka,

   I have two patches fixing the problems I found on my testing and they are
complementary patches. Please consider sending them on top of your patch set.

Thanks
Yuan



[Qemu-devel] [PATCH 2/2] sheepdog: put aio request into failed list when failing to send request

2013-07-24 Thread Liu Yuan
qemu_co_send() in the add_aio_request might fail if connection is closed. In
this case we should it requests into failed list to be resended later when
connection is repaired.

Signed-off-by: Liu Yuan 
---
 block/sheepdog.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 8c6c8f1..5bf78d0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1174,14 +1174,18 @@ static void coroutine_fn 
add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
 /* send a header */
 ret = qemu_co_send(s->fd, &hdr, sizeof(hdr));
 if (ret < (int)sizeof(hdr)) {
-error_report("failed to send a req, %s", strerror(errno));
+dprintf("failed to send a req, %s", strerror(errno));
+QLIST_REMOVE(aio_req, aio_siblings);
+QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req, aio_siblings);
 goto out;
 }
 
 if (wlen) {
 ret = qemu_co_sendv(s->fd, iov, niov, aio_req->iov_offset, wlen);
 if (ret < wlen) {
-error_report("failed to send a data, %s", strerror(errno));
+dprintf("failed to send a data, %s", strerror(errno));
+QLIST_REMOVE(aio_req, aio_siblings);
+QLIST_INSERT_HEAD(&s->pending_aio_head, aio_req, aio_siblings);
 }
 }
 out:
-- 
1.7.9.5




[Qemu-devel] [PATCH 1/2] sheepdog: correct signedness of comparison

2013-07-24 Thread Liu Yuan
When signed int compared to unsigned int, signed int will be converted to
unsigned int.

For example, (-1 < sizeof(structure)) always true because -1 in the left is
converted into unsigned int, thus this restule in unexpected true.

Signed-off-by: Liu Yuan 
---
 block/sheepdog.c |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 58e03c8..8c6c8f1 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -616,7 +616,7 @@ static coroutine_fn void do_co_req(void *opaque)
 
 if (*rlen) {
 ret = qemu_co_recv(sockfd, data, *rlen);
-if (ret < *rlen) {
+if (ret < (int)*rlen) {
 error_report("failed to get the data, %s", strerror(errno));
 ret = -errno;
 goto out;
@@ -755,7 +755,7 @@ static void coroutine_fn aio_read_response(void *opaque)
 
 /* read a header */
 ret = qemu_co_recv(fd, &rsp, sizeof(rsp));
-if (ret < sizeof(rsp)) {
+if (ret < (int)sizeof(rsp)) {
 error_report("failed to get the header, %s", strerror(errno));
 goto err;
 }
@@ -806,7 +806,7 @@ static void coroutine_fn aio_read_response(void *opaque)
 case AIOCB_READ_UDATA:
 ret = qemu_co_recvv(fd, acb->qiov->iov, acb->qiov->niov,
 aio_req->iov_offset, rsp.data_length);
-if (ret < rsp.data_length) {
+if (ret < (int)rsp.data_length) {
 error_report("failed to get the data, %s", strerror(errno));
 goto err;
 }
@@ -1116,7 +1116,7 @@ static void coroutine_fn 
add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
 {
 int nr_copies = s->inode.nr_copies;
 SheepdogObjReq hdr;
-unsigned int wlen = 0;
+int wlen = 0;
 int ret;
 uint64_t oid = aio_req->oid;
 unsigned int datalen = aio_req->data_len;
@@ -1173,7 +1173,7 @@ static void coroutine_fn 
add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
 
 /* send a header */
 ret = qemu_co_send(s->fd, &hdr, sizeof(hdr));
-if (ret < sizeof(hdr)) {
+if (ret < (int)sizeof(hdr)) {
 error_report("failed to send a req, %s", strerror(errno));
 goto out;
 }
-- 
1.7.9.5




Re: [Qemu-devel] vhost acceleration broken?

2013-07-24 Thread Michael S. Tsirkin
On Thu, Jul 25, 2013 at 11:25:20AM +0930, Rusty Russell wrote:
> Hi all,
> 
> Using latest kernel and master qemu, the following doesn't use
> vhost acceleration:
> 
> sudo qemu-system-x86_64 -machine pc,accel=kvm $ARGS -m 1024 -net 
> tap,script=/home/rusty/bin/kvm-ifup,downscript=no,vhost=on -net 
> nic,model=virtio -drive file=$QEMUIMAGE,index=0,media=disk,if=virtio -kernel 
> arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"
> 
> Culprit is here:
> 
> hw/net/virtio-net.c:virtio_net_vhost_status():
> if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
> return;
> }
> 
> info->type is NET_CLIENT_OPTIONS_KIND_HUBPORT.
> 
> At a glance, it seems like vlan is always enabled, and that means a hub,
> so that change silently disabled vhost acceleration.
> 
> It's quite possible that I've screwed up qemu's impenetrable command
> line (-net or -netdev, who knows what's better?).
> 
> Frustrated,
> Rusty.

That's just it.
Replace -net with -netdev, and things will work.





[Qemu-devel] [Bug 1204697] [NEW] guest disk accesses lead to ATA errors + host vcpu0 unhandled wrmsr/rdmsr

2013-07-24 Thread Christoph Anton Mitterer
Public bug reported:

Hi.

This is from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717724.

Using Debian sid with 1.5.0-5 my Linux VMs (also Debian sid) are broken. When 
they boot I get gazillions of ATA errors inside the guest, as well as:
[  242.479951] kvm [7790]: vcpu0 unhandled rdmsr: 0x345
[  242.483683] kvm [7790]: vcpu0 unhandled wrmsr: 0x680 data 0
[  242.483687] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c0 data 0
[  242.483689] kvm [7790]: vcpu0 unhandled wrmsr: 0x681 data 0
[  242.483691] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c1 data 0
[  242.483693] kvm [7790]: vcpu0 unhandled wrmsr: 0x682 data 0
[  242.483696] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c2 data 0
[  242.483698] kvm [7790]: vcpu0 unhandled wrmsr: 0x683 data 0
[  242.483700] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c3 data 0
[  242.483702] kvm [7790]: vcpu0 unhandled wrmsr: 0x684 data 0
[  242.483704] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c4 data 0
[  242.988307] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
[  242.988312] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
[  242.988314] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
[  242.988316] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
[  242.988318] kvm [7790]: vcpu0 unhandled rdmsr: 0x1ad
[  242.988320] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
[  242.988322] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
[  242.988324] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
[  242.988598] kvm [7790]: vcpu0 unhandled rdmsr: 0xce

in the host.

Please have a look at the Debian bug, for screenshots and more info.
The problem didn't occur in 1.5.0-4 and there were basically no changes inside 
the VM (i.e. no kernel upgrade or so).

Thanks,
Chris.

** Affects: qemu
 Importance: Undecided
 Status: New

** Affects: qemu (Debian)
 Importance: Unknown
 Status: Unknown

** Bug watch added: Debian Bug tracker #717724
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717724

** Also affects: qemu (Debian) via
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717724
   Importance: Unknown
   Status: Unknown

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

Title:
  guest disk accesses lead to ATA errors + host vcpu0 unhandled
  wrmsr/rdmsr

Status in QEMU:
  New
Status in “qemu” package in Debian:
  Unknown

Bug description:
  Hi.

  This is from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717724.

  Using Debian sid with 1.5.0-5 my Linux VMs (also Debian sid) are broken. When 
they boot I get gazillions of ATA errors inside the guest, as well as:
  [  242.479951] kvm [7790]: vcpu0 unhandled rdmsr: 0x345
  [  242.483683] kvm [7790]: vcpu0 unhandled wrmsr: 0x680 data 0
  [  242.483687] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c0 data 0
  [  242.483689] kvm [7790]: vcpu0 unhandled wrmsr: 0x681 data 0
  [  242.483691] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c1 data 0
  [  242.483693] kvm [7790]: vcpu0 unhandled wrmsr: 0x682 data 0
  [  242.483696] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c2 data 0
  [  242.483698] kvm [7790]: vcpu0 unhandled wrmsr: 0x683 data 0
  [  242.483700] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c3 data 0
  [  242.483702] kvm [7790]: vcpu0 unhandled wrmsr: 0x684 data 0
  [  242.483704] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c4 data 0
  [  242.988307] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
  [  242.988312] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
  [  242.988314] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988316] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988318] kvm [7790]: vcpu0 unhandled rdmsr: 0x1ad
  [  242.988320] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988322] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
  [  242.988324] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
  [  242.988598] kvm [7790]: vcpu0 unhandled rdmsr: 0xce

  in the host.

  Please have a look at the Debian bug, for screenshots and more info.
  The problem didn't occur in 1.5.0-4 and there were basically no changes 
inside the VM (i.e. no kernel upgrade or so).

  Thanks,
  Chris.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1204697/+subscriptions



[Qemu-devel] [Bug 1204697] Re: guest disk accesses lead to ATA errors + host vcpu0 unhandled wrmsr/rdmsr

2013-07-24 Thread Bug Watch Updater
** Changed in: qemu (Debian)
   Status: Unknown => Incomplete

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

Title:
  guest disk accesses lead to ATA errors + host vcpu0 unhandled
  wrmsr/rdmsr

Status in QEMU:
  New
Status in “qemu” package in Debian:
  Incomplete

Bug description:
  Hi.

  This is from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717724.

  Using Debian sid with 1.5.0-5 my Linux VMs (also Debian sid) are broken. When 
they boot I get gazillions of ATA errors inside the guest, as well as:
  [  242.479951] kvm [7790]: vcpu0 unhandled rdmsr: 0x345
  [  242.483683] kvm [7790]: vcpu0 unhandled wrmsr: 0x680 data 0
  [  242.483687] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c0 data 0
  [  242.483689] kvm [7790]: vcpu0 unhandled wrmsr: 0x681 data 0
  [  242.483691] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c1 data 0
  [  242.483693] kvm [7790]: vcpu0 unhandled wrmsr: 0x682 data 0
  [  242.483696] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c2 data 0
  [  242.483698] kvm [7790]: vcpu0 unhandled wrmsr: 0x683 data 0
  [  242.483700] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c3 data 0
  [  242.483702] kvm [7790]: vcpu0 unhandled wrmsr: 0x684 data 0
  [  242.483704] kvm [7790]: vcpu0 unhandled wrmsr: 0x6c4 data 0
  [  242.988307] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
  [  242.988312] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
  [  242.988314] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988316] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988318] kvm [7790]: vcpu0 unhandled rdmsr: 0x1ad
  [  242.988320] kvm [7790]: vcpu0 unhandled rdmsr: 0xce
  [  242.988322] kvm [7790]: vcpu0 unhandled rdmsr: 0xe8
  [  242.988324] kvm [7790]: vcpu0 unhandled rdmsr: 0xe7
  [  242.988598] kvm [7790]: vcpu0 unhandled rdmsr: 0xce

  in the host.

  Please have a look at the Debian bug, for screenshots and more info.
  The problem didn't occur in 1.5.0-4 and there were basically no changes 
inside the VM (i.e. no kernel upgrade or so).

  Thanks,
  Chris.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1204697/+subscriptions



Re: [Qemu-devel] Call for Proposals: 2013 Linux Plumbers Virtualization Microconference

2013-07-24 Thread Alex Williamson

Reminder, there's one week left to submit proposals for the
virtualization micro-conference at LPC.  Please see below for details
and note the update to submit proposals through the Linux Plumbers
website:

http://www.linuxplumbersconf.org/2013/ocw/events/LPC2013/proposals/new

Thanks,
Alex

On Sun, 2013-07-14 at 15:59 -0600, Alex Williamson wrote:
> On Fri, 2013-07-12 at 14:38 -0600, Alex Williamson wrote:
> > The Call for Proposals for the 2013 Linux Plumbers Virtualization
> > Microconference is now open.  This uconf is being held as part of Linux
> > Plumbers Conference in New Orleans, Louisiana, USA September 18-20th and
> > is co-located with LinuxCon North America.  For more information see:
> > 
> > http://www.linuxplumbersconf.org/2013/
> > 
> > The tentative deadline for proposals is August 1st.  To submit a topic
> > please email a brief abstract to lpc2013-virt...@codemonkey.ws  If you
> > require travel assistance (extremely limited) in order to attend, please
> > note that in your submission.  Also, please keep an eye on:
> > 
> > http://www.linuxplumbersconf.org/2013/submitting-topic/
> > http://www.linuxplumbersconf.org/2013/participate/
> > 
> > We've setup the above email submission as an interim approach until the
> > LPC program committee brings the official submission tool online.  I'll
> > send a follow-up message when that occurs, but please send your
> > proposals as soon as possible.  Thanks,
> 
> And the official tool is now online.  Please see:
> 
> http://www.linuxplumbersconf.org/2013/microconference-discussion-topic-bof-submissions-now-open/
> 
> for instructions to propose a discussion topic for the virtualization
> microconference.  Thanks,
> 
> Alex






Re: [Qemu-devel] RFC [PATCH] Make bdrv_flush synchronous only and update callers

2013-07-24 Thread Wenchao Xia
  I am glad to have an accurate sync bdrv_flush(). Code looks fine.

Reviewed-by: Wenchao Xia 

> This patch makes bdrv_flush a synchronous function and updates any callers 
> from
> a coroutine context to use bdrv_co_flush instead.
> 
> The motivation for this patch comes from the GSoC Continuation-Passing C
> project. When coroutines were introduced, synchronous functions in the block
> layer were converted to use asynchronous methods by dynamically detecting if
> they were being run from a coroutine context by calling qemu_in_coroutine(), 
> and
> yielding if so. If they were not, they would spawn a new coroutine and poll
> until the asynchronous counterpart finished.
> 
> However this approach does not work with CPC as the CPC translator converts 
> all
> functions annotated coroutine_fn to a different (continuation based) calling
> convention. This means that coroutine_fn annotated functions cannot be called
> from a non-coroutine context.
> 
> This patch is a Request For Comments on the approach of splitting these
> "dynamic" functions into synchronous and asynchronous versions. This is easy 
> for
> bdrv_flush as it already has an asynchronous counterpart - bdrv_co_flush. The
> only caller of bdrv_flush from a coroutine context is mirror_drain in
> block/mirror.c - this should be annotated as a coroutine_fn as it calls
> qemu_coroutine_yield().
> 
> If this approach meets with approval I will develop a patchset splitting the
> other "dynamic" functions in the block layer. This will allow all coroutine
> functions to have a coroutine_fn annotation that can be statically checked 
> (CPC
> can be used to verify annotations).
> 
> I have audited the other callers of bdrv_flush, they are included below:
> 
> block.c: bdrv_reopen_prepare, bdrv_close, bdrv_commit, bdrv_pwrite_sync
> block/qcow2-cache.c: qcow2_cache_entry_flush, qcow2_cache_flush
> block/qcow2-refcount.c: qcow2_update_snapshot_refcount
> block/qcow2-snapshot.c: qcow2_write_snapshots
> block/qcow2.c: qcow2_mark_dirty, qcow2_mark_clean
> block/qed-check.c: qed_check_mark_clean
> block/qed.c: bdrv_qed_open, bdrv_qed_close
> blockdev.c: external_snapshot_prepare, do_drive_del
> cpus.c: do_vm_stop
> hw/block/nvme.c: nvme_clear_ctrl
> qemu-io-cmds.c: flush_f
> savevm.c: bdrv_fclose
> 
> ---
>   block.c| 13 -
>   block/mirror.c |  4 ++--
>   2 files changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 6c493ad..00d71df 100644
> --- a/block.c
> +++ b/block.c
> @@ -4110,15 +4110,10 @@ int bdrv_flush(BlockDriverState *bs)
>   .ret = NOT_DONE,
>   };
> 
> -if (qemu_in_coroutine()) {
> -/* Fast-path if already in coroutine context */
> -bdrv_flush_co_entry(&rwco);
> -} else {
> -co = qemu_coroutine_create(bdrv_flush_co_entry);
> -qemu_coroutine_enter(co, &rwco);
> -while (rwco.ret == NOT_DONE) {
> -qemu_aio_wait();
> -}
> +co = qemu_coroutine_create(bdrv_flush_co_entry);
> +qemu_coroutine_enter(co, &rwco);
> +while (rwco.ret == NOT_DONE) {
> +qemu_aio_wait();
>   }
> 
>   return rwco.ret;
> diff --git a/block/mirror.c b/block/mirror.c
> index bed4a7e..3d5da7e 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -282,7 +282,7 @@ static void mirror_free_init(MirrorBlockJob *s)
>   }
>   }
> 
> -static void mirror_drain(MirrorBlockJob *s)
> +static void coroutine_fn mirror_drain(MirrorBlockJob *s)
>   {
>   while (s->in_flight > 0) {
>   qemu_coroutine_yield();
> @@ -390,7 +390,7 @@ static void coroutine_fn mirror_run(void *opaque)
>   should_complete = false;
>   if (s->in_flight == 0 && cnt == 0) {
>   trace_mirror_before_flush(s);
> -ret = bdrv_flush(s->target);
> +ret = bdrv_co_flush(s->target);
>   if (ret < 0) {
>   if (mirror_error_action(s, false, -ret) == 
> BDRV_ACTION_REPORT) {
>   goto immediate_exit;
> 


-- 
Best Regards

Wenchao Xia




Re: [Qemu-devel] [sheepdog] [PATCH v2 0/9] sheepdog: reconnect server after connection failure

2013-07-24 Thread Liu Yuan
On Wed, Jul 24, 2013 at 11:42:49PM +0800, Liu Yuan wrote:
> On Wed, Jul 24, 2013 at 06:07:21PM +0900, MORITA Kazutaka wrote:
> > At Wed, 24 Jul 2013 16:28:30 +0800,
> > Liu Yuan wrote:
> > > 
> > > On Wed, Jul 24, 2013 at 04:56:24PM +0900, MORITA Kazutaka wrote:
> > > > Currently, if a sheepdog server exits, all the connecting VMs need to
> > > > be restarted.  This series implements a feature to reconnect the
> > > > server, and enables us to do online sheepdog upgrade and avoid
> > > > restarting VMs when sheepdog servers crash unexpectedly.
> > > > 
> > > 
> > > It doesn't work on my test. I tried start linux-0.2.img stored in sheepdog
> > > cluster and then
> > > 
> > > 1. did some buffered writes
> > > 2. restart sheep that this QEMU VM connected to.
> > > 3. $ sync
> > > 
> > > I got following error:
> > > 
> > > $ ../qemu/x86_64-softmmu/qemu-system-x86_64 --enable-kvm -m 1024 -hda 
> > > sheepdog:test
> > > qemu-system-x86_64: failed to get the header, Resource temporarily 
> > > unavailable
> > > qemu-system-x86_64: Failed to connect to socket: Connection refused
> > > qemu-system-x86_64: Failed to connect to socket: Connection refused
> > > qemu-system-x86_64: Failed to connect to socket: Connection refused
> > > qemu-system-x86_64: Failed to connect to socket: Connection refused
> > > qemu-system-x86_64: Failed to connect to socket: Connection refused
> > > ...repeat...
> > > 
> > > QEMU version is master tip
> > 
> > Your sheep daemon looks like unreachable from qemu.  I tried the same
> > procedure, but couldn't reproduce it.
> > 
> > Is the problem reproducible?  Can you make sure that you can connect
> > to the sheep daemon from collie while the error message shows up?
> > 
> 
> Yesh. Well I try to repeat it with following process:
> 
> 1. did some buffered write
> 2. kill the sheep
> 3. $ sync # at guest, now 'sync' hang for response
> 4. restart sheep
> 
> After 4 'sync' still hangs until timeout with a message
> "hda:dma_timer_expiry: dma status == 0x21"
> 
> Guest end up freeze.
> 
> QEMU output is the same:
> qemu-system-x86_64: failed to get the header, Resource temporarily unavailable
> qemu-system-x86_64: Failed to connect to socket: Connection refused
> qemu-system-x86_64: Failed to connect to socket: Connection refused
> qemu-system-x86_64: Failed to connect to socket: Connection refused
> qemu-system-x86_64: Failed to connect to socket: Connection refused
> 
> But notice, if I did restart sheep with guest doing nothing, your patch set 
> work
> like a charm.

I have debug it a bit. The problem is that at stage 3, 'sync' invoke
add_aio_request() in the sheepdog driver and add_aio_request *succeed* with aio
put on the inflight_aio_head list, *not* on the failed_aio_head list. So in the
reconnect_to_sdog(), we have no way to resend the targeted aio and 'sync' wait
for ever.

Thanks
Yuan



Re: [Qemu-devel] [PATCH 0/4] export internal snapshot by qemu-nbd

2013-07-24 Thread Wenchao Xia
  Besides the argument, I think it helps to probe snapshot without
qemu-img convert, hope to get comments for the code.


-- 
Best Regards

Wenchao Xia




Re: [Qemu-devel] vhost acceleration broken?

2013-07-24 Thread Anthony Liguori
On Wed, Jul 24, 2013 at 8:55 PM, Rusty Russell  wrote:
> Hi all,
>
> Using latest kernel and master qemu, the following doesn't use
> vhost acceleration:
>
> sudo qemu-system-x86_64 -machine pc,accel=kvm $ARGS -m 1024 -net 
> tap,script=/home/rusty/bin/kvm-ifup,downscript=no,vhost=on -net 
> nic,model=virtio -drive file=$QEMUIMAGE,index=0,media=disk,if=virtio -kernel 
> arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"

sudo qemu-system-x86_64 -enable-kvm $ARGS -m 1G -netdev
tap,script=/home/rusty/bin/kvm-ifup,vhost=on,id=net0 -device
virtio-net-pci,netdev=net0 -drive file=$QEMUIMAGE,if=virtio -kernel
arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"

We really ought to strongly deprecate -net because it's misleading.  I
suspect we can reasonably add a warning for model=virtio saying
"please don't use this" and eventually remove it entirely.

> Culprit is here:
>
> hw/net/virtio-net.c:virtio_net_vhost_status():
> if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
> return;
> }
>
> info->type is NET_CLIENT_OPTIONS_KIND_HUBPORT.
>
> At a glance, it seems like vlan is always enabled, and that means a hub,
> so that change silently disabled vhost acceleration.
>
> It's quite possible that I've screwed up qemu's impenetrable command
> line (-net or -netdev, who knows what's better?).

It is for -net.  The whole vlan concept sucks and makes it too hard to
do offload or vhost.  It's still around for compatibility.

Regards,

Anthony Liguori

> Frustrated,
> Rusty.
>



[Qemu-devel] vhost acceleration broken?

2013-07-24 Thread Rusty Russell
Hi all,

Using latest kernel and master qemu, the following doesn't use
vhost acceleration:

sudo qemu-system-x86_64 -machine pc,accel=kvm $ARGS -m 1024 -net 
tap,script=/home/rusty/bin/kvm-ifup,downscript=no,vhost=on -net 
nic,model=virtio -drive file=$QEMUIMAGE,index=0,media=disk,if=virtio -kernel 
arch/x86/boot/bzImage -append "root=/dev/vda1 $KARGS $*"

Culprit is here:

hw/net/virtio-net.c:virtio_net_vhost_status():
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
return;
}

info->type is NET_CLIENT_OPTIONS_KIND_HUBPORT.

At a glance, it seems like vlan is always enabled, and that means a hub,
so that change silently disabled vhost acceleration.

It's quite possible that I've screwed up qemu's impenetrable command
line (-net or -netdev, who knows what's better?).

Frustrated,
Rusty.



Re: [Qemu-devel] [PATCH v2 08/11] block: simplify bdrv_drop_intermediate

2013-07-24 Thread Fam Zheng
On Wed, 07/24 19:16, Jeff Cody wrote:
> On Wed, Jul 17, 2013 at 05:42:13PM +0800, Fam Zheng wrote:
> > bdrv_drop_intermediate used a local list to iterate through backing
> > chain and delete each BDS. It is simplified while adopting to refcount
> > mechanism.
> > 
> 
> Hi Fam,
> 
> The reason for the local list is to keep the BDS deletion
> transactional, so it can be rolled back in case of error (see below)
> 
> > Signed-off-by: Fam Zheng 
> > ---
> >  block.c | 71 
> > ++---
> >  1 file changed, 11 insertions(+), 60 deletions(-)
> > 
> > diff --git a/block.c b/block.c
> > index 57a3876..499de22 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -2027,12 +2027,6 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState 
> > *active,
> >  return overlay;
> >  }
> >  
> > -typedef struct BlkIntermediateStates {
> > -BlockDriverState *bs;
> > -QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
> > -} BlkIntermediateStates;
> > -
> > -
> >  /*
> >   * Drops images above 'base' up to and including 'top', and sets the image
> >   * above 'top' to have base as its backing file.
> > @@ -2062,15 +2056,9 @@ typedef struct BlkIntermediateStates {
> >  int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
> > BlockDriverState *base)
> >  {
> > -BlockDriverState *intermediate;
> > -BlockDriverState *base_bs = NULL;
> >  BlockDriverState *new_top_bs = NULL;
> > -BlkIntermediateStates *intermediate_state, *next;
> >  int ret = -EIO;
> >  
> > -QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) 
> > states_to_delete;
> > -QSIMPLEQ_INIT(&states_to_delete);
> > -
> >  if (!top->drv || !base->drv) {
> >  goto exit;
> >  }
> > @@ -2082,58 +2070,21 @@ int bdrv_drop_intermediate(BlockDriverState 
> > *active, BlockDriverState *top,
> >  goto exit;
> >  }
> >  
> > -/* special case of new_top_bs->backing_hd already pointing to base - 
> > nothing
> > - * to do, no intermediate images */
> > -if (new_top_bs->backing_hd == base) {
> > -ret = 0;
> > -goto exit;
> > -}
> > -
> > -intermediate = top;
> > -
> > -/* now we will go down through the list, and add each BDS we find
> > - * into our deletion queue, until we hit the 'base'
> > - */
> > -while (intermediate) {
> > -intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
> > -intermediate_state->bs = intermediate;
> > -QSIMPLEQ_INSERT_TAIL(&states_to_delete, intermediate_state, entry);
> > -
> > -if (intermediate->backing_hd == base) {
> > -base_bs = intermediate->backing_hd;
> > -break;
> > +while (new_top_bs->backing_hd && new_top_bs->backing_hd != base) {
> > +BlockDriverState *backing = new_top_bs->backing_hd;
> > +if (backing == NULL) {
> > +goto exit;
> 
> If you simplify it until just a while loop that unrefs/deletes the BDS
> inside the loop as you navigate the chain, then any error exit leaves
> you in a bad state, with a potentially invalid chain.  This is one
> such error potential.
> 

Yes, I'll fix this.

-- 
Fam



Re: [Qemu-devel] [PATCH v3 05/14] loader: use file path size from fw_cfg.h

2013-07-24 Thread Andreas Färber
Am 24.07.2013 18:01, schrieb Michael S. Tsirkin:
> Avoid a bit of code duplication, make
> max file path constant reusable.
> 
> Suggested-by: Laszlo Ersek 
> Signed-off-by: Michael S. Tsirkin 

Reviewed-by: Andreas Färber 

Andreas

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



Re: [Qemu-devel] [PATCH qom-next] ide: Introduce abstract QOM type for PCIIDEState

2013-07-24 Thread Andreas Färber
Am 22.07.2013 17:58, schrieb Andreas Färber:
> Needed for QOM casts.
> 
> Signed-off-by: Andreas Färber 
> ---
>  hw/ide/cmd646.c | 62 
> ++---
>  hw/ide/pci.c| 30 +---
>  hw/ide/pci.h|  8 +++-
>  hw/ide/piix.c   | 24 ++
>  hw/ide/via.c| 18 -
>  5 files changed, 82 insertions(+), 60 deletions(-)

Since time is running away and there were no objections so far, applied
this to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

Andreas

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



[Qemu-devel] [PATCH qom-next for-1.6 8/8] tcx: QOM cast cleanups

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/tcx.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/display/tcx.c b/hw/display/tcx.c
index 9fd48b5..24876d3 100644
--- a/hw/display/tcx.c
+++ b/hw/display/tcx.c
@@ -34,8 +34,12 @@
 #define TCX_THC_NREGS_24 0x1000
 #define TCX_TEC_NREGS0x1000
 
+#define TYPE_TCX "SUNW,tcx"
+#define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX)
+
 typedef struct TCXState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 QemuConsole *con;
 uint8_t *vram;
 uint32_t *vram24, *cplane;
@@ -423,7 +427,7 @@ static const VMStateDescription vmstate_tcx = {
 
 static void tcx_reset(DeviceState *d)
 {
-TCXState *s = container_of(d, TCXState, busdev.qdev);
+TCXState *s = TCX(d);
 
 /* Initialize palette */
 memset(s->r, 0, 256);
@@ -523,7 +527,7 @@ static const GraphicHwOps tcx24_ops = {
 
 static int tcx_init1(SysBusDevice *dev)
 {
-TCXState *s = FROM_SYSBUS(TCXState, dev);
+TCXState *s = TCX(dev);
 ram_addr_t vram_offset = 0;
 int size;
 uint8_t *vram_base;
@@ -609,7 +613,7 @@ static void tcx_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo tcx_info = {
-.name  = "SUNW,tcx",
+.name  = TYPE_TCX,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(TCXState),
 .class_init= tcx_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 6/8] pl110: Rename pl110_state to PL110State

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/pl110.c | 64 +++---
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 60afcf3..7c2cd36 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -39,7 +39,7 @@ enum pl110_version
 PL111
 };
 
-typedef struct {
+typedef struct PL110State {
 SysBusDevice busdev;
 MemoryRegion iomem;
 QemuConsole *con;
@@ -59,7 +59,7 @@ typedef struct {
 uint32_t palette[256];
 uint32_t raw_palette[128];
 qemu_irq irq;
-} pl110_state;
+} PL110State;
 
 static int vmstate_pl110_post_load(void *opaque, int version_id);
 
@@ -69,20 +69,20 @@ static const VMStateDescription vmstate_pl110 = {
 .minimum_version_id = 1,
 .post_load = vmstate_pl110_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_INT32(version, pl110_state),
-VMSTATE_UINT32_ARRAY(timing, pl110_state, 4),
-VMSTATE_UINT32(cr, pl110_state),
-VMSTATE_UINT32(upbase, pl110_state),
-VMSTATE_UINT32(lpbase, pl110_state),
-VMSTATE_UINT32(int_status, pl110_state),
-VMSTATE_UINT32(int_mask, pl110_state),
-VMSTATE_INT32(cols, pl110_state),
-VMSTATE_INT32(rows, pl110_state),
-VMSTATE_UINT32(bpp, pl110_state),
-VMSTATE_INT32(invalidate, pl110_state),
-VMSTATE_UINT32_ARRAY(palette, pl110_state, 256),
-VMSTATE_UINT32_ARRAY(raw_palette, pl110_state, 128),
-VMSTATE_UINT32_V(mux_ctrl, pl110_state, 2),
+VMSTATE_INT32(version, PL110State),
+VMSTATE_UINT32_ARRAY(timing, PL110State, 4),
+VMSTATE_UINT32(cr, PL110State),
+VMSTATE_UINT32(upbase, PL110State),
+VMSTATE_UINT32(lpbase, PL110State),
+VMSTATE_UINT32(int_status, PL110State),
+VMSTATE_UINT32(int_mask, PL110State),
+VMSTATE_INT32(cols, PL110State),
+VMSTATE_INT32(rows, PL110State),
+VMSTATE_UINT32(bpp, PL110State),
+VMSTATE_INT32(invalidate, PL110State),
+VMSTATE_UINT32_ARRAY(palette, PL110State, 256),
+VMSTATE_UINT32_ARRAY(raw_palette, PL110State, 128),
+VMSTATE_UINT32_V(mux_ctrl, PL110State, 2),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -121,14 +121,14 @@ static const unsigned char *idregs[] = {
 #define BITS 32
 #include "pl110_template.h"
 
-static int pl110_enabled(pl110_state *s)
+static int pl110_enabled(PL110State *s)
 {
   return (s->cr & PL110_CR_EN) && (s->cr & PL110_CR_PWR);
 }
 
 static void pl110_update_display(void *opaque)
 {
-pl110_state *s = (pl110_state *)opaque;
+PL110State *s = (PL110State *)opaque;
 DisplaySurface *surface = qemu_console_surface(s->con);
 drawfn* fntable;
 drawfn fn;
@@ -246,14 +246,14 @@ static void pl110_update_display(void *opaque)
 
 static void pl110_invalidate_display(void * opaque)
 {
-pl110_state *s = (pl110_state *)opaque;
+PL110State *s = (PL110State *)opaque;
 s->invalidate = 1;
 if (pl110_enabled(s)) {
 qemu_console_resize(s->con, s->cols, s->rows);
 }
 }
 
-static void pl110_update_palette(pl110_state *s, int n)
+static void pl110_update_palette(PL110State *s, int n)
 {
 DisplaySurface *surface = qemu_console_surface(s->con);
 int i;
@@ -289,7 +289,7 @@ static void pl110_update_palette(pl110_state *s, int n)
 }
 }
 
-static void pl110_resize(pl110_state *s, int width, int height)
+static void pl110_resize(PL110State *s, int width, int height)
 {
 if (width != s->cols || height != s->rows) {
 if (pl110_enabled(s)) {
@@ -301,7 +301,7 @@ static void pl110_resize(pl110_state *s, int width, int 
height)
 }
 
 /* Update interrupts.  */
-static void pl110_update(pl110_state *s)
+static void pl110_update(PL110State *s)
 {
   /* TODO: Implement interrupts.  */
 }
@@ -309,7 +309,7 @@ static void pl110_update(pl110_state *s)
 static uint64_t pl110_read(void *opaque, hwaddr offset,
unsigned size)
 {
-pl110_state *s = (pl110_state *)opaque;
+PL110State *s = (PL110State *)opaque;
 
 if (offset >= 0xfe0 && offset < 0x1000) {
 return idregs[s->version][(offset - 0xfe0) >> 2];
@@ -359,7 +359,7 @@ static uint64_t pl110_read(void *opaque, hwaddr offset,
 static void pl110_write(void *opaque, hwaddr offset,
 uint64_t val, unsigned size)
 {
-pl110_state *s = (pl110_state *)opaque;
+PL110State *s = (PL110State *)opaque;
 int n;
 
 /* For simplicity invalidate the display whenever a control register
@@ -432,13 +432,13 @@ static const MemoryRegionOps pl110_ops = {
 
 static void pl110_mux_ctrl_set(void *opaque, int line, int level)
 {
-pl110_state *s = (pl110_state *)opaque;
+PL110State *s = (PL110State *)opaque;
 s->mux_ctrl = level;
 }
 
 static int vmstate_pl110_post_load(void *opaque, int version_id)
 {
-pl110_state *s = opaque;
+PL110State *s = opaque;
 /* Make sure we redraw, and at the right size */
   

[Qemu-devel] [PATCH qom-next for-1.6 3/8] jazz_led: QOM cast cleanups

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/jazz_led.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c
index 7f82037..8407e6c 100644
--- a/hw/display/jazz_led.c
+++ b/hw/display/jazz_led.c
@@ -32,8 +32,12 @@ typedef enum {
 REDRAW_NONE = 0, REDRAW_SEGMENTS = 1, REDRAW_BACKGROUND = 2,
 } screen_state_t;
 
+#define TYPE_JAZZ_LED "jazz-led"
+#define JAZZ_LED(obj) OBJECT_CHECK(LedState, (obj), TYPE_JAZZ_LED)
+
 typedef struct LedState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 uint8_t segments;
 QemuConsole *con;
@@ -262,7 +266,7 @@ static const GraphicHwOps jazz_led_ops = {
 
 static int jazz_led_init(SysBusDevice *dev)
 {
-LedState *s = FROM_SYSBUS(LedState, dev);
+LedState *s = JAZZ_LED(dev);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &led_ops, s, "led", 1);
 sysbus_init_mmio(dev, &s->iomem);
@@ -274,7 +278,7 @@ static int jazz_led_init(SysBusDevice *dev)
 
 static void jazz_led_reset(DeviceState *d)
 {
-LedState *s = DO_UPCAST(LedState, busdev.qdev, d);
+LedState *s = JAZZ_LED(d);
 
 s->segments = 0;
 s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
@@ -293,7 +297,7 @@ static void jazz_led_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo jazz_led_info = {
-.name  = "jazz-led",
+.name  = TYPE_JAZZ_LED,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(LedState),
 .class_init= jazz_led_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 7/8] pl110: QOM'ify pl110, pl110_versatile and pl111

2013-07-24 Thread Andreas Färber
Let pl110_versatile and pl111 inherit from pl110 and use PL110() cast;
set their version index in an instance_init.

Signed-off-by: Andreas Färber 
---
 hw/display/pl110.c | 71 ++
 1 file changed, 29 insertions(+), 42 deletions(-)

diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7c2cd36..c774e46 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -39,8 +39,12 @@ enum pl110_version
 PL111
 };
 
+#define TYPE_PL110 "pl110"
+#define PL110(obj) OBJECT_CHECK(PL110State, (obj), TYPE_PL110)
+
 typedef struct PL110State {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 QemuConsole *con;
 
@@ -129,6 +133,7 @@ static int pl110_enabled(PL110State *s)
 static void pl110_update_display(void *opaque)
 {
 PL110State *s = (PL110State *)opaque;
+SysBusDevice *sbd;
 DisplaySurface *surface = qemu_console_surface(s->con);
 drawfn* fntable;
 drawfn fn;
@@ -138,8 +143,11 @@ static void pl110_update_display(void *opaque)
 int first;
 int last;
 
-if (!pl110_enabled(s))
+if (!pl110_enabled(s)) {
 return;
+}
+
+sbd = SYS_BUS_DEVICE(s);
 
 switch (surface_bits_per_pixel(surface)) {
 case 0:
@@ -232,7 +240,7 @@ static void pl110_update_display(void *opaque)
 }
 dest_width *= s->cols;
 first = 0;
-framebuffer_update_display(surface, sysbus_address_space(&s->busdev),
+framebuffer_update_display(surface, sysbus_address_space(sbd),
s->upbase, s->cols, s->rows,
src_width, dest_width, 0,
s->invalidate,
@@ -449,30 +457,31 @@ static const GraphicHwOps pl110_gfx_ops = {
 .gfx_update  = pl110_update_display,
 };
 
-static int pl110_init(SysBusDevice *dev)
+static int pl110_init(SysBusDevice *sbd)
 {
-PL110State *s = FROM_SYSBUS(PL110State, dev);
+DeviceState *dev = DEVICE(sbd);
+PL110State *s = PL110(dev);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &pl110_ops, s, "pl110", 
0x1000);
-sysbus_init_mmio(dev, &s->iomem);
-sysbus_init_irq(dev, &s->irq);
-qdev_init_gpio_in(&s->busdev.qdev, pl110_mux_ctrl_set, 1);
-s->con = graphic_console_init(DEVICE(dev), &pl110_gfx_ops, s);
+sysbus_init_mmio(sbd, &s->iomem);
+sysbus_init_irq(sbd, &s->irq);
+qdev_init_gpio_in(dev, pl110_mux_ctrl_set, 1);
+s->con = graphic_console_init(dev, &pl110_gfx_ops, s);
 return 0;
 }
 
-static int pl110_versatile_init(SysBusDevice *dev)
+static void pl110_versatile_init(Object *obj)
 {
-PL110State *s = FROM_SYSBUS(PL110State, dev);
+PL110State *s = PL110(obj);
+
 s->version = PL110_VERSATILE;
-return pl110_init(dev);
 }
 
-static int pl111_init(SysBusDevice *dev)
+static void pl111_init(Object *obj)
 {
-PL110State *s = FROM_SYSBUS(PL110State, dev);
+PL110State *s = PL110(obj);
+
 s->version = PL111;
-return pl110_init(dev);
 }
 
 static void pl110_class_init(ObjectClass *klass, void *data)
@@ -486,44 +495,22 @@ static void pl110_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo pl110_info = {
-.name  = "pl110",
+.name  = TYPE_PL110,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(PL110State),
 .class_init= pl110_class_init,
 };
 
-static void pl110_versatile_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
-
-k->init = pl110_versatile_init;
-dc->no_user = 1;
-dc->vmsd = &vmstate_pl110;
-}
-
 static const TypeInfo pl110_versatile_info = {
 .name  = "pl110_versatile",
-.parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(PL110State),
-.class_init= pl110_versatile_class_init,
+.parent= TYPE_PL110,
+.instance_init = pl110_versatile_init,
 };
 
-static void pl111_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
-
-k->init = pl111_init;
-dc->no_user = 1;
-dc->vmsd = &vmstate_pl110;
-}
-
 static const TypeInfo pl111_info = {
 .name  = "pl111",
-.parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(PL110State),
-.class_init= pl111_class_init,
+.parent= TYPE_PL110,
+.instance_init = pl111_init,
 };
 
 static void pl110_register_types(void)
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 4/8] milkymist-tmu2: QOM cast cleanups

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/milkymist-tmu2.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/hw/display/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c
index efda082..b2a5fba 100644
--- a/hw/display/milkymist-tmu2.c
+++ b/hw/display/milkymist-tmu2.c
@@ -75,8 +75,13 @@ struct vertex {
 int y;
 } QEMU_PACKED;
 
+#define TYPE_MILKYMIST_TMU2 "milkymist-tmu2"
+#define MILKYMIST_TMU2(obj) \
+OBJECT_CHECK(MilkymistTMU2State, (obj), TYPE_MILKYMIST_TMU2)
+
 struct MilkymistTMU2State {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion regs_region;
 CharDriverState *chr;
 qemu_irq irq;
@@ -429,7 +434,7 @@ static const MemoryRegionOps tmu2_mmio_ops = {
 
 static void milkymist_tmu2_reset(DeviceState *d)
 {
-MilkymistTMU2State *s = container_of(d, MilkymistTMU2State, busdev.qdev);
+MilkymistTMU2State *s = MILKYMIST_TMU2(d);
 int i;
 
 for (i = 0; i < R_MAX; i++) {
@@ -439,7 +444,7 @@ static void milkymist_tmu2_reset(DeviceState *d)
 
 static int milkymist_tmu2_init(SysBusDevice *dev)
 {
-MilkymistTMU2State *s = FROM_SYSBUS(typeof(*s), dev);
+MilkymistTMU2State *s = MILKYMIST_TMU2(dev);
 
 if (tmu2_glx_init(s)) {
 return 1;
@@ -476,7 +481,7 @@ static void milkymist_tmu2_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo milkymist_tmu2_info = {
-.name  = "milkymist-tmu2",
+.name  = TYPE_MILKYMIST_TMU2,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(MilkymistTMU2State),
 .class_init= milkymist_tmu2_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 1/8] exynos4210_fimd: QOM cast cleanup

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/exynos4210_fimd.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c
index eb168ea..65cca1d 100644
--- a/hw/display/exynos4210_fimd.c
+++ b/hw/display/exynos4210_fimd.c
@@ -292,8 +292,13 @@ struct Exynos4210fimdWindow {
 hwaddr fb_len;   /* Framebuffer length */
 };
 
+#define TYPE_EXYNOS4210_FIMD "exynos4210.fimd"
+#define EXYNOS4210_FIMD(obj) \
+OBJECT_CHECK(Exynos4210fimdState, (obj), TYPE_EXYNOS4210_FIMD)
+
 typedef struct {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 QemuConsole *console;
 qemu_irq irq[3];
@@ -1108,6 +1113,7 @@ static inline int fimd_get_buffer_id(Exynos4210fimdWindow 
*w)
  * VIDOSDA, VIDOSDB, VIDWADDx and SHADOWCON registers */
 static void fimd_update_memory_section(Exynos4210fimdState *s, unsigned win)
 {
+SysBusDevice *sbd = SYS_BUS_DEVICE(s);
 Exynos4210fimdWindow *w = &s->window[win];
 hwaddr fb_start_addr, fb_mapped_len;
 
@@ -1131,8 +1137,8 @@ static void 
fimd_update_memory_section(Exynos4210fimdState *s, unsigned win)
  * does not support hot-unplug.
  */
 memory_region_unref(w->mem_section.mr);
-w->mem_section = memory_region_find(sysbus_address_space(&s->busdev),
-fb_start_addr, w->fb_len);
+w->mem_section = memory_region_find(sysbus_address_space(sbd),
+fb_start_addr, w->fb_len);
 assert(w->mem_section.mr);
 assert(w->mem_section.offset_within_address_space == fb_start_addr);
 DPRINT_TRACE("Window %u framebuffer changed: address=0x%08x, len=0x%x\n",
@@ -1328,7 +1334,7 @@ static void exynos4210_fimd_update(void *opaque)
 
 static void exynos4210_fimd_reset(DeviceState *d)
 {
-Exynos4210fimdState *s = DO_UPCAST(Exynos4210fimdState, busdev.qdev, d);
+Exynos4210fimdState *s = EXYNOS4210_FIMD(d);
 unsigned w;
 
 DPRINT_TRACE("Display controller reset\n");
@@ -1900,7 +1906,7 @@ static const GraphicHwOps exynos4210_fimd_ops = {
 
 static int exynos4210_fimd_init(SysBusDevice *dev)
 {
-Exynos4210fimdState *s = FROM_SYSBUS(Exynos4210fimdState, dev);
+Exynos4210fimdState *s = EXYNOS4210_FIMD(dev);
 
 s->ifb = NULL;
 
@@ -1927,7 +1933,7 @@ static void exynos4210_fimd_class_init(ObjectClass 
*klass, void *data)
 }
 
 static const TypeInfo exynos4210_fimd_info = {
-.name = "exynos4210.fimd",
+.name = TYPE_EXYNOS4210_FIMD,
 .parent = TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(Exynos4210fimdState),
 .class_init = exynos4210_fimd_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 0/8] display: QOM cast cleanups

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

This series eliminates FROM_SYSBUS() in hw/display/.

Regards,
Andreas

Cc: Hu Tao 

Andreas Färber (8):
  exynos4210_fimd: QOM cast cleanup
  g364fb: QOM cast cleanup
  jazz_led: QOM cast cleanups
  milkymist-tmu2: QOM cast cleanups
  milkymist-vgafb: QOM cast cleanups
  pl110: Rename pl110_state to PL110State
  pl110: QOM'ify pl110, pl110_versatile and pl111
  tcx: QOM cast cleanups

 hw/display/exynos4210_fimd.c |  18 ---
 hw/display/g364fb.c  |  25 +
 hw/display/jazz_led.c|  12 +++--
 hw/display/milkymist-tmu2.c  |  13 +++--
 hw/display/milkymist-vgafb.c |  17 --
 hw/display/pl110.c   | 125 +++
 hw/display/tcx.c |  12 +++--
 7 files changed, 121 insertions(+), 101 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 2/8] g364fb: QOM cast cleanup

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/g364fb.c | 25 -
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 79a0a50..a24a882 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -493,26 +493,33 @@ static void g364fb_init(DeviceState *dev, G364State *s)
 memory_region_set_coalescing(&s->mem_vram);
 }
 
+#define TYPE_G364 "sysbus-g364"
+#define G364(obj) OBJECT_CHECK(G364SysBusState, (obj), TYPE_G364)
+
 typedef struct {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 G364State g364;
 } G364SysBusState;
 
-static int g364fb_sysbus_init(SysBusDevice *dev)
+static int g364fb_sysbus_init(SysBusDevice *sbd)
 {
-G364State *s = &FROM_SYSBUS(G364SysBusState, dev)->g364;
+DeviceState *dev = DEVICE(sbd);
+G364SysBusState *sbs = G364(dev);
+G364State *s = &sbs->g364;
 
-g364fb_init(&dev->qdev, s);
-sysbus_init_irq(dev, &s->irq);
-sysbus_init_mmio(dev, &s->mem_ctrl);
-sysbus_init_mmio(dev, &s->mem_vram);
+g364fb_init(dev, s);
+sysbus_init_irq(sbd, &s->irq);
+sysbus_init_mmio(sbd, &s->mem_ctrl);
+sysbus_init_mmio(sbd, &s->mem_vram);
 
 return 0;
 }
 
 static void g364fb_sysbus_reset(DeviceState *d)
 {
-G364SysBusState *s = DO_UPCAST(G364SysBusState, busdev.qdev, d);
+G364SysBusState *s = G364(d);
+
 g364fb_reset(&s->g364);
 }
 
@@ -535,7 +542,7 @@ static void g364fb_sysbus_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo g364fb_sysbus_info = {
-.name  = "sysbus-g364",
+.name  = TYPE_G364,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(G364SysBusState),
 .class_init= g364fb_sysbus_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 5/8] milkymist-vgafb: QOM cast cleanups

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/display/milkymist-vgafb.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/hw/display/milkymist-vgafb.c b/hw/display/milkymist-vgafb.c
index 870b339..5150cb4 100644
--- a/hw/display/milkymist-vgafb.c
+++ b/hw/display/milkymist-vgafb.c
@@ -63,8 +63,13 @@ enum {
 CTRL_RESET = (1<<0),
 };
 
+#define TYPE_MILKYMIST_VGAFB "milkymist-vgafb"
+#define MILKYMIST_VGAFB(obj) \
+OBJECT_CHECK(MilkymistVgafbState, (obj), TYPE_MILKYMIST_VGAFB)
+
 struct MilkymistVgafbState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion regs_region;
 QemuConsole *con;
 
@@ -84,6 +89,7 @@ static int vgafb_enabled(MilkymistVgafbState *s)
 static void vgafb_update_display(void *opaque)
 {
 MilkymistVgafbState *s = opaque;
+SysBusDevice *sbd;
 DisplaySurface *surface = qemu_console_surface(s->con);
 int first = 0;
 int last = 0;
@@ -93,6 +99,7 @@ static void vgafb_update_display(void *opaque)
 return;
 }
 
+sbd = SYS_BUS_DEVICE(s);
 int dest_width = s->regs[R_HRES];
 
 switch (surface_bits_per_pixel(surface)) {
@@ -122,7 +129,7 @@ static void vgafb_update_display(void *opaque)
 break;
 }
 
-framebuffer_update_display(surface, sysbus_address_space(&s->busdev),
+framebuffer_update_display(surface, sysbus_address_space(sbd),
s->regs[R_BASEADDRESS] + s->fb_offset,
s->regs[R_HRES],
s->regs[R_VRES],
@@ -256,7 +263,7 @@ static const MemoryRegionOps vgafb_mmio_ops = {
 
 static void milkymist_vgafb_reset(DeviceState *d)
 {
-MilkymistVgafbState *s = container_of(d, MilkymistVgafbState, busdev.qdev);
+MilkymistVgafbState *s = MILKYMIST_VGAFB(d);
 int i;
 
 for (i = 0; i < R_MAX; i++) {
@@ -277,7 +284,7 @@ static const GraphicHwOps vgafb_ops = {
 
 static int milkymist_vgafb_init(SysBusDevice *dev)
 {
-MilkymistVgafbState *s = FROM_SYSBUS(typeof(*s), dev);
+MilkymistVgafbState *s = MILKYMIST_VGAFB(dev);
 
 memory_region_init_io(&s->regs_region, OBJECT(s), &vgafb_mmio_ops, s,
 "milkymist-vgafb", R_MAX * 4);
@@ -324,7 +331,7 @@ static void milkymist_vgafb_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo milkymist_vgafb_info = {
-.name  = "milkymist-vgafb",
+.name  = TYPE_MILKYMIST_VGAFB,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(MilkymistVgafbState),
 .class_init= milkymist_vgafb_class_init,
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH v2 08/11] block: simplify bdrv_drop_intermediate

2013-07-24 Thread Jeff Cody
On Wed, Jul 17, 2013 at 05:42:13PM +0800, Fam Zheng wrote:
> bdrv_drop_intermediate used a local list to iterate through backing
> chain and delete each BDS. It is simplified while adopting to refcount
> mechanism.
> 

Hi Fam,

The reason for the local list is to keep the BDS deletion
transactional, so it can be rolled back in case of error (see below)

> Signed-off-by: Fam Zheng 
> ---
>  block.c | 71 
> ++---
>  1 file changed, 11 insertions(+), 60 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 57a3876..499de22 100644
> --- a/block.c
> +++ b/block.c
> @@ -2027,12 +2027,6 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState 
> *active,
>  return overlay;
>  }
>  
> -typedef struct BlkIntermediateStates {
> -BlockDriverState *bs;
> -QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
> -} BlkIntermediateStates;
> -
> -
>  /*
>   * Drops images above 'base' up to and including 'top', and sets the image
>   * above 'top' to have base as its backing file.
> @@ -2062,15 +2056,9 @@ typedef struct BlkIntermediateStates {
>  int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
> BlockDriverState *base)
>  {
> -BlockDriverState *intermediate;
> -BlockDriverState *base_bs = NULL;
>  BlockDriverState *new_top_bs = NULL;
> -BlkIntermediateStates *intermediate_state, *next;
>  int ret = -EIO;
>  
> -QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete;
> -QSIMPLEQ_INIT(&states_to_delete);
> -
>  if (!top->drv || !base->drv) {
>  goto exit;
>  }
> @@ -2082,58 +2070,21 @@ int bdrv_drop_intermediate(BlockDriverState *active, 
> BlockDriverState *top,
>  goto exit;
>  }
>  
> -/* special case of new_top_bs->backing_hd already pointing to base - 
> nothing
> - * to do, no intermediate images */
> -if (new_top_bs->backing_hd == base) {
> -ret = 0;
> -goto exit;
> -}
> -
> -intermediate = top;
> -
> -/* now we will go down through the list, and add each BDS we find
> - * into our deletion queue, until we hit the 'base'
> - */
> -while (intermediate) {
> -intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
> -intermediate_state->bs = intermediate;
> -QSIMPLEQ_INSERT_TAIL(&states_to_delete, intermediate_state, entry);
> -
> -if (intermediate->backing_hd == base) {
> -base_bs = intermediate->backing_hd;
> -break;
> +while (new_top_bs->backing_hd && new_top_bs->backing_hd != base) {
> +BlockDriverState *backing = new_top_bs->backing_hd;
> +if (backing == NULL) {
> +goto exit;

If you simplify it until just a while loop that unrefs/deletes the BDS
inside the loop as you navigate the chain, then any error exit leaves
you in a bad state, with a potentially invalid chain.  This is one
such error potential.

>  }
> -intermediate = intermediate->backing_hd;
> -}
> -if (base_bs == NULL) {
> -/* something went wrong, we did not end at the base. safely
> - * unravel everything, and exit with error */
> -goto exit;
> +new_top_bs->backing_hd = backing->backing_hd;
> +/* break backing_hd chain before releasing bs, so we don't free all 
> the
> + * way up the backing chain */
> +backing->backing_hd = NULL;
> +bdrv_unref(backing, false);

These two statements, which unlink this BDS from the chain, can't be
undone now, in case of error.

>  }
>  
> -/* success - we can delete the intermediate states, and link top->base */
> -ret = bdrv_change_backing_file(new_top_bs, base_bs->filename,
> -   base_bs->drv ? base_bs->drv->format_name 
> : "");
> -if (ret) {
> -goto exit;
> -}
> -if (new_top_bs->backing_hd) {
> -bdrv_unref(new_top_bs->backing_hd, false);
> -}
> -new_top_bs->backing_hd = base_bs;
> -bdrv_ref(base_bs, false);
> -
> -QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, 
> next) {
> -/* so that bdrv_close() does not recursively close the chain */
> -intermediate_state->bs->backing_hd = NULL;
> -bdrv_delete(intermediate_state->bs);
> -}

The foreach loop over the list was placed such that there were no more
error paths; we were guaranteed at this point to have been able delete
and unchain each intermediate BDS.

> -ret = 0;
> -
> +ret = bdrv_change_backing_file(new_top_bs, base->filename,
> +   base->drv ? base->drv->format_name : "");

This is effectively another error path that would cause problems, if
ret < 0.

>  exit:
> -QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, 
> next) {
> -g_free(intermediate_state);
> -}
>  return ret;
>  }
>  
> -- 
> 1.8.3.2
> 
> 



Re: [Qemu-devel] [PATCH V7 09/13] monitor: support sub command in help

2013-07-24 Thread Eric Blake
On 07/19/2013 07:44 PM, Wenchao Xia wrote:
> The old code in help_cmd() use global 'info_cmds' and treat it as a

s/use/uses/; s/treat/treats/

> special case. Actually 'info_cmds' is an sub command group of 'mon_cmds',

s/an sub/a sub/

> in order to avoid direct use of it, help_cmd() need to change its work

s/need/needs/

> mechanism to support sub command and not treat it as a special case
> any more.
> 
> To support sub command, help_cmd() will first parse the input and then call
> help_cmd_dump(), which works as an reentrant function. When it mets sub

s/an/a/; s/mets/meets a/

> command, it simply re-enter the function again. Since help dumping need to

s/re-enter/enters/; s/need/needs/

> know whole input to printf full help message include prefix, for example,
> "help info block" need to printf prefix "info", so help_cmd_dump() takes all
> args from input and extra parameter arg_index to identify the progress.
> Another function help_cmd_dump_one() is introduced to printf the prefix
> and command's help message.
> 
> Now help support sub command, so later if another sub command group is

s/support/supports/

> added in any depth, help will automatically work for it. Still "help info
> block" will show error since command parser reject additional parameter,
> which can be improved later. "log" is still treated as a special case.
> 
> Signed-off-by: Wenchao Xia 
> ---
>  monitor.c |   63 +++-
>  1 files changed, 53 insertions(+), 10 deletions(-)
> 

Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH qom-next for-1.6 2/2] arm11mpcore: QOM cast cleanups for mpcore_rirq_state

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/cpu/arm11mpcore.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/hw/cpu/arm11mpcore.c b/hw/cpu/arm11mpcore.c
index 31c9d5a..a786c62 100644
--- a/hw/cpu/arm11mpcore.c
+++ b/hw/cpu/arm11mpcore.c
@@ -161,11 +161,16 @@ static int mpcore_priv_init(SysBusDevice *sbd)
 return 0;
 }
 
+#define TYPE_REALVIEW_MPCORE_RIRQ "realview_mpcore"
+#define REALVIEW_MPCORE_RIRQ(obj) \
+OBJECT_CHECK(mpcore_rirq_state, (obj), TYPE_REALVIEW_MPCORE_RIRQ)
+
 /* Dummy PIC to route IRQ lines.  The baseboard has 4 independent IRQ
controllers.  The output of these, plus some of the raw input lines
are fed into a single SMP-aware interrupt controller on the CPU.  */
 typedef struct {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 SysBusDevice *priv;
 qemu_irq cpuic[32];
 qemu_irq rvic[4][64];
@@ -196,9 +201,10 @@ static void mpcore_rirq_set_irq(void *opaque, int irq, int 
level)
 }
 }
 
-static int realview_mpcore_init(SysBusDevice *dev)
+static int realview_mpcore_init(SysBusDevice *sbd)
 {
-mpcore_rirq_state *s = FROM_SYSBUS(mpcore_rirq_state, dev);
+DeviceState *dev = DEVICE(sbd);
+mpcore_rirq_state *s = REALVIEW_MPCORE_RIRQ(dev);
 DeviceState *gic;
 DeviceState *priv;
 int n;
@@ -208,7 +214,7 @@ static int realview_mpcore_init(SysBusDevice *dev)
 qdev_prop_set_uint32(priv, "num-cpu", s->num_cpu);
 qdev_init_nofail(priv);
 s->priv = SYS_BUS_DEVICE(priv);
-sysbus_pass_irq(dev, s->priv);
+sysbus_pass_irq(sbd, s->priv);
 for (i = 0; i < 32; i++) {
 s->cpuic[i] = qdev_get_gpio_in(priv, i);
 }
@@ -220,8 +226,8 @@ static int realview_mpcore_init(SysBusDevice *dev)
 s->rvic[n][i] = qdev_get_gpio_in(gic, i);
 }
 }
-qdev_init_gpio_in(&dev->qdev, mpcore_rirq_set_irq, 64);
-sysbus_init_mmio(dev, sysbus_mmio_get_region(s->priv, 0));
+qdev_init_gpio_in(dev, mpcore_rirq_set_irq, 64);
+sysbus_init_mmio(sbd, sysbus_mmio_get_region(s->priv, 0));
 return 0;
 }
 
@@ -240,7 +246,7 @@ static void mpcore_rirq_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo mpcore_rirq_info = {
-.name  = "realview_mpcore",
+.name  = TYPE_REALVIEW_MPCORE_RIRQ,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(mpcore_rirq_state),
 .class_init= mpcore_rirq_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 1/2] arm11mpcore: QOM cast cleanups for ARM11MPCorePriveState

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/cpu/arm11mpcore.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/hw/cpu/arm11mpcore.c b/hw/cpu/arm11mpcore.c
index 8eeb53e..31c9d5a 100644
--- a/hw/cpu/arm11mpcore.c
+++ b/hw/cpu/arm11mpcore.c
@@ -12,8 +12,13 @@
 
 /* MPCore private memory region.  */
 
+#define TYPE_ARM11MPCORE_PRIV "arm11mpcore_priv"
+#define ARM11MPCORE_PRIV(obj) \
+OBJECT_CHECK(ARM11MPCorePriveState, (obj), TYPE_ARM11MPCORE_PRIV)
+
 typedef struct ARM11MPCorePriveState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 uint32_t scu_control;
 int iomemtype;
 uint32_t old_timer_status[8];
@@ -125,9 +130,10 @@ static void mpcore_priv_map_setup(ARM11MPCorePriveState *s)
 }
 }
 
-static int mpcore_priv_init(SysBusDevice *dev)
+static int mpcore_priv_init(SysBusDevice *sbd)
 {
-ARM11MPCorePriveState *s = FROM_SYSBUS(ARM11MPCorePriveState, dev);
+DeviceState *dev = DEVICE(sbd);
+ARM11MPCorePriveState *s = ARM11MPCORE_PRIV(dev);
 
 s->gic = qdev_create(NULL, "arm_gic");
 qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
@@ -137,10 +143,10 @@ static int mpcore_priv_init(SysBusDevice *dev)
 qdev_init_nofail(s->gic);
 
 /* Pass through outbound IRQ lines from the GIC */
-sysbus_pass_irq(dev, SYS_BUS_DEVICE(s->gic));
+sysbus_pass_irq(sbd, SYS_BUS_DEVICE(s->gic));
 
 /* Pass through inbound GPIO lines to the GIC */
-qdev_init_gpio_in(&s->busdev.qdev, mpcore_priv_set_irq, s->num_irq - 32);
+qdev_init_gpio_in(dev, mpcore_priv_set_irq, s->num_irq - 32);
 
 s->mptimer = qdev_create(NULL, "arm_mptimer");
 qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
@@ -151,7 +157,7 @@ static int mpcore_priv_init(SysBusDevice *dev)
 qdev_init_nofail(s->wdtimer);
 
 mpcore_priv_map_setup(s);
-sysbus_init_mmio(dev, &s->container);
+sysbus_init_mmio(sbd, &s->container);
 return 0;
 }
 
@@ -198,7 +204,7 @@ static int realview_mpcore_init(SysBusDevice *dev)
 int n;
 int i;
 
-priv = qdev_create(NULL, "arm11mpcore_priv");
+priv = qdev_create(NULL, TYPE_ARM11MPCORE_PRIV);
 qdev_prop_set_uint32(priv, "num-cpu", s->num_cpu);
 qdev_init_nofail(priv);
 s->priv = SYS_BUS_DEVICE(priv);
@@ -264,7 +270,7 @@ static void mpcore_priv_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo mpcore_priv_info = {
-.name  = "arm11mpcore_priv",
+.name  = TYPE_ARM11MPCORE_PRIV,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(ARM11MPCorePriveState),
 .class_init= mpcore_priv_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 0/2] cpu: QOM cast cleanups

2013-07-24 Thread Andreas Färber
Hello Peter,

This series eliminates FROM_SYSBUS() in hw/cpu/.

For QOM realize post-1.6 these devices will need cleanups similar to a9/a15;
it even instantiates arm11mpcore_priv from the realview_mpcore device, similar
to my Tegra2 SoC (although in the same file ;)).

Regards,
Andreas

Cc: Peter Maydell 
Cc: Hu Tao 

Andreas Färber (2):
  arm11mpcore: QOM cast cleanups for ARM11MPCorePriveState
  arm11mpcore: QOM cast cleanups for mpcore_rirq_state

 hw/cpu/arm11mpcore.c | 42 +++---
 1 file changed, 27 insertions(+), 15 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 02/14] escc: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/escc.c | 19 +++
 include/hw/char/escc.h |  1 +
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index 4c42198..6397f6f 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -96,8 +96,11 @@ typedef struct ChannelState {
 uint8_t rx, tx;
 } ChannelState;
 
+#define ESCC(obj) OBJECT_CHECK(ESCCState, (obj), TYPE_ESCC)
+
 typedef struct ESCCState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 struct ChannelState chn[2];
 uint32_t it_shift;
 MemoryRegion mmio;
@@ -309,7 +312,7 @@ static void escc_reset_chn(ChannelState *s)
 
 static void escc_reset(DeviceState *d)
 {
-ESCCState *s = container_of(d, ESCCState, busdev.qdev);
+ESCCState *s = ESCC(d);
 
 escc_reset_chn(&s->chn[0]);
 escc_reset_chn(&s->chn[1]);
@@ -534,7 +537,7 @@ static void escc_mem_write(void *opaque, hwaddr addr,
 escc_reset_chn(&serial->chn[1]);
 return;
 case MINTR_RST_ALL:
-escc_reset(&serial->busdev.qdev);
+escc_reset(DEVICE(serial));
 return;
 }
 break;
@@ -691,7 +694,7 @@ MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, 
qemu_irq irqB,
 SysBusDevice *s;
 ESCCState *d;
 
-dev = qdev_create(NULL, "escc");
+dev = qdev_create(NULL, TYPE_ESCC);
 qdev_prop_set_uint32(dev, "disabled", 0);
 qdev_prop_set_uint32(dev, "frequency", clock);
 qdev_prop_set_uint32(dev, "it_shift", it_shift);
@@ -707,7 +710,7 @@ MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, 
qemu_irq irqB,
 sysbus_mmio_map(s, 0, base);
 }
 
-d = FROM_SYSBUS(ESCCState, s);
+d = ESCC(s);
 return &d->mmio;
 }
 
@@ -852,7 +855,7 @@ void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
 DeviceState *dev;
 SysBusDevice *s;
 
-dev = qdev_create(NULL, "escc");
+dev = qdev_create(NULL, TYPE_ESCC);
 qdev_prop_set_uint32(dev, "disabled", disabled);
 qdev_prop_set_uint32(dev, "frequency", clock);
 qdev_prop_set_uint32(dev, "it_shift", it_shift);
@@ -869,7 +872,7 @@ void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
 
 static int escc_init1(SysBusDevice *dev)
 {
-ESCCState *s = FROM_SYSBUS(ESCCState, dev);
+ESCCState *s = ESCC(dev);
 unsigned int i;
 
 s->chn[0].disabled = s->disabled;
@@ -924,7 +927,7 @@ static void escc_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo escc_info = {
-.name  = "escc",
+.name  = TYPE_ESCC,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(ESCCState),
 .class_init= escc_class_init,
diff --git a/include/hw/char/escc.h b/include/hw/char/escc.h
index bda3213..2742d70 100644
--- a/include/hw/char/escc.h
+++ b/include/hw/char/escc.h
@@ -2,6 +2,7 @@
 #define HW_ESCC_H 1
 
 /* escc.c */
+#define TYPE_ESCC "escc"
 #define ESCC_SIZE 4
 MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, qemu_irq irqB,
   CharDriverState *chrA, CharDriverState *chrB,
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH V6 1/3] Implement sync modes for drive-backup.

2013-07-24 Thread Ian Main
On Wed, Jul 24, 2013 at 02:32:53PM -0600, Eric Blake wrote:
> On 07/24/2013 04:55 AM, Kevin Wolf wrote:
> 
> > Unconditionally overriding format for NEW_IMAGE_MODE_EXISTING is
> > definitely wrong. It's the user's choice which COW format to use for the
> > backup image. There's no reason why it has to be the same format as the
> > image that is being backed up.
> > 
> > Before, bs->drv->format_name was a default for the case where a new
> > image had to be created and no format was given; and the format of
> > existing images could be probed. This is still what makes most sense to
> > me. What's even the goal with this change?

Actually I think that code is wrong.  If we are using
NEW_IMAGE_MODE_EXISTING then format doesn't get used.  We just end up
using bdrv_open() below to open the existing image.  Format should not
be specified for an existing image.
 
> Furthermore, I'm proposing that for 1.6, we should make the format
> argument mandatory for drive-backup.  We made it optional for
> drive-mirror, to allow for probing, but there have been CVEs in the past
> due to probing of a raw file gone wrong.  We can always relax a
> mandatory argument into an optional one in 1.7, if we decide that
> probing can be done safely, but we can never turn an optional argument
> into a mandatory one once the initial release bakes in the option.  It
> would make the code a lot simpler to just have a mandatory format
> argument, instead of having to bake in and document hueristics on which
> format is picked when the caller doesn't provide one.

So I made format mandatory in the last patch but only for
NEW_IMAGE_MODE_ABSOLUTE_PATHS.  It actually doesn't make sense to
specify the format of an existing image so I left it optional as an
argument, but it will throw an error if it's not specified for the case
where we create a new image.

That make sense?

Ian
 



[Qemu-devel] [PATCH qom-next for-1.6 00/14] char: QOM cast cleanups

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

This series eliminates FROM_SYSBUS() in hw/char/.

Regards,
Andreas

Cc: Hu Tao 

Andreas Färber (14):
  cadence_uart: QOM'ify
  escc: QOM'ify
  etraxfs_ser: QOM'ify
  exynos4210_uart: QOM'ify
  grlib_apbuart: QOM'ify
  imx_serial: QOM'ify
  lm32_juart: Relocate and tidy header
  lm32_juart: QOM'ify
  lm32_uart: QOM'ify
  milkymist-uart: QOM'ify
  pl011: Rename pl011_state
  pl011: QOM'ify pl011 and pl011_luminary
  xilinx_uartlite: Rename xlx_uartlite to XilinxUARTLite
  xilinx_uartlite: QOM'ify

 MAINTAINERS|   1 +
 hw/char/cadence_uart.c |  10 ++-
 hw/char/escc.c |  19 +++---
 hw/char/etraxfs_ser.c  |  37 ++-
 hw/char/exynos4210_uart.c  |  26 
 hw/char/grlib_apbuart.c|  13 ++--
 hw/char/imx_serial.c   |  16 +++--
 hw/char/lm32_juart.c   |  21 ---
 hw/char/lm32_uart.c|  12 ++--
 hw/char/milkymist-uart.c   |  15 +++--
 hw/char/pl011.c| 110 +
 hw/char/xilinx_uartlite.c  |  30 +
 hw/lm32/lm32.h |   5 +-
 include/hw/char/escc.h |   1 +
 include/hw/{lm32 => char}/lm32_juart.h |   8 ++-
 target-lm32/op_helper.c|   2 +-
 16 files changed, 186 insertions(+), 140 deletions(-)
 rename include/hw/{lm32 => char}/lm32_juart.h (65%)

-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6] empty_slot: QOM'ify

2013-07-24 Thread Andreas Färber
Introduce type constant and use QOM casts.

Signed-off-by: Andreas Färber 
---
 hw/core/empty_slot.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/core/empty_slot.c b/hw/core/empty_slot.c
index e624991..612b109 100644
--- a/hw/core/empty_slot.c
+++ b/hw/core/empty_slot.c
@@ -22,8 +22,12 @@
 #define DPRINTF(fmt, ...) do {} while (0)
 #endif
 
+#define TYPE_EMPTY_SLOT "empty_slot"
+#define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
+
 typedef struct EmptySlot {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 uint64_t size;
 } EmptySlot;
@@ -55,9 +59,9 @@ void empty_slot_init(hwaddr addr, uint64_t slot_size)
 SysBusDevice *s;
 EmptySlot *e;
 
-dev = qdev_create(NULL, "empty_slot");
+dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
 s = SYS_BUS_DEVICE(dev);
-e = FROM_SYSBUS(EmptySlot, s);
+e = EMPTY_SLOT(dev);
 e->size = slot_size;
 
 qdev_init_nofail(dev);
@@ -68,7 +72,7 @@ void empty_slot_init(hwaddr addr, uint64_t slot_size)
 
 static int empty_slot_init1(SysBusDevice *dev)
 {
-EmptySlot *s = FROM_SYSBUS(EmptySlot, dev);
+EmptySlot *s = EMPTY_SLOT(dev);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
   "empty-slot", s->size);
@@ -84,7 +88,7 @@ static void empty_slot_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo empty_slot_info = {
-.name  = "empty_slot",
+.name  = TYPE_EMPTY_SLOT,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(EmptySlot),
 .class_init= empty_slot_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 14/14] xilinx_uartlite: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/xilinx_uartlite.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c
index 929743c..b0d1d04 100644
--- a/hw/char/xilinx_uartlite.c
+++ b/hw/char/xilinx_uartlite.c
@@ -46,8 +46,13 @@
 #define CONTROL_RST_RX0x02
 #define CONTROL_IE0x10
 
+#define TYPE_XILINX_UARTLITE "xlnx.xps-uartlite"
+#define XILINX_UARTLITE(obj) \
+OBJECT_CHECK(XilinxUARTLite, (obj), TYPE_XILINX_UARTLITE)
+
 typedef struct XilinxUARTLite {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion mmio;
 CharDriverState *chr;
 qemu_irq irq;
@@ -193,7 +198,7 @@ static void uart_event(void *opaque, int event)
 
 static int xilinx_uartlite_init(SysBusDevice *dev)
 {
-XilinxUARTLite *s = FROM_SYSBUS(typeof (*s), dev);
+XilinxUARTLite *s = XILINX_UARTLITE(dev);
 
 sysbus_init_irq(dev, &s->irq);
 
@@ -216,7 +221,7 @@ static void xilinx_uartlite_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo xilinx_uartlite_info = {
-.name  = "xlnx.xps-uartlite",
+.name  = TYPE_XILINX_UARTLITE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(XilinxUARTLite),
 .class_init= xilinx_uartlite_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 10/14] milkymist-uart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/milkymist-uart.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/char/milkymist-uart.c b/hw/char/milkymist-uart.c
index 46deab2..2e4b5c5 100644
--- a/hw/char/milkymist-uart.c
+++ b/hw/char/milkymist-uart.c
@@ -52,8 +52,13 @@ enum {
 DBG_BREAK_EN = (1<<0),
 };
 
+#define TYPE_MILKYMIST_UART "milkymist-uart"
+#define MILKYMIST_UART(obj) \
+OBJECT_CHECK(MilkymistUartState, (obj), TYPE_MILKYMIST_UART)
+
 struct MilkymistUartState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion regs_region;
 CharDriverState *chr;
 qemu_irq irq;
@@ -179,7 +184,7 @@ static void uart_event(void *opaque, int event)
 
 static void milkymist_uart_reset(DeviceState *d)
 {
-MilkymistUartState *s = container_of(d, MilkymistUartState, busdev.qdev);
+MilkymistUartState *s = MILKYMIST_UART(d);
 int i;
 
 for (i = 0; i < R_MAX; i++) {
@@ -192,12 +197,12 @@ static void milkymist_uart_reset(DeviceState *d)
 
 static int milkymist_uart_init(SysBusDevice *dev)
 {
-MilkymistUartState *s = FROM_SYSBUS(typeof(*s), dev);
+MilkymistUartState *s = MILKYMIST_UART(dev);
 
 sysbus_init_irq(dev, &s->irq);
 
 memory_region_init_io(&s->regs_region, OBJECT(s), &uart_mmio_ops, s,
-"milkymist-uart", R_MAX * 4);
+  "milkymist-uart", R_MAX * 4);
 sysbus_init_mmio(dev, &s->regs_region);
 
 s->chr = qemu_char_get_next_serial();
@@ -230,7 +235,7 @@ static void milkymist_uart_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo milkymist_uart_info = {
-.name  = "milkymist-uart",
+.name  = TYPE_MILKYMIST_UART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(MilkymistUartState),
 .class_init= milkymist_uart_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 08/14] lm32_juart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/lm32_juart.c | 19 +++
 hw/lm32/lm32.h   |  5 ++---
 include/hw/char/lm32_juart.h |  2 ++
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
index 154511e..252fe46 100644
--- a/hw/char/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -38,8 +38,11 @@ enum {
 JRX_FULL = (1<<8),
 };
 
+#define LM32_JUART(obj) OBJECT_CHECK(LM32JuartState, (obj), TYPE_LM32_JUART)
+
 struct LM32JuartState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 CharDriverState *chr;
 
 uint32_t jtx;
@@ -49,7 +52,7 @@ typedef struct LM32JuartState LM32JuartState;
 
 uint32_t lm32_juart_get_jtx(DeviceState *d)
 {
-LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
+LM32JuartState *s = LM32_JUART(d);
 
 trace_lm32_juart_get_jtx(s->jtx);
 return s->jtx;
@@ -57,7 +60,7 @@ uint32_t lm32_juart_get_jtx(DeviceState *d)
 
 uint32_t lm32_juart_get_jrx(DeviceState *d)
 {
-LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
+LM32JuartState *s = LM32_JUART(d);
 
 trace_lm32_juart_get_jrx(s->jrx);
 return s->jrx;
@@ -65,7 +68,7 @@ uint32_t lm32_juart_get_jrx(DeviceState *d)
 
 void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx)
 {
-LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
+LM32JuartState *s = LM32_JUART(d);
 unsigned char ch = jtx & 0xff;
 
 trace_lm32_juart_set_jtx(s->jtx);
@@ -78,7 +81,7 @@ void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx)
 
 void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx)
 {
-LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
+LM32JuartState *s = LM32_JUART(d);
 
 trace_lm32_juart_set_jrx(s->jrx);
 s->jrx &= ~JRX_FULL;
@@ -104,7 +107,7 @@ static void juart_event(void *opaque, int event)
 
 static void juart_reset(DeviceState *d)
 {
-LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
+LM32JuartState *s = LM32_JUART(d);
 
 s->jtx = 0;
 s->jrx = 0;
@@ -112,7 +115,7 @@ static void juart_reset(DeviceState *d)
 
 static int lm32_juart_init(SysBusDevice *dev)
 {
-LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev);
+LM32JuartState *s = LM32_JUART(dev);
 
 s->chr = qemu_char_get_next_serial();
 if (s->chr) {
@@ -145,7 +148,7 @@ static void lm32_juart_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo lm32_juart_info = {
-.name  = "lm32-juart",
+.name  = TYPE_LM32_JUART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(LM32JuartState),
 .class_init= lm32_juart_class_init,
diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
index 236686e..18aa6fd 100644
--- a/hw/lm32/lm32.h
+++ b/hw/lm32/lm32.h
@@ -1,8 +1,7 @@
 #ifndef HW_LM32_H
 #define HW_LM32_H 1
 
-
-#include "qemu-common.h"
+#include "hw/char/lm32_juart.h"
 
 static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)
 {
@@ -21,7 +20,7 @@ static inline DeviceState *lm32_juart_init(void)
 {
 DeviceState *dev;
 
-dev = qdev_create(NULL, "lm32-juart");
+dev = qdev_create(NULL, TYPE_LM32_JUART);
 qdev_init_nofail(dev);
 
 return dev;
diff --git a/include/hw/char/lm32_juart.h b/include/hw/char/lm32_juart.h
index 1cd3148..70dc416 100644
--- a/include/hw/char/lm32_juart.h
+++ b/include/hw/char/lm32_juart.h
@@ -3,6 +3,8 @@
 
 #include "hw/qdev.h"
 
+#define TYPE_LM32_JUART "lm32-juart"
+
 uint32_t lm32_juart_get_jtx(DeviceState *d);
 uint32_t lm32_juart_get_jrx(DeviceState *d);
 void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx);
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 09/14] lm32_uart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/lm32_uart.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/char/lm32_uart.c b/hw/char/lm32_uart.c
index 37b38ba..85d7265 100644
--- a/hw/char/lm32_uart.c
+++ b/hw/char/lm32_uart.c
@@ -89,8 +89,12 @@ enum {
 MSR_DCD  = (1<<7),
 };
 
+#define TYPE_LM32_UART "lm32-uart"
+#define LM32_UART(obj) OBJECT_CHECK(LM32UartState, (obj), TYPE_LM32_UART)
+
 struct LM32UartState {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 CharDriverState *chr;
 qemu_irq irq;
@@ -233,7 +237,7 @@ static void uart_event(void *opaque, int event)
 
 static void uart_reset(DeviceState *d)
 {
-LM32UartState *s = container_of(d, LM32UartState, busdev.qdev);
+LM32UartState *s = LM32_UART(d);
 int i;
 
 for (i = 0; i < R_MAX; i++) {
@@ -246,7 +250,7 @@ static void uart_reset(DeviceState *d)
 
 static int lm32_uart_init(SysBusDevice *dev)
 {
-LM32UartState *s = FROM_SYSBUS(typeof(*s), dev);
+LM32UartState *s = LM32_UART(dev);
 
 sysbus_init_irq(dev, &s->irq);
 
@@ -284,7 +288,7 @@ static void lm32_uart_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo lm32_uart_info = {
-.name  = "lm32-uart",
+.name  = TYPE_LM32_UART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(LM32UartState),
 .class_init= lm32_uart_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 06/14] imx_serial: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/imx_serial.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c
index 69b9ed2..d5d21c9 100644
--- a/hw/char/imx_serial.c
+++ b/hw/char/imx_serial.c
@@ -43,8 +43,12 @@ do { printf("imx_serial: " fmt , ##args); } while (0)
 #  define IPRINTF(fmt, args...) do {} while (0)
 #endif
 
-typedef struct {
-SysBusDevice busdev;
+#define TYPE_IMX_SERIAL "imx-serial"
+#define IMX_SERIAL(obj) OBJECT_CHECK(IMXSerialState, (obj), TYPE_IMX_SERIAL)
+
+typedef struct IMXSerialState {
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 int32_t readbuff;
 
@@ -169,7 +173,7 @@ static void imx_serial_reset(IMXSerialState *s)
 
 static void imx_serial_reset_at_boot(DeviceState *dev)
 {
-IMXSerialState *s = container_of(dev, IMXSerialState, busdev.qdev);
+IMXSerialState *s = IMX_SERIAL(dev);
 
 imx_serial_reset(s);
 
@@ -383,7 +387,7 @@ static const struct MemoryRegionOps imx_serial_ops = {
 
 static int imx_serial_init(SysBusDevice *dev)
 {
-IMXSerialState *s = FROM_SYSBUS(IMXSerialState, dev);
+IMXSerialState *s = IMX_SERIAL(dev);
 
 
 memory_region_init_io(&s->iomem, OBJECT(s), &imx_serial_ops, s,
@@ -410,7 +414,7 @@ void imx_serial_create(int uart, const hwaddr addr, 
qemu_irq irq)
 const char chr_name[] = "serial";
 char label[ARRAY_SIZE(chr_name) + 1];
 
-dev = qdev_create(NULL, "imx-serial");
+dev = qdev_create(NULL, TYPE_IMX_SERIAL);
 
 if (uart >= MAX_SERIAL_PORTS) {
 hw_error("Cannot assign uart %d: QEMU supports only %d ports\n",
@@ -454,7 +458,7 @@ static void imx_serial_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo imx_serial_info = {
-.name = "imx-serial",
+.name = TYPE_IMX_SERIAL,
 .parent = TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(IMXSerialState),
 .class_init = imx_serial_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 07/14] lm32_juart: Relocate and tidy header

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 MAINTAINERS| 1 +
 hw/char/lm32_juart.c   | 2 +-
 include/hw/{lm32 => char}/lm32_juart.h | 6 +++---
 target-lm32/op_helper.c| 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)
 rename include/hw/{lm32 => char}/lm32_juart.h (72%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 93ad19d..82ca5fb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -80,6 +80,7 @@ M: Michael Walle 
 S: Maintained
 F: target-lm32/
 F: hw/lm32/
+F: hw/char/lm32_*
 
 M68K
 M: Paul Brook 
diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
index 839f3eb..154511e 100644
--- a/hw/char/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -22,7 +22,7 @@
 #include "trace.h"
 #include "sysemu/char.h"
 
-#include "hw/lm32/lm32_juart.h"
+#include "hw/char/lm32_juart.h"
 
 enum {
 LM32_JUART_MIN_SAVE_VERSION = 0,
diff --git a/include/hw/lm32/lm32_juart.h b/include/hw/char/lm32_juart.h
similarity index 72%
rename from include/hw/lm32/lm32_juart.h
rename to include/hw/char/lm32_juart.h
index 67fc586..1cd3148 100644
--- a/include/hw/lm32/lm32_juart.h
+++ b/include/hw/char/lm32_juart.h
@@ -1,7 +1,7 @@
-#ifndef QEMU_HW_LM32_JUART_H
-#define QEMU_HW_LM32_JUART_H
+#ifndef QEMU_HW_CHAR_LM32_JUART_H
+#define QEMU_HW_CHAR_LM32_JUART_H
 
-#include "qemu-common.h"
+#include "hw/qdev.h"
 
 uint32_t lm32_juart_get_jtx(DeviceState *d);
 uint32_t lm32_juart_get_jrx(DeviceState *d);
diff --git a/target-lm32/op_helper.c b/target-lm32/op_helper.c
index f106873..2dab9f2 100644
--- a/target-lm32/op_helper.c
+++ b/target-lm32/op_helper.c
@@ -4,7 +4,7 @@
 #include "qemu/host-utils.h"
 
 #include "hw/lm32/lm32_pic.h"
-#include "hw/lm32/lm32_juart.h"
+#include "hw/char/lm32_juart.h"
 
 #if !defined(CONFIG_USER_ONLY)
 #define MMUSUFFIX _mmu
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 04/14] exynos4210_uart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/exynos4210_uart.c | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index 855ce7a..eef23a0 100644
--- a/hw/char/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -166,8 +166,13 @@ typedef struct {
 uint32_tsize;
 } Exynos4210UartFIFO;
 
-typedef struct {
-SysBusDevice busdev;
+#define TYPE_EXYNOS4210_UART "exynos4210.uart"
+#define EXYNOS4210_UART(obj) \
+OBJECT_CHECK(Exynos4210UartState, (obj), TYPE_EXYNOS4210_UART)
+
+typedef struct Exynos4210UartState {
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 
 uint32_t reg[EXYNOS4210_UART_REGS_MEM_SIZE / sizeof(uint32_t)];
@@ -538,8 +543,7 @@ static void exynos4210_uart_event(void *opaque, int event)
 
 static void exynos4210_uart_reset(DeviceState *dev)
 {
-Exynos4210UartState *s =
-container_of(dev, Exynos4210UartState, busdev.qdev);
+Exynos4210UartState *s = EXYNOS4210_UART(dev);
 int regs_number = sizeof(exynos4210_uart_regs)/sizeof(Exynos4210UartReg);
 int i;
 
@@ -582,10 +586,10 @@ static const VMStateDescription vmstate_exynos4210_uart = 
{
 };
 
 DeviceState *exynos4210_uart_create(hwaddr addr,
- int fifo_size,
- int channel,
- CharDriverState *chr,
- qemu_irq irq)
+int fifo_size,
+int channel,
+CharDriverState *chr,
+qemu_irq irq)
 {
 DeviceState  *dev;
 SysBusDevice *bus;
@@ -593,7 +597,7 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
 const char chr_name[] = "serial";
 char label[ARRAY_SIZE(chr_name) + 1];
 
-dev = qdev_create(NULL, "exynos4210.uart");
+dev = qdev_create(NULL, TYPE_EXYNOS4210_UART);
 
 if (!chr) {
 if (channel >= MAX_SERIAL_PORTS) {
@@ -627,7 +631,7 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
 
 static int exynos4210_uart_init(SysBusDevice *dev)
 {
-Exynos4210UartState *s = FROM_SYSBUS(Exynos4210UartState, dev);
+Exynos4210UartState *s = EXYNOS4210_UART(dev);
 
 /* memory mapping */
 memory_region_init_io(&s->iomem, OBJECT(s), &exynos4210_uart_ops, s,
@@ -662,7 +666,7 @@ static void exynos4210_uart_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo exynos4210_uart_info = {
-.name  = "exynos4210.uart",
+.name  = TYPE_EXYNOS4210_UART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(Exynos4210UartState),
 .class_init= exynos4210_uart_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 13/14] xilinx_uartlite: Rename xlx_uartlite to XilinxUARTLite

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/xilinx_uartlite.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c
index feca497..929743c 100644
--- a/hw/char/xilinx_uartlite.c
+++ b/hw/char/xilinx_uartlite.c
@@ -46,8 +46,7 @@
 #define CONTROL_RST_RX0x02
 #define CONTROL_IE0x10
 
-struct xlx_uartlite
-{
+typedef struct XilinxUARTLite {
 SysBusDevice busdev;
 MemoryRegion mmio;
 CharDriverState *chr;
@@ -58,9 +57,9 @@ struct xlx_uartlite
 unsigned int rx_fifo_len;
 
 uint32_t regs[R_MAX];
-};
+} XilinxUARTLite;
 
-static void uart_update_irq(struct xlx_uartlite *s)
+static void uart_update_irq(XilinxUARTLite *s)
 {
 unsigned int irq;
 
@@ -71,7 +70,7 @@ static void uart_update_irq(struct xlx_uartlite *s)
 qemu_set_irq(s->irq, irq);
 }
 
-static void uart_update_status(struct xlx_uartlite *s)
+static void uart_update_status(XilinxUARTLite *s)
 {
 uint32_t r;
 
@@ -86,7 +85,7 @@ static void uart_update_status(struct xlx_uartlite *s)
 static uint64_t
 uart_read(void *opaque, hwaddr addr, unsigned int size)
 {
-struct xlx_uartlite *s = opaque;
+XilinxUARTLite *s = opaque;
 uint32_t r = 0;
 addr >>= 2;
 switch (addr)
@@ -113,7 +112,7 @@ static void
 uart_write(void *opaque, hwaddr addr,
uint64_t val64, unsigned int size)
 {
-struct xlx_uartlite *s = opaque;
+XilinxUARTLite *s = opaque;
 uint32_t value = val64;
 unsigned char ch = value;
 
@@ -164,7 +163,7 @@ static const MemoryRegionOps uart_ops = {
 
 static void uart_rx(void *opaque, const uint8_t *buf, int size)
 {
-struct xlx_uartlite *s = opaque;
+XilinxUARTLite *s = opaque;
 
 /* Got a byte.  */
 if (s->rx_fifo_len >= 8) {
@@ -182,7 +181,7 @@ static void uart_rx(void *opaque, const uint8_t *buf, int 
size)
 
 static int uart_can_rx(void *opaque)
 {
-struct xlx_uartlite *s = opaque;
+XilinxUARTLite *s = opaque;
 
 return s->rx_fifo_len < sizeof(s->rx_fifo);
 }
@@ -194,7 +193,7 @@ static void uart_event(void *opaque, int event)
 
 static int xilinx_uartlite_init(SysBusDevice *dev)
 {
-struct xlx_uartlite *s = FROM_SYSBUS(typeof (*s), dev);
+XilinxUARTLite *s = FROM_SYSBUS(typeof (*s), dev);
 
 sysbus_init_irq(dev, &s->irq);
 
@@ -219,7 +218,7 @@ static void xilinx_uartlite_class_init(ObjectClass *klass, 
void *data)
 static const TypeInfo xilinx_uartlite_info = {
 .name  = "xlnx.xps-uartlite",
 .parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof (struct xlx_uartlite),
+.instance_size = sizeof(XilinxUARTLite),
 .class_init= xilinx_uartlite_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 03/14] etraxfs_ser: QOM'ify

2013-07-24 Thread Andreas Färber
Rename etrax_serial to ETRAXSerial, introduce type constant and use QOM
casts.

Signed-off-by: Andreas Färber 
---
 hw/char/etraxfs_ser.c | 37 +
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index d19af00..460094e 100644
--- a/hw/char/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -44,9 +44,13 @@
 #define STAT_TR_IDLE 22
 #define STAT_TR_RDY  24
 
-struct etrax_serial
-{
-SysBusDevice busdev;
+#define TYPE_ETRAX_FS_SERIAL "etraxfs,serial"
+#define ETRAX_SERIAL(obj) \
+OBJECT_CHECK(ETRAXSerial, (obj), TYPE_ETRAX_FS_SERIAL)
+
+typedef struct ETRAXSerial {
+SysBusDevice parent_obj;
+
 MemoryRegion mmio;
 CharDriverState *chr;
 qemu_irq irq;
@@ -59,9 +63,9 @@ struct etrax_serial
 
 /* Control registers.  */
 uint32_t regs[R_MAX];
-};
+} ETRAXSerial;
 
-static void ser_update_irq(struct etrax_serial *s)
+static void ser_update_irq(ETRAXSerial *s)
 {
 
 if (s->rx_fifo_len) {
@@ -77,7 +81,7 @@ static void ser_update_irq(struct etrax_serial *s)
 static uint64_t
 ser_read(void *opaque, hwaddr addr, unsigned int size)
 {
-struct etrax_serial *s = opaque;
+ETRAXSerial *s = opaque;
 uint32_t r = 0;
 
 addr >>= 2;
@@ -112,7 +116,7 @@ static void
 ser_write(void *opaque, hwaddr addr,
   uint64_t val64, unsigned int size)
 {
-struct etrax_serial *s = opaque;
+ETRAXSerial *s = opaque;
 uint32_t value = val64;
 unsigned char ch = val64;
 
@@ -156,7 +160,7 @@ static const MemoryRegionOps ser_ops = {
 
 static void serial_receive(void *opaque, const uint8_t *buf, int size)
 {
-struct etrax_serial *s = opaque;
+ETRAXSerial *s = opaque;
 int i;
 
 /* Got a byte.  */
@@ -177,7 +181,7 @@ static void serial_receive(void *opaque, const uint8_t 
*buf, int size)
 
 static int serial_can_receive(void *opaque)
 {
-struct etrax_serial *s = opaque;
+ETRAXSerial *s = opaque;
 int r;
 
 /* Is the receiver enabled?  */
@@ -196,7 +200,7 @@ static void serial_event(void *opaque, int event)
 
 static void etraxfs_ser_reset(DeviceState *d)
 {
-struct etrax_serial *s = container_of(d, typeof(*s), busdev.qdev);
+ETRAXSerial *s = ETRAX_SERIAL(d);
 
 /* transmitter begins ready and idle.  */
 s->regs[RS_STAT_DIN] |= (1 << STAT_TR_RDY);
@@ -208,7 +212,7 @@ static void etraxfs_ser_reset(DeviceState *d)
 
 static int etraxfs_ser_init(SysBusDevice *dev)
 {
-struct etrax_serial *s = FROM_SYSBUS(typeof (*s), dev);
+ETRAXSerial *s = ETRAX_SERIAL(dev);
 
 sysbus_init_irq(dev, &s->irq);
 memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s,
@@ -216,10 +220,11 @@ static int etraxfs_ser_init(SysBusDevice *dev)
 sysbus_init_mmio(dev, &s->mmio);
 
 s->chr = qemu_char_get_next_serial();
-if (s->chr)
+if (s->chr) {
 qemu_chr_add_handlers(s->chr,
-  serial_can_receive, serial_receive,
-  serial_event, s);
+  serial_can_receive, serial_receive,
+  serial_event, s);
+}
 return 0;
 }
 
@@ -233,9 +238,9 @@ static void etraxfs_ser_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo etraxfs_ser_info = {
-.name  = "etraxfs,serial",
+.name  = TYPE_ETRAX_FS_SERIAL,
 .parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(struct etrax_serial),
+.instance_size = sizeof(ETRAXSerial),
 .class_init= etraxfs_ser_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 11/14] pl011: Rename pl011_state

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/pl011.c | 52 ++--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index ebec64f..e0f7071 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -10,7 +10,7 @@
 #include "hw/sysbus.h"
 #include "sysemu/char.h"
 
-typedef struct {
+typedef struct PL011State {
 SysBusDevice busdev;
 MemoryRegion iomem;
 uint32_t readbuff;
@@ -31,7 +31,7 @@ typedef struct {
 CharDriverState *chr;
 qemu_irq irq;
 const unsigned char *id;
-} pl011_state;
+} PL011State;
 
 #define PL011_INT_TX 0x20
 #define PL011_INT_RX 0x10
@@ -46,7 +46,7 @@ static const unsigned char pl011_id_arm[8] =
 static const unsigned char pl011_id_luminary[8] =
   { 0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1 };
 
-static void pl011_update(pl011_state *s)
+static void pl011_update(PL011State *s)
 {
 uint32_t flags;
 
@@ -57,7 +57,7 @@ static void pl011_update(pl011_state *s)
 static uint64_t pl011_read(void *opaque, hwaddr offset,
unsigned size)
 {
-pl011_state *s = (pl011_state *)opaque;
+PL011State *s = (PL011State *)opaque;
 uint32_t c;
 
 if (offset >= 0xfe0 && offset < 0x1000) {
@@ -113,7 +113,7 @@ static uint64_t pl011_read(void *opaque, hwaddr offset,
 }
 }
 
-static void pl011_set_read_trigger(pl011_state *s)
+static void pl011_set_read_trigger(PL011State *s)
 {
 #if 0
 /* The docs say the RX interrupt is triggered when the FIFO exceeds
@@ -130,7 +130,7 @@ static void pl011_set_read_trigger(pl011_state *s)
 static void pl011_write(void *opaque, hwaddr offset,
 uint64_t value, unsigned size)
 {
-pl011_state *s = (pl011_state *)opaque;
+PL011State *s = (PL011State *)opaque;
 unsigned char ch;
 
 switch (offset >> 2) {
@@ -191,7 +191,7 @@ static void pl011_write(void *opaque, hwaddr offset,
 
 static int pl011_can_receive(void *opaque)
 {
-pl011_state *s = (pl011_state *)opaque;
+PL011State *s = (PL011State *)opaque;
 
 if (s->lcr & 0x10)
 return s->read_count < 16;
@@ -201,7 +201,7 @@ static int pl011_can_receive(void *opaque)
 
 static void pl011_put_fifo(void *opaque, uint32_t value)
 {
-pl011_state *s = (pl011_state *)opaque;
+PL011State *s = (PL011State *)opaque;
 int slot;
 
 slot = s->read_pos + s->read_count;
@@ -242,28 +242,28 @@ static const VMStateDescription vmstate_pl011 = {
 .minimum_version_id = 1,
 .minimum_version_id_old = 1,
 .fields  = (VMStateField[]) {
-VMSTATE_UINT32(readbuff, pl011_state),
-VMSTATE_UINT32(flags, pl011_state),
-VMSTATE_UINT32(lcr, pl011_state),
-VMSTATE_UINT32(cr, pl011_state),
-VMSTATE_UINT32(dmacr, pl011_state),
-VMSTATE_UINT32(int_enabled, pl011_state),
-VMSTATE_UINT32(int_level, pl011_state),
-VMSTATE_UINT32_ARRAY(read_fifo, pl011_state, 16),
-VMSTATE_UINT32(ilpr, pl011_state),
-VMSTATE_UINT32(ibrd, pl011_state),
-VMSTATE_UINT32(fbrd, pl011_state),
-VMSTATE_UINT32(ifl, pl011_state),
-VMSTATE_INT32(read_pos, pl011_state),
-VMSTATE_INT32(read_count, pl011_state),
-VMSTATE_INT32(read_trigger, pl011_state),
+VMSTATE_UINT32(readbuff, PL011State),
+VMSTATE_UINT32(flags, PL011State),
+VMSTATE_UINT32(lcr, PL011State),
+VMSTATE_UINT32(cr, PL011State),
+VMSTATE_UINT32(dmacr, PL011State),
+VMSTATE_UINT32(int_enabled, PL011State),
+VMSTATE_UINT32(int_level, PL011State),
+VMSTATE_UINT32_ARRAY(read_fifo, PL011State, 16),
+VMSTATE_UINT32(ilpr, PL011State),
+VMSTATE_UINT32(ibrd, PL011State),
+VMSTATE_UINT32(fbrd, PL011State),
+VMSTATE_UINT32(ifl, PL011State),
+VMSTATE_INT32(read_pos, PL011State),
+VMSTATE_INT32(read_count, PL011State),
+VMSTATE_INT32(read_trigger, PL011State),
 VMSTATE_END_OF_LIST()
 }
 };
 
 static int pl011_init(SysBusDevice *dev, const unsigned char *id)
 {
-pl011_state *s = FROM_SYSBUS(pl011_state, dev);
+PL011State *s = FROM_SYSBUS(PL011State, dev);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &pl011_ops, s, "pl011", 
0x1000);
 sysbus_init_mmio(dev, &s->iomem);
@@ -303,7 +303,7 @@ static void pl011_arm_class_init(ObjectClass *klass, void 
*data)
 static const TypeInfo pl011_arm_info = {
 .name  = "pl011",
 .parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(pl011_state),
+.instance_size = sizeof(PL011State),
 .class_init= pl011_arm_class_init,
 };
 
@@ -317,7 +317,7 @@ static void pl011_luminary_class_init(ObjectClass *klass, 
void *data)
 static const TypeInfo pl011_luminary_info = {
 .name  = "pl011_luminary",
 .parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(pl011_state),
+.instance_size = sizeof(PL011State),
 .class_init= pl011_lumina

[Qemu-devel] [PATCH qom-next for-1.6 05/14] grlib_apbuart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/grlib_apbuart.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index 82e1b95..35ef661 100644
--- a/hw/char/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
@@ -67,8 +67,13 @@
 
 #define FIFO_LENGTH 1024
 
+#define TYPE_GRLIB_APB_UART "grlib,apbuart"
+#define GRLIB_APB_UART(obj) \
+OBJECT_CHECK(UART, (obj), TYPE_GRLIB_APB_UART)
+
 typedef struct UART {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 qemu_irq irq;
 
@@ -232,7 +237,7 @@ static const MemoryRegionOps grlib_apbuart_ops = {
 
 static int grlib_apbuart_init(SysBusDevice *dev)
 {
-UART *uart = FROM_SYSBUS(typeof(*uart), dev);
+UART *uart = GRLIB_APB_UART(dev);
 
 qemu_chr_add_handlers(uart->chr,
   grlib_apbuart_can_receive,
@@ -252,7 +257,7 @@ static int grlib_apbuart_init(SysBusDevice *dev)
 
 static void grlib_apbuart_reset(DeviceState *d)
 {
-UART *uart = container_of(d, UART, busdev.qdev);
+UART *uart = GRLIB_APB_UART(d);
 
 /* Transmitter FIFO and shift registers are always empty in QEMU */
 uart->status =  UART_TRANSMIT_FIFO_EMPTY | UART_TRANSMIT_SHIFT_EMPTY;
@@ -279,7 +284,7 @@ static void grlib_apbuart_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo grlib_apbuart_info = {
-.name  = "grlib,apbuart",
+.name  = TYPE_GRLIB_APB_UART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(UART),
 .class_init= grlib_apbuart_class_init,
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 12/14] pl011: QOM'ify pl011 and pl011_luminary

2013-07-24 Thread Andreas Färber
Let the Luminary variant inherit from the ARM one, overwriting its ID on
instance_init. Introduce type constant and use QOM casts. Replace
triplicated SysBusDevice initfn with QOM realizefn and instance_init.

Signed-off-by: Andreas Färber 
---
 hw/char/pl011.c | 62 +
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index e0f7071..a8ae6f4 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -10,8 +10,12 @@
 #include "hw/sysbus.h"
 #include "sysemu/char.h"
 
+#define TYPE_PL011 "pl011"
+#define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)
+
 typedef struct PL011State {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 uint32_t readbuff;
 uint32_t flags;
@@ -261,64 +265,62 @@ static const VMStateDescription vmstate_pl011 = {
 }
 };
 
-static int pl011_init(SysBusDevice *dev, const unsigned char *id)
+static void pl011_init(Object *obj)
 {
-PL011State *s = FROM_SYSBUS(PL011State, dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+PL011State *s = PL011(obj);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &pl011_ops, s, "pl011", 
0x1000);
-sysbus_init_mmio(dev, &s->iomem);
-sysbus_init_irq(dev, &s->irq);
-s->id = id;
-s->chr = qemu_char_get_next_serial();
+sysbus_init_mmio(sbd, &s->iomem);
+sysbus_init_irq(sbd, &s->irq);
 
 s->read_trigger = 1;
 s->ifl = 0x12;
 s->cr = 0x300;
 s->flags = 0x90;
-if (s->chr) {
-qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
-  pl011_event, s);
-}
-vmstate_register(&dev->qdev, -1, &vmstate_pl011, s);
-return 0;
-}
 
-static int pl011_arm_init(SysBusDevice *dev)
-{
-return pl011_init(dev, pl011_id_arm);
+s->id = pl011_id_arm;
 }
 
-static int pl011_luminary_init(SysBusDevice *dev)
+static void pl011_realize(DeviceState *dev, Error **errp)
 {
-return pl011_init(dev, pl011_id_luminary);
+PL011State *s = PL011(dev);
+
+s->chr = qemu_char_get_next_serial();
+
+if (s->chr) {
+qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
+  pl011_event, s);
+}
 }
 
-static void pl011_arm_class_init(ObjectClass *klass, void *data)
+static void pl011_class_init(ObjectClass *oc, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(oc);
 
-sdc->init = pl011_arm_init;
+dc->realize = pl011_realize;
+dc->vmsd = &vmstate_pl011;
 }
 
 static const TypeInfo pl011_arm_info = {
-.name  = "pl011",
+.name  = TYPE_PL011,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(PL011State),
-.class_init= pl011_arm_class_init,
+.instance_init = pl011_init,
+.class_init= pl011_class_init,
 };
 
-static void pl011_luminary_class_init(ObjectClass *klass, void *data)
+static void pl011_luminary_init(Object *obj)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+PL011State *s = PL011(obj);
 
-sdc->init = pl011_luminary_init;
+s->id = pl011_id_luminary;
 }
 
 static const TypeInfo pl011_luminary_info = {
 .name  = "pl011_luminary",
-.parent= TYPE_SYS_BUS_DEVICE,
-.instance_size = sizeof(PL011State),
-.class_init= pl011_luminary_class_init,
+.parent= TYPE_PL011,
+.instance_init = pl011_luminary_init,
 };
 
 static void pl011_register_types(void)
-- 
1.8.1.4




[Qemu-devel] [PATCH qom-next for-1.6 01/14] cadence_uart: QOM'ify

2013-07-24 Thread Andreas Färber
Signed-off-by: Andreas Färber 
---
 hw/char/cadence_uart.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 4d457f8..3c2e960 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -106,8 +106,12 @@
 
 #define R_MAX (R_TTRIG + 1)
 
+#define TYPE_CADENCE_UART "cadence_uart"
+#define CADENCE_UART(obj) OBJECT_CHECK(UartState, (obj), TYPE_CADENCE_UART)
+
 typedef struct {
-SysBusDevice busdev;
+SysBusDevice parent_obj;
+
 MemoryRegion iomem;
 uint32_t r[R_MAX];
 uint8_t r_fifo[RX_FIFO_SIZE];
@@ -442,7 +446,7 @@ static void cadence_uart_reset(UartState *s)
 
 static int cadence_uart_init(SysBusDevice *dev)
 {
-UartState *s = FROM_SYSBUS(UartState, dev);
+UartState *s = CADENCE_UART(dev);
 
 memory_region_init_io(&s->iomem, OBJECT(s), &uart_ops, s, "uart", 0x1000);
 sysbus_init_mmio(dev, &s->iomem);
@@ -504,7 +508,7 @@ static void cadence_uart_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo cadence_uart_info = {
-.name  = "cadence_uart",
+.name  = TYPE_CADENCE_UART,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(UartState),
 .class_init= cadence_uart_class_init,
-- 
1.8.1.4




Re: [Qemu-devel] [libvirt] [PATCH] caps: use -device for primary video when qemu >=1.6

2013-07-24 Thread Eric Blake
[adding qemu-devel]

On 07/24/2013 03:41 AM, Guannan Ren wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=981094
> The commit 0ad9025ef introduce qemu flag QEMU_CAPS_DEVICE_VIDEO_PRIMARY
> for using -device VGA, -device cirrus-vga, -device vmware-svga and
> -device qxl-vga. In use, for -device qxl-vga, mouse doesn't display
> in guest window like the desciption in above bug.

s/desciption/description/

As someone that was hit by the qemu bug of no mouse cursor display on a
qxl guest, I'm more than willing to agree to this patch.  Upstream qemu
has a patch in their queue to fix the qxl mouse display bug for qemu 1.6.

> This patch try to use -device for primary video when qemu >=1.6 which
> is safe.
> ---
>  src/qemu/qemu_capabilities.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

ACK.  I hate hard-coded version checks for capability bits, but don't
know if we can do any better.  It would be nice if we had some other
capability bit that we could query in QMP to know for certain whether
'-device qxl-vga' properly works without eating the mouse cursor.

> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 5dc3c9e..08406b8 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -1189,8 +1189,6 @@ virQEMUCapsComputeCmdFlags(const char *help,
>  virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
>  }
>  
> -if (version >= 1002000)
> -virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
>  return 0;
>  }
>  
> @@ -2424,7 +2422,6 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
>  virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
>  virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
>  virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
> -virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
>  }
>  
>  /* Capabilities that are architecture depending
> @@ -2597,6 +2594,9 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
>  if (qemuCaps->version >= 1003001)
>  virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET);
>  
> +if (qemuCaps->version >= 1006000)
> +virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
> +
>  if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0)
>  goto cleanup;
>  if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0)
> 

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH V6 1/3] Implement sync modes for drive-backup.

2013-07-24 Thread Eric Blake
On 07/24/2013 04:55 AM, Kevin Wolf wrote:

> Unconditionally overriding format for NEW_IMAGE_MODE_EXISTING is
> definitely wrong. It's the user's choice which COW format to use for the
> backup image. There's no reason why it has to be the same format as the
> image that is being backed up.
> 
> Before, bs->drv->format_name was a default for the case where a new
> image had to be created and no format was given; and the format of
> existing images could be probed. This is still what makes most sense to
> me. What's even the goal with this change?

Furthermore, I'm proposing that for 1.6, we should make the format
argument mandatory for drive-backup.  We made it optional for
drive-mirror, to allow for probing, but there have been CVEs in the past
due to probing of a raw file gone wrong.  We can always relax a
mandatory argument into an optional one in 1.7, if we decide that
probing can be done safely, but we can never turn an optional argument
into a mandatory one once the initial release bakes in the option.  It
would make the code a lot simpler to just have a mandatory format
argument, instead of having to bake in and document hueristics on which
format is picked when the caller doesn't provide one.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] VM can not boot after commit 235e898

2013-07-24 Thread Andreas Färber
Am 24.07.2013 18:53, schrieb Gleb Natapov:
> What happens on upstream kernel
> (works for me obviously :)).

3.10.x has been working fine for me on openSUSE 12.3.

Andreas

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



Re: [Qemu-devel] VM can not boot after commit 235e898

2013-07-24 Thread Alexander Graf

On 07/24/2013 06:53 PM, Gleb Natapov wrote:

On Wed, Jul 24, 2013 at 06:26:41PM +0200, Alexander Graf wrote:

before. Are you saying configuring BIOS memslot differently solves the
problem?

Git bisect pointed to the commit mentioned in this email. The
following patch also gets me a working guest again:

diff --git a/kvm-all.c b/kvm-all.c
index 4fb4ccb..deca9e5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1455,7 +1455,7 @@ int kvm_init(void)
  s->irq_set_ioctl = KVM_IRQ_LINE_STATUS;
  }

-#ifdef KVM_CAP_READONLY_MEM
+#if 0 //def KVM_CAP_READONLY_MEM
  kvm_readonly_mem_allowed =
  (kvm_check_extension(s, KVM_CAP_READONLY_MEM)>  0);
  #endif


Can you disable emulate_invalid_state on 3.7?


I could only find emulate_invalid_guest_state. I suppose you mean that 
one? :)


$ rmmod kvm-intel
$ modprobe kvm-intel emulate_invalid_guest_state=n
$ ./x86_64-softmmu/qemu-system-x86_64 -nographic -kernel /boot/vmlinuz 
-append console=ttyS0 -bios pc-bios/bios.bin -enable-kvm

QEMU 1.5.50 monitor - type 'help' for more information
(qemu)
KVM: entry failed, hardware error 0x8021

If you're running a guest on an Intel machine without unrestricted mode
support, the failure can be most likely due to the guest entering an invalid
state for Intel VT. For example, the guest maybe running in big real mode
which is not supported on less recent Intel processors.

EAX=0011 EBX=18ae1000 ECX=6a12 EDX=000fffa9
ESI=07feb50d EDI= EBP=69d2 ESP=69d2
EIP=c489 EFL=00010006 [-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =fd39 000fd390  00809300 DPL=0 DS16 [-WA]
CS =f000 000f  9b00 DPL=0 CS16 [-RA]
SS =   9300 DPL=0 DS16 [-WA]
DS =0030   00809300 DPL=0 DS16 [-WA]
FS =0030   00809300 DPL=0 DS16 [-WA]
GS =c900 000c9000  00809300 DPL=0 DS16 [-WA]
LDT=   8200 DPL=0 LDT
TR =   8b00 DPL=0 TSS32-busy
GDT= 000fd3a8 0037
IDT= 000fd3e6 
CR0=0011 CR2= CR3= CR4=
DR0= DR1= DR2= 
DR3=

DR6=0ff0 DR7=0400
EFER=
Code=01 1e e0 d3 2e 0f 01 16 a0 d3 0f 20 c0 66 83 c8 01 0f 22 c0 <66> ea 
91 c4 0f 00 08 00 b8 10 00 00 00 8e d8 8e c0 8e d0 8e e0 8e e8 89 c8 ff 
e2 89 c1 b8

QEMU: Terminated



What happens on upstream kernel
(works for me obviously :)).


kvm-kmod from 3.9 works.


Alex




Re: [Qemu-devel] [PATCH 6/9] PlatBus: Add serial-platbus device

2013-07-24 Thread Peter Maydell
On 24 July 2013 21:16, Scott Wood  wrote:
> Plus, it's nice to have debug output from early on, rather than having to
> wait until PCI is up and running.

It would be nice if the device tree had bindings for
"you can find your emergency serial port here"...

-- PMM



Re: [Qemu-devel] [PATCH 6/9] PlatBus: Add serial-platbus device

2013-07-24 Thread Scott Wood

On 07/22/2013 01:56:32 PM, Alexander Graf wrote:


On 22.07.2013, at 20:26, Peter Maydell wrote:

> On 22 July 2013 18:50, Alexander Graf  wrote:
>> We want to be able to spawn a serial console on the platform bus.  
Create

>> a small platbus wrapper device very similar to the ISA one.
>
> Why not use virtio-console?

Because eventually we want -nodefaults not generate any UARTs and  
only create them through -device. Guests expect /dev/ttySx device  
nodes for their serial ports.


Plus, it's nice to have debug output from early on, rather than having  
to wait until PCI is up and running.


-Scott



[Qemu-devel] [PATCH 1/2] alpha-linux-user: Fix umount syscall numbers

2013-07-24 Thread Richard Henderson
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 
---
 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 00a0390..e42c20e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5719,7 +5719,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.3.1




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

2013-07-24 Thread Richard Henderson
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 
---
 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 f6a3aad..450520a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1813,7 +1813,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 */
@@ -1843,7 +1843,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.3.1




Re: [Qemu-devel] [RFC] [PATCH] linux-user: implement m68k atomic syscalls

2013-07-24 Thread Richard Henderson
On 07/23/2013 09:10 PM, riku.voi...@linaro.org wrote:
> +#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))
> +ret = -TARGET_EFAULT;
> +if (mem_value == arg2)
> +put_user_u32(arg1, arg6);
> +ret = mem_value;
> +break;
> +}

The ret = -TARGET_FAULT doesn't do anything useful
without an associated break.

The kernel queues the expected SIGSEGV for this sort
of failure.  Would that happen here?


r~





Re: [Qemu-devel] APM regression since v1.3.0-408-g9ee59f3

2013-07-24 Thread Sebastian Herbszt

Gerd Hoffmann wrote:

On 07/03/13 22:25, Sebastian Herbszt wrote:

Commit 9ee59f3 ("pc: remove bochs bios debug ports") broke the APM
interface
between QEMU and Bochs BIOS/SeaBIOS. Without APM support older guests
are no longer able to power off the VM. This regression also affects
older machine
types like pc-1.2.


--verbose please.  Which guest?  Which firmware?


The guest is syslinux. Its poweroff module [1] uses the APM interface.
I'am also no longer able to power off linux (2.6.20) with acpi=off.

Firmware is SeaBIOS 1.7.2.


ACPI poweroff with seabios works just fine.  If APM support in seabios
uses something else it should be switched to use the same hardware ports
ACPI uses for poweroff (some piix4 pm device register I think) instead
of the debug ports which where never meant to be used that way.


SeaBIOS uses the same QEMU / BIOS interface as Bochs BIOS (port 0x8900).
This interface was removed by commit 9ee59f3.


Does bochs bios run on recent qemu versions in the first place?


Last time I checked it did, but "recent" is relative.

[1] http://www.syslinux.org/archives/2013-July/020367.html

Sebastian




Re: [Qemu-devel] [libvirt] [PATCH 4/7] qemu: Add monitor APIs to fetch CPUID data from QEMU

2013-07-24 Thread Eduardo Habkost
On Wed, Jul 24, 2013 at 11:03:03AM +0100, Daniel P. Berrange wrote:
> On Tue, Jul 23, 2013 at 07:28:38PM +0200, Jiri Denemark wrote:
> > On Tue, Jul 23, 2013 at 17:32:42 +0100, Daniel Berrange wrote:
> > > On Tue, Jul 23, 2013 at 06:11:33PM +0200, Jiri Denemark wrote:
> > > > ---
> > > >  src/qemu/qemu_monitor.c|  21 +++
> > > >  src/qemu/qemu_monitor.h|   3 +
> > > >  src/qemu/qemu_monitor_json.c   | 162 
> > > > +
> > > >  src/qemu/qemu_monitor_json.h   |   6 +
> > > >  tests/Makefile.am  |   1 +
> > > >  .../qemumonitorjson-getcpu-empty.data  |   2 +
> > > >  .../qemumonitorjson-getcpu-empty.json  |  46 ++
> > > >  .../qemumonitorjson-getcpu-filtered.data   |   4 +
> > > >  .../qemumonitorjson-getcpu-filtered.json   |  46 ++
> > > >  .../qemumonitorjson-getcpu-full.data   |   4 +
> > > >  .../qemumonitorjson-getcpu-full.json   |  46 ++
> > > >  .../qemumonitorjson-getcpu-host.data   |   5 +
> > > >  .../qemumonitorjson-getcpu-host.json   |  45 ++
> > > >  tests/qemumonitorjsontest.c|  74 ++
> > > >  14 files changed, 465 insertions(+)
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.json
> > > 
> > > ACK, though I believe the design of this monitor API is flawed
> > > because it requires you to re-launch QEMU with different accel
> > > args
> > 
> > Not really, this can be used in tcg too. It's just when we want to get
> > the data for "host" CPU, we need to enable kvm as tcg knows nothing
> > about that CPU. Which makes sense as kvm (the kernel module) influences
> > how the "host" CPU will look like.
> 
> Is there no ioctl() for the KVM module we can just invoke directly to
> discover what CPU flag filtering it will perform. Presumably QEMU is
> using some ioctl to discover this, so libvirt ought to be able to
> too.
> 

Yes, there is: GET_SUPPORTED_CPUID. But availability of some features
may depend on QEMU capabilities as well. On those cases libvirt may need
to combine the GET_SUPPORTED_CPUID results with what it knows about QEMU
capabilities. But this should work as long as we report and document
QEMU capabilities/options that affect CPU features very clearly.

That may be an appropriate way to go to, if you don't mind having
low-level KVM ioctl() code inside libvirt, that duplicates some QEMU
logic.

(But we still have the problem of querying/reporting CPU feature details
that depend on machine-type+CPU-model [that is not addressed by this
series yet]. See my previous message about it)

-- 
Eduardo



Re: [Qemu-devel] [libvirt] [PATCH 4/7] qemu: Add monitor APIs to fetch CPUID data from QEMU

2013-07-24 Thread Eduardo Habkost
On Tue, Jul 23, 2013 at 07:32:46PM +0200, Jiri Denemark wrote:
> On Tue, Jul 23, 2013 at 19:28:38 +0200, Jiri Denemark wrote:
> > On Tue, Jul 23, 2013 at 17:32:42 +0100, Daniel Berrange wrote:
> > > On Tue, Jul 23, 2013 at 06:11:33PM +0200, Jiri Denemark wrote:
> > > > ---
> > > >  src/qemu/qemu_monitor.c|  21 +++
> > > >  src/qemu/qemu_monitor.h|   3 +
> > > >  src/qemu/qemu_monitor_json.c   | 162 
> > > > +
> > > >  src/qemu/qemu_monitor_json.h   |   6 +
> > > >  tests/Makefile.am  |   1 +
> > > >  .../qemumonitorjson-getcpu-empty.data  |   2 +
> > > >  .../qemumonitorjson-getcpu-empty.json  |  46 ++
> > > >  .../qemumonitorjson-getcpu-filtered.data   |   4 +
> > > >  .../qemumonitorjson-getcpu-filtered.json   |  46 ++
> > > >  .../qemumonitorjson-getcpu-full.data   |   4 +
> > > >  .../qemumonitorjson-getcpu-full.json   |  46 ++
> > > >  .../qemumonitorjson-getcpu-host.data   |   5 +
> > > >  .../qemumonitorjson-getcpu-host.json   |  45 ++
> > > >  tests/qemumonitorjsontest.c|  74 ++
> > > >  14 files changed, 465 insertions(+)
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.json
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.data
> > > >  create mode 100644 
> > > > tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.json
> > > 
> > > ACK, though I believe the design of this monitor API is flawed
> > > because it requires you to re-launch QEMU with different accel
> > > args
> > 
> > Not really, this can be used in tcg too. It's just when we want to get
> > the data for "host" CPU, we need to enable kvm as tcg knows nothing
> > about that CPU. Which makes sense as kvm (the kernel module) influences
> > how the "host" CPU will look like.
> 
> However, you need to have a CPU to be able to ask for his properties
> (which kinda makes sense too) and for that you also need a machine with
> type != none. Which makes sense too, as the CPU may differ depending on
> machine type (which, however, does not happen for "host" CPU).

In addition to the "-cpu host" KVM initialization problem, this is an
additional problem with the current interfaces provided by QEMU:

1) libvirt needs to query data that depend on chosen machine-type and
   CPU model
2) Some machine-type behavior is code and not introspectable data
   * Luckily most of the data we need in this case should/will be
 encoded in the compat_props tables.
   * In either case, we don't have an API to query for machine-type
 compat_props information yet.
3) CPU model behavior will be modelled as CPU class behavior. Like
   on the machine-type case, some of the CPU-model-specific behavior may
   be modelled as code, and not introspectable data.
   * However, e may be able to eventually encode most or all of
 CPU-model-specific behavior simply as different per-CPU-class
 property defaults.
   * In either case, we don't have an API for QOM class introspection,
 yet.

But there's something important in this case: the resulting CPUID data
for a specific machine-type + CPU-model combination must be always the
same, forever. This means libvirt may even use a static table, or cache
this information indefinitely.

(Note that I am not talking about "-cpu host", here, but about all the
other CPU models)

-- 
Eduardo



Re: [Qemu-devel] [libvirt] [PATCH 6/7] qemu: Probe QEMU binary for host CPU

2013-07-24 Thread Eduardo Habkost
On Tue, Jul 23, 2013 at 05:19:03PM +0100, Daniel P. Berrange wrote:
> On Tue, Jul 23, 2013 at 06:11:35PM +0200, Jiri Denemark wrote:
> > Since QEMU and kvm may filter some host CPU features or add efficiently
> > emulated features, asking QEMU binary for host CPU data provides
> > better results when we later use the data for building guest CPUs.
> > ---
> >  src/qemu/qemu_capabilities.c | 44 
> > +++-
> >  src/qemu/qemu_capabilities.h |  2 ++
> >  2 files changed, 45 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> > index 9440396..d46a059 100644
> > --- a/src/qemu/qemu_capabilities.c
> > +++ b/src/qemu/qemu_capabilities.c
> > @@ -253,6 +253,7 @@ struct _virQEMUCaps {
> >  
> >  size_t ncpuDefinitions;
> >  char **cpuDefinitions;
> > +virCPUDefPtr hostCPU;
> >  
> >  size_t nmachineTypes;
> >  char **machineTypes;
> > @@ -1757,6 +1758,9 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr 
> > qemuCaps)
> >  goto error;
> >  }
> >  
> > +if (!(ret->hostCPU = virCPUDefCopy(qemuCaps->hostCPU)))
> > +goto error;
> > +
> >  if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
> >  goto error;
> >  if (VIR_ALLOC_N(ret->machineAliases, qemuCaps->nmachineTypes) < 0)
> > @@ -1796,6 +1800,7 @@ void virQEMUCapsDispose(void *obj)
> >  VIR_FREE(qemuCaps->cpuDefinitions[i]);
> >  }
> >  VIR_FREE(qemuCaps->cpuDefinitions);
> > +virCPUDefFree(qemuCaps->hostCPU);
> >  
> >  virBitmapFree(qemuCaps->flags);
> >  
> > @@ -2485,7 +2490,6 @@ virQEMUCapsInitQMPCommandNew(const char *binary,
> > "-no-user-config",
> > "-nodefaults",
> > "-nographic",
> > -   "-M", "none",
> > "-qmp", monitor,
> > "-pidfile", pidfile,
> > "-daemonize",
> > @@ -2617,6 +2621,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
> >  
> >  cmd = virQEMUCapsInitQMPCommandNew(qemuCaps->binary, monarg, pidfile,
> > runUid, runGid);
> > +virCommandAddArgList(cmd, "-M", "none", NULL);
> >  
> >  if ((ret = virQEMUCapsInitQMPCommandRun(cmd, qemuCaps->binary, pidfile,
> >  &config, &mon, &pid)) < 0) {
> > @@ -2679,6 +2684,37 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
> >  if (virQEMUCapsProbeQMPCommandLine(qemuCaps, mon) < 0)
> >  goto cleanup;
> >  
> > +if ((qemuCaps->arch == VIR_ARCH_I686 ||
> > + qemuCaps->arch == VIR_ARCH_X86_64) &&
> > +(virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) ||
> > + virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM)) &&
> > +virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_HOST) &&
> > +qemuCaps->nmachineTypes) {
> > +virQEMUCapsInitQMPCommandAbort(&cmd, &mon, &pid, pidfile);
> > +
> > +VIR_DEBUG("Checking host CPU data provided by %s", 
> > qemuCaps->binary);
> > +cmd = virQEMUCapsInitQMPCommandNew(qemuCaps->binary, monarg, 
> > pidfile,
> > +   runUid, runGid);
> > +virCommandAddArgList(cmd, "-cpu", "host", NULL);
> > +/* -cpu host gives the same CPU for all machine types so we just
> > + * use the first one when probing
> > + */
> > +virCommandAddArg(cmd, "-machine");
> > +virCommandAddArgFormat(cmd, "%s,accel=kvm",
> > +   qemuCaps->machineTypes[0]);
> > +
> > +if (virQEMUCapsInitQMPCommandRun(cmd, qemuCaps->binary, pidfile,
> > + &config, &mon, &pid) < 0)
> > +goto cleanup;
> > +
> > +qemuCaps->hostCPU = qemuMonitorGetCPU(mon, qemuCaps->arch);
> > +if (qemuCaps->hostCPU) {
> > +char *cpu = virCPUDefFormat(qemuCaps->hostCPU, 0);
> > +VIR_DEBUG("Host CPU reported by %s: %s", qemuCaps->binary, 
> > cpu);
> > +VIR_FREE(cpu);
> > +}
> > +}
> 
> 
> This code is causing us to invoke the QEMU binary multiple times,
> which is something we worked really hard to get away from. I really,
> really don't like this as an approach. QEMU needs to be able to
> give us the data we need here without multiple invocations.
> 
> eg, by allowing the monitor command to specify 'kvm' vs 'qemu'
> when asking for data, so you can interrogate it without having
> to re-launch it with different accel=XXX args.

The specific information libvirt requires here depend on KVM being
initialized, and QEMU code/interfaces currently assume that: 1) there's
only 1 machine being initialized, and it is initialized very early; 2)
there's only one accelerator being initialized, and it is initialized
very early.

I have no idea how long it will take for QEMU to

Re: [Qemu-devel] [PATCH V6 2/3] Add tests for sync modes 'TOP' and 'NONE'

2013-07-24 Thread Ian Main
On Wed, Jul 24, 2013 at 01:19:18PM +0200, Kevin Wolf wrote:
> Am 23.07.2013 um 00:09 hat Ian Main geschrieben:
> > This patch adds tests for sync modes top and none.  Also added are tests
> > for invalid and missing formats.
> > 
> > Signed-off-by: Ian Main 
> > ---
> >  tests/qemu-iotests/055| 108 
> > +-
> >  tests/qemu-iotests/055.out|   4 +-
> >  tests/qemu-iotests/group  |   2 +-
> >  tests/qemu-iotests/iotests.py |   5 ++
> >  4 files changed, 103 insertions(+), 16 deletions(-)
> 
> > @@ -127,7 +202,8 @@ class TestSetSpeed(iotests.QMPTestCase):
> >  self.assert_qmp(result, 'return[0]/device', 'drive0')
> >  self.assert_qmp(result, 'return[0]/speed', 0)
> >  
> > -result = self.vm.qmp('block-job-set-speed', device='drive0', 
> > speed=8 * 1024 * 1024)
> > +result = self.vm.qmp('block-job-set-speed', device='drive0',
> > + speed=8 * 1024 * 1024)
> 
> Forgot adding sync?

Sync defaults to FULL which I think is intended here.  IIRC it was just
a long line fix.
 
> >  self.assert_qmp(result, 'return', {})
> >  
> >  # Ensure the speed we set was accepted
> 
> > @@ -285,4 +367,4 @@ class TestSingleTransaction(iotests.QMPTestCase):
> >  self.assert_no_active_block_jobs()
> >  
> >  if __name__ == '__main__':
> > -iotests.main(supported_fmts=['raw', 'qcow2'])
> > +iotests.main(supported_fmts=['qcow2', 'qed'])
> 
> Not good. Can we split the test in a part that can be run by raw, and a
> separate part that uses backing files?

If that is what is needed, sure.

Ian

> Kevin



Re: [Qemu-devel] [PATCH] seccomp: add additional asynchronous I/O syscalls

2013-07-24 Thread Eduardo Otubo



On 07/23/2013 10:57 AM, Paul Moore wrote:

On Monday, July 15, 2013 03:32:01 PM Paul Moore wrote:

A previous commit, "seccomp: add the asynchronous I/O syscalls to the
whitelist", added several asynchronous I/O syscalls but left out the
io_submit() and io_cancel() syscalls.  This patch corrects this by
adding the two missing asynchronous I/O syscalls.

Signed-off-by: Paul Moore 


A gentle nudge so this fix doesn't get forgotten.


Reviewed and tested.

Reviewed-by: Eduardo Otubo 




---
  qemu-seccomp.c |2 ++
  1 file changed, 2 insertions(+)

diff --git a/qemu-seccomp.c b/qemu-seccomp.c
index ca123bf..173d185 100644
--- a/qemu-seccomp.c
+++ b/qemu-seccomp.c
@@ -33,6 +33,7 @@ static const struct QemuSeccompSyscall seccomp_whitelist[]
= { { SCMP_SYS(socketcall), 250 },
  #endif
  { SCMP_SYS(read), 249 },
+{ SCMP_SYS(io_submit), 249 },
  { SCMP_SYS(brk), 248 },
  { SCMP_SYS(clone), 247 },
  { SCMP_SYS(mmap), 247 },
@@ -231,6 +232,7 @@ static const struct QemuSeccompSyscall
seccomp_whitelist[] = { { SCMP_SYS(recvmmsg), 241 },
  { SCMP_SYS(prlimit64), 241 },
  { SCMP_SYS(waitid), 241 },
+{ SCMP_SYS(io_cancel), 241 },
  { SCMP_SYS(io_setup), 241 },
  { SCMP_SYS(io_destroy), 241 }
  };


--
Eduardo Otubo
IBM Linux Technology Center




Re: [Qemu-devel] [PATCH] seccomp: add arch_prctl() to the syscall whitelist

2013-07-24 Thread Eduardo Otubo



On 07/23/2013 10:57 AM, Paul Moore wrote:

On Thursday, July 18, 2013 09:57:03 AM Paul Moore wrote:

It appears that even a very simple /etc/qemu-ifup configuration can
require the arch_prctl() syscall, see the example below:

#!/bin/sh
/sbin/ifconfig $1 0.0.0.0 up
/usr/sbin/brctl addif  $1

Signed-off-by: Paul Moore 


As with the other fix, a gentle nudge so this isn't forgotten.


Reviewed and tested.

Reviewed-by: Eduardo Otubo 




---
  qemu-seccomp.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/qemu-seccomp.c b/qemu-seccomp.c
index 173d185..9e91c73 100644
--- a/qemu-seccomp.c
+++ b/qemu-seccomp.c
@@ -234,7 +234,8 @@ static const struct QemuSeccompSyscall
seccomp_whitelist[] = { { SCMP_SYS(waitid), 241 },
  { SCMP_SYS(io_cancel), 241 },
  { SCMP_SYS(io_setup), 241 },
-{ SCMP_SYS(io_destroy), 241 }
+{ SCMP_SYS(io_destroy), 241 },
+{ SCMP_SYS(arch_prctl), 240 }
  };

  int seccomp_start(void)


--
Eduardo Otubo
IBM Linux Technology Center




[Qemu-devel] [PATCH 9/9] block: vhdx write support

2013-07-24 Thread Jeff Cody
This adds support for writing to VHDX image files, using coroutines.
Writes into the BAT table goes through the VHDX log.  Currently, BAT
table writes occur when expanding a dynamic VHDX file, and allocating a
new BAT entry.

Signed-off-by: Jeff Cody 
---
 block/vhdx.c | 149 ++-
 1 file changed, 147 insertions(+), 2 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index a8dd6d7..791c6dc 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -831,7 +831,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, 
int flags)
 vhdx_update_headers(bs, s, false, NULL);
 }
 
-/* TODO: differencing files, write */
+/* TODO: differencing files */
 
 return 0;
 fail:
@@ -963,7 +963,45 @@ exit:
 return ret;
 }
 
+/*
+ * Allocate a new payload block at the end of the file.
+ *
+ * Allocation will happen at 1MB alignment inside the file
+ *
+ * Returns the file offset start of the new payload block
+ */
+static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
+uint64_t *new_offset)
+{
+*new_offset = bdrv_getlength(bs->file);
 
+/* per the spec, the address for a block is in units of 1MB */
+if (*new_offset % (1024*1024)) {
+*new_offset = ((*new_offset >> 20) + 1) << 20;  /* round up to 1MB */
+}
+
+return bdrv_truncate(bs->file, *new_offset + s->block_size);
+}
+
+/*
+ * Update the BAT tablet entry with the new file offset, and the new entry
+ * state */
+static void vhdx_update_bat_table_entry(BlockDriverState *bs, BDRVVHDXState *s,
+   VHDXSectorInfo *sinfo,
+   uint64_t *bat_entry,
+   uint64_t *bat_offset, int state)
+{
+/* The BAT entry is a uint64, with 44 bits for the file offset in units of
+ * 1MB, and 3 bits for the block state. */
+s->bat[sinfo->bat_idx]  = ((sinfo->file_offset>>20) <<
+   VHDX_BAT_FILE_OFF_BITS);
+
+s->bat[sinfo->bat_idx] |= state & VHDX_BAT_STATE_BIT_MASK;
+
+*bat_entry = cpu_to_le64(s->bat[sinfo->bat_idx]);
+*bat_offset = s->bat_offset + sinfo->bat_idx * sizeof(VHDXBatEntry);
+
+}
 
 /* Per the spec, on the first write of guest-visible data to the file the
  * data write guid must be updated in the header */
@@ -978,7 +1016,114 @@ void vhdx_user_visible_write(BlockDriverState *bs, 
BDRVVHDXState *s)
 static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t 
sector_num,
   int nb_sectors, QEMUIOVector *qiov)
 {
-return -ENOTSUP;
+int ret = -ENOTSUP;
+BDRVVHDXState *s = bs->opaque;
+VHDXSectorInfo sinfo;
+uint64_t bytes_done = 0;
+uint64_t bat_entry = 0;
+uint64_t bat_entry_offset = 0;
+bool bat_update;
+QEMUIOVector hd_qiov;
+
+qemu_iovec_init(&hd_qiov, qiov->niov);
+
+qemu_co_mutex_lock(&s->lock);
+
+vhdx_user_visible_write(bs, s);
+
+while (nb_sectors > 0) {
+if (s->params.data_bits & VHDX_PARAMS_HAS_PARENT) {
+/* not supported yet */
+ret = -ENOTSUP;
+goto exit;
+} else {
+bat_update = false;
+vhdx_block_translate(s, sector_num, nb_sectors, &sinfo);
+
+qemu_iovec_reset(&hd_qiov);
+qemu_iovec_concat(&hd_qiov, qiov,  bytes_done, sinfo.bytes_avail);
+/* check the payload block state */
+switch (s->bat[sinfo.bat_idx] & VHDX_BAT_STATE_BIT_MASK) {
+case PAYLOAD_BLOCK_ZERO:
+/* in this case, we need to preserve zero writes for
+ * data that is not part of this write, so we must pad
+ * the rest of the buffer to zeroes */
+
+/* if we are on a posix system with ftruncate() that extends
+ * a file, then it is zero-filled for us.  On Win32, the raw
+ * layer uses SetFilePointer and SetFileEnd, which does not
+ * zero fill AFAIK */
+
+/* TODO: queue another write of zero buffers if the host OS 
does
+ * not zero-fill on file extension */
+
+/* fall through */
+case PAYLOAD_BLOCK_NOT_PRESENT: /* fall through */
+case PAYLOAD_BLOCK_UNMAPPED:/* fall through */
+case PAYLOAD_BLOCK_UNDEFINED:   /* fall through */
+ret = vhdx_allocate_block(bs, s, &sinfo.file_offset);
+if (ret < 0) {
+goto exit;
+}
+/* once we support differencing files, this may also be
+ * partially present */
+/* update block state to the newly specified state */
+vhdx_update_bat_table_entry(bs, s, &sinfo, &bat_entry,
+&bat_entry_offset,
+PAYLOAD_BLOCK_FULL_PRESENT);
+  

[Qemu-devel] [PATCH 8/9] block: vhdx - add log write support

2013-07-24 Thread Jeff Cody
This adds support for writing to the VHDX log.

For spec details, see VHDX Specification Format v1.00:
https://www.microsoft.com/en-us/download/details.aspx?id=34750

There are a few limitations to this log support:
1.) There is no caching yet
2.) The log is flushed after each entry

The primary write interface, vhdx_log_write_and_flush(), performs a log
write followed by an immediate flush of the log.

As each log entry sector is a minimum of 4KB, partial sector writes are
filled in with data from the disk write destination.

If the current file log GUID is 0, a new GUID is generated and updated
in the header.

Signed-off-by: Jeff Cody 
---
 block/vhdx-log.c | 273 +++
 block/vhdx.h |   3 +
 2 files changed, 276 insertions(+)

diff --git a/block/vhdx-log.c b/block/vhdx-log.c
index 89b9000..786b393 100644
--- a/block/vhdx-log.c
+++ b/block/vhdx-log.c
@@ -170,6 +170,53 @@ exit:
 return ret;
 }
 
+/* Writes num_sectors to the log (all log sectors are 4096 bytes),
+ * from buffer 'buffer'.  Upon return, *sectors_written will contain
+ * the number of sectors successfully written.
+ *
+ * It is assumed that 'buffer' is at least 4096*num_sectors large.
+ *
+ * 0 is returned on success, -errno otherwise */
+static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
+  uint32_t *sectors_written, void *buffer,
+  uint32_t num_sectors)
+{
+int ret = 0;
+uint64_t offset;
+uint32_t write;
+void *buffer_tmp;
+BDRVVHDXState *s = bs->opaque;
+
+vhdx_user_visible_write(bs, s);
+
+write = log->write;
+
+buffer_tmp = buffer;
+while (num_sectors) {
+
+offset = log->offset + write;
+write = vhdx_log_inc_idx(write, log->length);
+if (write == log->read) {
+/* full */
+break;
+}
+ret = bdrv_pwrite_sync(bs->file, offset, buffer_tmp,
+   VHDX_LOG_SECTOR_SIZE);
+if (ret < 0) {
+goto exit;
+}
+buffer_tmp += VHDX_LOG_SECTOR_SIZE;
+
+log->write = write;
+*sectors_written = *sectors_written + 1;
+num_sectors--;
+}
+
+exit:
+return ret;
+}
+
+
 /* Validates a log entry header */
 static bool vhdx_log_hdr_is_valid(VHDXLogEntries *log, VHDXLogEntryHeader *hdr,
   BDRVVHDXState *s)
@@ -732,3 +779,229 @@ exit:
 return ret;
 }
 
+
+
+static void vhdx_log_raw_to_le_sector(VHDXLogDescriptor *desc,
+  VHDXLogDataSector *sector, void *data,
+  uint64_t seq)
+{
+memcpy(&desc->leading_bytes, data, 8);
+data += 8;
+cpu_to_le64s(&desc->leading_bytes);
+memcpy(sector->data, data, 4084);
+data += 4084;
+memcpy(&desc->trailing_bytes, data, 4);
+cpu_to_le32s(&desc->trailing_bytes);
+data += 4;
+
+sector->sequence_high  = (uint32_t) (seq >> 32);
+sector->sequence_low   = (uint32_t) (seq & 0x);
+sector->data_signature = VHDX_LOG_DATA_SIGNATURE;
+
+vhdx_log_desc_le_export(desc);
+vhdx_log_data_le_export(sector);
+}
+
+
+static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
+  void *data, uint32_t length, uint64_t offset)
+{
+int ret = 0;
+void *buffer = NULL;
+void *merged_sector = NULL;
+void *data_tmp, *sector_write;
+unsigned int i;
+int sector_offset;
+uint32_t desc_sectors, sectors, total_length;
+uint32_t sectors_written = 0;
+uint32_t aligned_length;
+uint32_t leading_length = 0;
+uint32_t trailing_length = 0;
+uint32_t partial_sectors = 0;
+uint32_t bytes_written = 0;
+uint64_t file_offset;
+VHDXHeader *header;
+VHDXLogEntryHeader new_hdr;
+VHDXLogDescriptor *new_desc = NULL;
+VHDXLogDataSector *data_sector = NULL;
+MSGUID new_guid = { 0 };
+
+header = s->headers[s->curr_header];
+
+/* need to have offset read data, and be on 4096 byte boundary */
+
+if (length > header->log_length) {
+/* no log present.  we could create a log here instead of failing */
+ret = -EINVAL;
+goto exit;
+}
+
+if (vhdx_log_guid_is_zero(&header->log_guid)) {
+vhdx_guid_generate(&new_guid);
+vhdx_update_headers(bs, s, false, &new_guid);
+} else {
+/* currently, we require that the log be flushed after
+ * every write. */
+ret = -ENOTSUP;
+}
+
+/* 0 is an invalid sequence number, but may also represent the first
+ * log write (or a wrapped seq) */
+if (s->log.sequence == 0) {
+s->log.sequence = 1;
+}
+
+sector_offset = offset % VHDX_LOG_SECTOR_SIZE;
+file_offset = (offset / VHDX_LOG_SECTOR_SIZE) * VHDX_LOG_SECTOR_SIZE;
+
+aligned_length = length;
+
+/* add in the unaligned head and tail bytes */
+if (sector_offset) {
+leading_

[Qemu-devel] [PATCH 7/9] block: vhdx - log parsing, replay, and flush support

2013-07-24 Thread Jeff Cody
This adds support for VHDX v0 logs, as specified in Microsoft's
VHDX Specification Format v1.00:
https://www.microsoft.com/en-us/download/details.aspx?id=34750

The following support is added:

* Log parsing, and validation - validate that an existing log
  is correct.

* Log search - search through an existing log, to find any valid
  sequence of entries.

* Log replay and flush - replay an existing log, and flush/clear
  the log when complete.

The VHDX log is a circular buffer, with elements (sectors) of 4KB.

A log entry is a variably-length number of sectors, that is
comprised of a header and 'descriptors', that describe each sector.

A log may contain multiple entries, know as a log sequence.  In a log
sequence, each log entry immediately follows the previous entry, with an
incrementing sequence number.  There can only ever be one active and
valid sequence in the log.

Each log entry must match the file log GUID in order to be valid (along
with other criteria).  Once we have flushed all valid log entries, we
marked the file log GUID to be zero, which indicates a buffer with no
valid entries.

Signed-off-by: Jeff Cody 
---
 block/Makefile.objs |   2 +-
 block/vhdx-log.c| 734 
 block/vhdx.c|  44 +---
 block/vhdx.h|   7 +-
 4 files changed, 743 insertions(+), 44 deletions(-)
 create mode 100644 block/vhdx-log.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index e6f5d33..2fbd79a 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o 
bochs.o vpc.o vvfat
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o
+block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
 block-obj-y += snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
new file mode 100644
index 000..89b9000
--- /dev/null
+++ b/block/vhdx-log.c
@@ -0,0 +1,734 @@
+/*
+ * Block driver for Hyper-V VHDX Images
+ *
+ * Copyright (c) 2013 Red Hat, Inc.,
+ *
+ * Authors:
+ *  Jeff Cody 
+ *
+ *  This is based on the "VHDX Format Specification v1.00", published 8/25/2012
+ *  by Microsoft:
+ *  https://www.microsoft.com/en-us/download/details.aspx?id=34750
+ *
+ * This file covers the functionality of the metadata log writing, parsing, and
+ * replay.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#include "qemu-common.h"
+#include "block/block_int.h"
+#include "qemu/module.h"
+#include "block/vhdx.h"
+
+
+typedef struct VHDXLogSequence {
+bool valid;
+uint32_t count;
+VHDXLogEntries log;
+VHDXLogEntryHeader hdr;
+} VHDXLogSequence;
+
+typedef struct VHDXLogDescEntries {
+VHDXLogEntryHeader hdr;
+VHDXLogDescriptor desc[];
+} VHDXLogDescEntries;
+
+
+/* Returns true if the GUID is zero */
+static bool vhdx_log_guid_is_zero(MSGUID *guid)
+{
+int i;
+int ret = 0;
+
+/* If either the log guid, or log length is zero,
+ * then a replay log is not present */
+for (i = 0; i < sizeof(MSGUID); i++) {
+ret |= ((uint8_t *) guid)[i];
+}
+
+return ret == 0;
+}
+
+/* The log located on the disk is circular buffer containing
+ * sectors of 4096 bytes each.
+ *
+ * It is assumed for the read/write functions below that the
+ * circular buffer scheme uses a 'one sector open' to indicate
+ * the buffer is full.  Given the validation methods used for each
+ * sector, this method should be compatible with other methods that
+ * do not waste a sector.
+ */
+
+
+/* Allow peeking at the hdr entry at the beginning of the current
+ * read index, without advancing the read index */
+static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log,
+ VHDXLogEntryHeader *hdr)
+{
+int ret = 0;
+uint64_t offset;
+uint32_t read;
+
+assert(hdr != NULL);
+
+/* peek is only support on sector boundaries */
+if (log->read % VHDX_LOG_SECTOR_SIZE) {
+ret = -EFAULT;
+goto exit;
+}
+
+read = log->read;
+/* we are guaranteed that a) log sectors are 4096 bytes,
+ * and b) the log length is a multiple of 1MB. So, there
+ * is always a round number of sectors in the buffer */
+if ((read + sizeof(VHDXLogEntryHeader)) > log->length) {
+read = 0;
+}
+
+if (read == log->write) {
+ret = -EINVAL;
+goto exit;
+}
+
+offset = log->offset + read;
+
+ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader));
+if (ret < 0) {
+goto exit;
+}
+
+exit:
+return ret;
+}
+
+/* Index increment for log, based on se

Re: [Qemu-devel] [PATCH V6 1/3] Implement sync modes for drive-backup.

2013-07-24 Thread Ian Main
On Wed, Jul 24, 2013 at 12:55:43PM +0200, Kevin Wolf wrote:
> Am 23.07.2013 um 00:09 hat Ian Main geschrieben:
> > This patch adds sync-modes to the drive-backup interface and
> > implements the FULL, NONE and TOP modes of synchronization.
> > 
> > FULL performs as before copying the entire contents of the drive
> > while preserving the point-in-time using CoW.
> > NONE only copies new writes to the target drive.
> > TOP copies changes to the topmost drive image and preserves the
> > point-in-time using CoW.
> > 
> > For sync mode TOP are creating a new target image using the same backing
> > file as the original disk image.  Then any new data that has been laid
> > on top of it since creation is copied in the main backup_run() loop.
> > There is an extra check in the 'TOP' case so that we don't bother to copy
> > all the data of the backing file as it already exists in the target.
> > This is where the bdrv_co_is_allocated() is used to determine if the
> > data exists in the topmost layer or below.
> > 
> > Also any new data being written is intercepted via the write_notifier
> > hook which ends up calling backup_do_cow() to copy old data out before
> > it gets overwritten.
> > 
> > For mode 'NONE' we create the new target image and only copy in the
> > original data from the disk image starting from the time the call was
> > made.  This preserves the point in time data by only copying the parts
> > that are *going to change* to the target image.  This way we can
> > reconstruct the final image by checking to see if the given block exists
> > in the new target image first, and if it does not, you can get it from
> > the original image.  This is basically an optimization allowing you to
> > do point-in-time snapshots with low overhead vs the 'FULL' version.
> > 
> > Since there is no old data to copy out the loop in backup_run() for the
> > NONE case just calls qemu_coroutine_yield() which only wakes up after
> > an event (usually cancel in this case).  The rest is handled by the
> > before_write notifier which again calls backup_do_cow() to write out
> > the old data so it can be preserved.
> > 
> > Signed-off-by: Ian Main 
> > ---
> >  block/backup.c| 91 
> > +++
> >  blockdev.c| 36 ---
> >  include/block/block_int.h |  4 ++-
> >  qapi-schema.json  |  4 +--
> >  qmp-commands.hx   |  2 ++
> >  5 files changed, 92 insertions(+), 45 deletions(-)
> > 
> > diff --git a/block/backup.c b/block/backup.c
> > index 16105d4..68abd23 100644
> > --- a/block/backup.c
> > +++ b/block/backup.c
> > @@ -37,6 +37,7 @@ typedef struct CowRequest {
> >  typedef struct BackupBlockJob {
> >  BlockJob common;
> >  BlockDriverState *target;
> > +MirrorSyncMode sync_mode;
> >  RateLimit limit;
> >  BlockdevOnError on_source_error;
> >  BlockdevOnError on_target_error;
> > @@ -247,40 +248,69 @@ static void coroutine_fn backup_run(void *opaque)
> >  
> >  bdrv_add_before_write_notifier(bs, &before_write);
> >  
> > -for (; start < end; start++) {
> > -bool error_is_read;
> > -
> > -if (block_job_is_cancelled(&job->common)) {
> > -break;
> > +if (job->sync_mode == MIRROR_SYNC_MODE_NONE) {
> > +while (!block_job_is_cancelled(&job->common)) {
> > +/* Yield until the job is cancelled.  We just let our 
> > before_write
> > + * notify callback service CoW requests. */
> > +job->common.busy = false;
> > +qemu_coroutine_yield();
> > +job->common.busy = true;
> >  }
> > +} else {
> > +/* Both FULL and TOP SYNC_MODE's require copying.. */
> > +for (; start < end; start++) {
> > +bool error_is_read;
> >  
> > -/* we need to yield so that qemu_aio_flush() returns.
> > - * (without, VM does not reboot)
> > - */
> > -if (job->common.speed) {
> > -uint64_t delay_ns = ratelimit_calculate_delay(
> > -&job->limit, job->sectors_read);
> > -job->sectors_read = 0;
> > -block_job_sleep_ns(&job->common, rt_clock, delay_ns);
> > -} else {
> > -block_job_sleep_ns(&job->common, rt_clock, 0);
> > -}
> > +if (block_job_is_cancelled(&job->common)) {
> > +break;
> > +}
> >  
> > -if (block_job_is_cancelled(&job->common)) {
> > -break;
> > -}
> > +/* we need to yield so that qemu_aio_flush() returns.
> > + * (without, VM does not reboot)
> > + */
> > +if (job->common.speed) {
> > +uint64_t delay_ns = ratelimit_calculate_delay(
> > +&job->limit, job->sectors_read);
> > +job->sectors_read = 0;
> > +block_job_sleep_ns(&job->common, rt_clock, delay_ns);
> > +} else {
> > +b

[Qemu-devel] [PATCH 3/9] block: vhdx code movement - VHDXMetadataEntries and BDRVVHDXState to header.

2013-07-24 Thread Jeff Cody
In preparation for VHDX log support, move these structures to the
header.

Signed-off-by: Jeff Cody 
---
 block/vhdx.c | 51 ---
 block/vhdx.h | 47 +++
 2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 13e486d..72af996 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -104,16 +104,6 @@ static const MSGUID parent_vhdx_guid = { .data1 = 
0xb04aefb7,
  META_PAGE_83_PRESENT | META_LOGICAL_SECTOR_SIZE_PRESENT | \
  META_PHYS_SECTOR_SIZE_PRESENT)
 
-typedef struct VHDXMetadataEntries {
-VHDXMetadataTableEntry file_parameters_entry;
-VHDXMetadataTableEntry virtual_disk_size_entry;
-VHDXMetadataTableEntry page83_data_entry;
-VHDXMetadataTableEntry logical_sector_size_entry;
-VHDXMetadataTableEntry phys_sector_size_entry;
-VHDXMetadataTableEntry parent_locator_entry;
-uint16_t present;
-} VHDXMetadataEntries;
-
 
 typedef struct VHDXSectorInfo {
 uint32_t bat_idx;   /* BAT entry index */
@@ -124,47 +114,6 @@ typedef struct VHDXSectorInfo {
 uint64_t block_offset;  /* block offset, in bytes */
 } VHDXSectorInfo;
 
-
-
-typedef struct BDRVVHDXState {
-CoMutex lock;
-
-int curr_header;
-VHDXHeader *headers[2];
-
-VHDXRegionTableHeader rt;
-VHDXRegionTableEntry bat_rt; /* region table for the BAT */
-VHDXRegionTableEntry metadata_rt;/* region table for the metadata */
-
-VHDXMetadataTableHeader metadata_hdr;
-VHDXMetadataEntries metadata_entries;
-
-VHDXFileParameters params;
-uint32_t block_size;
-uint32_t block_size_bits;
-uint32_t sectors_per_block;
-uint32_t sectors_per_block_bits;
-
-uint64_t virtual_disk_size;
-uint32_t logical_sector_size;
-uint32_t physical_sector_size;
-
-uint64_t chunk_ratio;
-uint32_t chunk_ratio_bits;
-uint32_t logical_sector_size_bits;
-
-uint32_t bat_entries;
-VHDXBatEntry *bat;
-uint64_t bat_offset;
-
-MSGUID session_guid;
-
-
-VHDXParentLocatorHeader parent_header;
-VHDXParentLocatorEntry *parent_entries;
-
-} BDRVVHDXState;
-
 /* Calculates new checksum.
  *
  * Zero is substituted during crc calculation for the original crc field
diff --git a/block/vhdx.h b/block/vhdx.h
index 3999cb1..c8d8593 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -308,6 +308,53 @@ typedef struct QEMU_PACKED VHDXParentLocatorEntry {
 
 /* - END VHDX SPECIFICATION STRUCTURES  */
 
+typedef struct VHDXMetadataEntries {
+VHDXMetadataTableEntry file_parameters_entry;
+VHDXMetadataTableEntry virtual_disk_size_entry;
+VHDXMetadataTableEntry page83_data_entry;
+VHDXMetadataTableEntry logical_sector_size_entry;
+VHDXMetadataTableEntry phys_sector_size_entry;
+VHDXMetadataTableEntry parent_locator_entry;
+uint16_t present;
+} VHDXMetadataEntries;
+
+typedef struct BDRVVHDXState {
+CoMutex lock;
+
+int curr_header;
+VHDXHeader *headers[2];
+
+VHDXRegionTableHeader rt;
+VHDXRegionTableEntry bat_rt; /* region table for the BAT */
+VHDXRegionTableEntry metadata_rt;/* region table for the metadata */
+
+VHDXMetadataTableHeader metadata_hdr;
+VHDXMetadataEntries metadata_entries;
+
+VHDXFileParameters params;
+uint32_t block_size;
+uint32_t block_size_bits;
+uint32_t sectors_per_block;
+uint32_t sectors_per_block_bits;
+
+uint64_t virtual_disk_size;
+uint32_t logical_sector_size;
+uint32_t physical_sector_size;
+
+uint64_t chunk_ratio;
+uint32_t chunk_ratio_bits;
+uint32_t logical_sector_size_bits;
+
+uint32_t bat_entries;
+VHDXBatEntry *bat;
+uint64_t bat_offset;
+
+MSGUID session_guid;
+
+VHDXParentLocatorHeader parent_header;
+VHDXParentLocatorEntry *parent_entries;
+
+} BDRVVHDXState;
 
 void vhdx_guid_generate(MSGUID *guid);
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 6/9] block: vhdx - update log guid in header, and first write tracker

2013-07-24 Thread Jeff Cody
Allow tracking of first file write in the VHDX image, as well as
the ability to update the GUID in the header.  This is in preparation
for log support.

Signed-off-by: Jeff Cody 
---
 block/vhdx.c | 28 +++-
 block/vhdx.h |  7 +--
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 9f7f04f..f5689c3 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -233,7 +233,8 @@ static int vhdx_probe(const uint8_t *buf, int buf_size, 
const char *filename)
  *
  *  - non-current header is updated with largest sequence number
  */
-static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, bool rw)
+static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+  MSGUID *log_guid)
 {
 int ret = 0;
 int hdr_idx = 0;
@@ -266,6 +267,11 @@ static int vhdx_update_header(BlockDriverState *bs, 
BDRVVHDXState *s, bool rw)
 vhdx_guid_generate(&inactive_header->data_write_guid);
 }
 
+/* update the log guid if present */
+if (log_guid) {
+memcpy(&inactive_header->log_guid, log_guid, sizeof(MSGUID));
+}
+
 /* the header checksum is not over just the packed size of VHDXHeader,
  * but rather over the entire 'reserved' range for the header, which is
  * 4KB (VHDX_HEADER_SIZE). */
@@ -293,15 +299,16 @@ fail:
  * The VHDX spec calls for header updates to be performed twice, so that both
  * the current and non-current header have valid info
  */
-static int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw)
+int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+MSGUID *log_guid)
 {
 int ret;
 
-ret = vhdx_update_header(bs, s, rw);
+ret = vhdx_update_header(bs, s, rw, log_guid);
 if (ret < 0) {
 return ret;
 }
-ret = vhdx_update_header(bs, s, rw);
+ret = vhdx_update_header(bs, s, rw, log_guid);
 return ret;
 }
 
@@ -781,6 +788,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, 
int flags)
 
 
 s->bat = NULL;
+s->first_visible_write = true;
 
 qemu_co_mutex_init(&s->lock);
 
@@ -861,7 +869,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, 
int flags)
 }
 
 if (flags & BDRV_O_RDWR) {
-vhdx_update_headers(bs, s, false);
+vhdx_update_headers(bs, s, false, NULL);
 }
 
 /* TODO: differencing files, write */
@@ -998,6 +1006,16 @@ exit:
 
 
 
+/* Per the spec, on the first write of guest-visible data to the file the
+ * data write guid must be updated in the header */
+void vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s)
+{
+if (s->first_visible_write) {
+s->first_visible_write = false;
+vhdx_update_headers(bs, s, true, NULL);
+}
+}
+
 static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t 
sector_num,
   int nb_sectors, QEMUIOVector *qiov)
 {
diff --git a/block/vhdx.h b/block/vhdx.h
index 5e0a1d3..cb3ce0e 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -366,6 +366,7 @@ typedef struct BDRVVHDXState {
 VHDXBatEntry *bat;
 uint64_t bat_offset;
 
+bool first_visible_write;
 MSGUID session_guid;
 
 VHDXLogEntries log;
@@ -377,6 +378,9 @@ typedef struct BDRVVHDXState {
 
 void vhdx_guid_generate(MSGUID *guid);
 
+int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+MSGUID *log_guid);
+
 uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset);
 uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size,
 int crc_offset);
@@ -406,8 +410,7 @@ void vhdx_log_data_le_export(VHDXLogDataSector *d);
 void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr);
 void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr);
 
-
-
+void vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s);
 
 
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 4/9] block: vhdx - log support struct and defines

2013-07-24 Thread Jeff Cody
This adds some magic number defines, and internal structure
definitions for VHDX log replay support.

Signed-off-by: Jeff Cody 
---
 block/vhdx.h | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/block/vhdx.h b/block/vhdx.h
index c8d8593..2db6615 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -151,7 +151,10 @@ typedef struct QEMU_PACKED VHDXRegionTableEntry {
 
 
 /*  LOG ENTRY STRUCTURES  */
+#define VHDX_LOG_MIN_SIZE (1024*1024)
+#define VHDX_LOG_SECTOR_SIZE 4096
 #define VHDX_LOG_HDR_SIZE 64
+#define VHDX_LOG_SIGNATURE 0x65676f6c
 typedef struct QEMU_PACKED VHDXLogEntryHeader {
 uint32_tsignature;  /* "loge" in ASCII */
 uint32_tchecksum;   /* CRC-32C hash of the 64KB table */
@@ -174,7 +177,8 @@ typedef struct QEMU_PACKED VHDXLogEntryHeader {
 } VHDXLogEntryHeader;
 
 #define VHDX_LOG_DESC_SIZE 32
-
+#define VHDX_LOG_DESC_SIGNATURE 0x63736564
+#define VHDX_LOG_ZERO_SIGNATURE 0x6f72657a
 typedef struct QEMU_PACKED VHDXLogDescriptor {
 uint32_tsignature;  /* "zero" or "desc" in ASCII */
 union  {
@@ -194,6 +198,7 @@ typedef struct QEMU_PACKED VHDXLogDescriptor {
vhdx_log_entry_header */
 } VHDXLogDescriptor;
 
+#define VHDX_LOG_DATA_SIGNATURE 0x61746164
 typedef struct QEMU_PACKED VHDXLogDataSector {
 uint32_tdata_signature; /* "data" in ASCII */
 uint32_tsequence_high;  /* 4 MSB of 8 byte sequence_number */
@@ -318,6 +323,18 @@ typedef struct VHDXMetadataEntries {
 uint16_t present;
 } VHDXMetadataEntries;
 
+typedef struct VHDXLogEntries {
+uint64_t offset;
+uint64_t length;
+uint32_t head;
+uint32_t tail;
+} VHDXLogEntries;
+
+typedef struct VHDXLogEntryInfo {
+uint64_t sector_start;
+uint32_t desc_count;
+} VHDXLogEntryInfo;
+
 typedef struct BDRVVHDXState {
 CoMutex lock;
 
@@ -351,6 +368,8 @@ typedef struct BDRVVHDXState {
 
 MSGUID session_guid;
 
+VHDXLogEntries log;
+
 VHDXParentLocatorHeader parent_header;
 VHDXParentLocatorEntry *parent_entries;
 
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH] misc: Fix new typos in comments and strings

2013-07-24 Thread Peter Maydell
On 24 July 2013 18:48, Stefan Weil  wrote:
> All these typos were found by codespell.
>
> sould -> should
> emperical -> empirical
> intialization -> initialization
> successfuly -> successfully
> gaurantee -> guarantee
>
> Fix also another error (before before) in the same context.
>
> Signed-off-by: Stefan Weil 

Reviewed-by: Peter Maydell 

-- PMM



[Qemu-devel] [PATCH 1/9] block: vhdx - minor comments and typo correction.

2013-07-24 Thread Jeff Cody
Just a couple of minor comments to help note where allocated
buffers are freed, and a typo fix.

Signed-off-by: Jeff Cody 
---
 block/vhdx.c | 6 --
 block/vhdx.h | 6 +++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index e9704b1..56bc88e 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -6,9 +6,9 @@
  * Authors:
  *  Jeff Cody 
  *
- *  This is based on the "VHDX Format Specification v0.95", published 4/12/2012
+ *  This is based on the "VHDX Format Specification v1.00", published 8/25/2012
  *  by Microsoft:
- *  https://www.microsoft.com/en-us/download/details.aspx?id=29681
+ *  https://www.microsoft.com/en-us/download/details.aspx?id=34750
  *
  * This work is licensed under the terms of the GNU LGPL, version 2 or later.
  * See the COPYING.LIB file in the top-level directory.
@@ -262,6 +262,7 @@ static int vhdx_parse_header(BlockDriverState *bs, 
BDRVVHDXState *s)
 uint64_t h2_seq = 0;
 uint8_t *buffer;
 
+/* header1 & header2 are freed in vhdx_close() */
 header1 = qemu_blockalign(bs, sizeof(VHDXHeader));
 header2 = qemu_blockalign(bs, sizeof(VHDXHeader));
 
@@ -787,6 +788,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, 
int flags)
 goto fail;
 }
 
+/* s->bat is freed in vhdx_close() */
 s->bat = qemu_blockalign(bs, s->bat_rt.length);
 
 ret = bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.length);
diff --git a/block/vhdx.h b/block/vhdx.h
index c3b64c6..1dbb320 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -6,9 +6,9 @@
  * Authors:
  *  Jeff Cody 
  *
- *  This is based on the "VHDX Format Specification v0.95", published 4/12/2012
+ *  This is based on the "VHDX Format Specification v1.00", published 8/25/2012
  *  by Microsoft:
- *  https://www.microsoft.com/en-us/download/details.aspx?id=29681
+ *  https://www.microsoft.com/en-us/download/details.aspx?id=34750
  *
  * This work is licensed under the terms of the GNU LGPL, version 2 or later.
  * See the COPYING.LIB file in the top-level directory.
@@ -116,7 +116,7 @@ typedef struct QEMU_PACKED VHDXHeader {
valid. */
 uint16_tlog_version;/* version of the log format. Mustn't 
be
zero, unless log_guid is also zero 
*/
-uint16_tversion;/* version of th evhdx file.  
Currently,
+uint16_tversion;/* version of the vhdx file.  
Currently,
only supported version is "1" */
 uint32_tlog_length; /* length of the log.  Must be multiple
of 1MB */
-- 
1.8.1.4




[Qemu-devel] [PATCH 5/9] block: vhdx - break endian translation functions out

2013-07-24 Thread Jeff Cody
This moves the endian translation functions out from the vhdx.c source,
into a separate source file. In addition to the previously defined
endian functions, new endian translation functions for log support are
added as well.

Signed-off-by: Jeff Cody 
---
 block/Makefile.objs |   2 +-
 block/vhdx-endian.c | 141 
 block/vhdx.c|  43 
 block/vhdx.h|  13 +
 4 files changed, 155 insertions(+), 44 deletions(-)
 create mode 100644 block/vhdx-endian.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index e5e54e6..e6f5d33 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o 
bochs.o vpc.o vvfat
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-$(CONFIG_VHDX) += vhdx.o
+block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
 block-obj-y += snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
new file mode 100644
index 000..f7a59c5
--- /dev/null
+++ b/block/vhdx-endian.c
@@ -0,0 +1,141 @@
+/*
+ * Block driver for Hyper-V VHDX Images
+ *
+ * Copyright (c) 2013 Red Hat, Inc.,
+ *
+ * Authors:
+ *  Jeff Cody 
+ *
+ *  This is based on the "VHDX Format Specification v1.00", published 8/25/2012
+ *  by Microsoft:
+ *  https://www.microsoft.com/en-us/download/details.aspx?id=34750
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "block/block_int.h"
+#include "block/vhdx.h"
+
+#include 
+
+
+/*
+ * All the VHDX formats on disk are little endian - the following
+ * are helper import/export functions to correctly convert
+ * endianness from disk read to native cpu format, and back again.
+ */
+
+
+/* VHDX File Header */
+
+
+void vhdx_header_le_import(VHDXHeader *h)
+{
+assert(h != NULL);
+
+le32_to_cpus(&h->signature);
+le32_to_cpus(&h->checksum);
+le64_to_cpus(&h->sequence_number);
+
+leguid_to_cpus(&h->file_write_guid);
+leguid_to_cpus(&h->data_write_guid);
+leguid_to_cpus(&h->log_guid);
+
+le16_to_cpus(&h->log_version);
+le16_to_cpus(&h->version);
+le32_to_cpus(&h->log_length);
+le64_to_cpus(&h->log_offset);
+}
+
+void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h)
+{
+assert(orig_h != NULL);
+assert(new_h != NULL);
+
+new_h->signature   = cpu_to_le32(orig_h->signature);
+new_h->checksum= cpu_to_le32(orig_h->checksum);
+new_h->sequence_number = cpu_to_le64(orig_h->sequence_number);
+
+memcpy(&new_h->file_write_guid, &orig_h->file_write_guid, sizeof(MSGUID));
+memcpy(&new_h->data_write_guid, &orig_h->data_write_guid, sizeof(MSGUID));
+memcpy(&new_h->log_guid,&orig_h->log_guid,sizeof(MSGUID));
+
+cpu_to_leguids(&new_h->file_write_guid);
+cpu_to_leguids(&new_h->data_write_guid);
+cpu_to_leguids(&new_h->log_guid);
+
+new_h->log_version = cpu_to_le16(orig_h->log_version);
+new_h->version = cpu_to_le16(orig_h->version);
+new_h->log_length  = cpu_to_le32(orig_h->log_length);
+new_h->log_offset  = cpu_to_le64(orig_h->log_offset);
+}
+
+
+/* VHDX Log Headers */
+
+
+void vhdx_log_desc_le_import(VHDXLogDescriptor *d)
+{
+assert(d != NULL);
+
+le32_to_cpus(&d->signature);
+le32_to_cpus(&d->trailing_bytes);
+le64_to_cpus(&d->leading_bytes);
+le64_to_cpus(&d->file_offset);
+le64_to_cpus(&d->sequence_number);
+}
+
+void vhdx_log_desc_le_export(VHDXLogDescriptor *d)
+{
+assert(d != NULL);
+
+cpu_to_le32s(&d->signature);
+cpu_to_le32s(&d->trailing_bytes);
+cpu_to_le64s(&d->leading_bytes);
+cpu_to_le64s(&d->file_offset);
+cpu_to_le64s(&d->sequence_number);
+}
+
+void vhdx_log_data_le_export(VHDXLogDataSector *d)
+{
+assert(d != NULL);
+
+cpu_to_le32s(&d->data_signature);
+cpu_to_le32s(&d->sequence_high);
+cpu_to_le32s(&d->sequence_low);
+}
+
+void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr)
+{
+assert(hdr != NULL);
+
+le32_to_cpus(&hdr->signature);
+le32_to_cpus(&hdr->checksum);
+le32_to_cpus(&hdr->entry_length);
+le32_to_cpus(&hdr->tail);
+le64_to_cpus(&hdr->sequence_number);
+le32_to_cpus(&hdr->descriptor_count);
+leguid_to_cpus(&hdr->log_guid);
+le64_to_cpus(&hdr->flushed_file_offset);
+le64_to_cpus(&hdr->last_file_offset);
+}
+
+void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr)
+{
+assert(hdr != NULL);
+
+cpu_to_le32s(&hdr->signature);
+cpu_to_le32s(&hdr->checksum);
+cpu_to_le32s(&hdr->entry_length);
+cpu_to_le32s(&hdr->tail);
+cpu_to_le64s(&

[Qemu-devel] [PATCH 0/9] VHDX log replay and write support

2013-07-24 Thread Jeff Cody
This patch series contains the initial VHDX log parsing, replay,
and write support.

This will allow an existing log in a VHDX image to be replayed (e.g., a VHDX
image from a Hyper-V host that crashed).  In addition, metadata writes are
enabled through the log.  This allows write support to be enabled for VHDX,
as the BAT can be updated safely via the log journal.

The patches are also available from github, for testing:
https://github.com/codyprime/qemu-kvm-jtc/tree/jtc-vhdx-latest

Jeff Cody (9):
  block: vhdx - minor comments and typo correction.
  block: vhdx - add header update capability.
  block: vhdx code movement - VHDXMetadataEntries and BDRVVHDXState to
header.
  block: vhdx - log support struct and defines
  block: vhdx - break endian translation functions out
  block: vhdx - update log guid in header, and first write tracker
  block: vhdx - log parsing, replay, and flush support
  block: vhdx - add log write support
  block: vhdx write support

 block/Makefile.objs |2 +-
 block/vhdx-endian.c |  141 
 block/vhdx-log.c| 1007 +++
 block/vhdx.c|  394 ++--
 block/vhdx.h|  110 +-
 configure   |   13 +
 6 files changed, 1556 insertions(+), 111 deletions(-)
 create mode 100644 block/vhdx-endian.c
 create mode 100644 block/vhdx-log.c

-- 
1.8.1.4




[Qemu-devel] [PATCH 2/9] block: vhdx - add header update capability.

2013-07-24 Thread Jeff Cody
This adds the ability to update the headers in a VHDX image, including
generating a new MS-compatible GUID.

As VHDX depends on uuid.h, VHDX is now a configurable build option.  If
VHDX support is enabled, that will also enable uuid as well.  The
default is to have VHDX enabled.

To enable/disable VHDX:  --enable-vhdx, --disable-vhdx

Signed-off-by: Jeff Cody 
---
 block/Makefile.objs |   2 +-
 block/vhdx.c| 157 +++-
 block/vhdx.h|  12 +++-
 configure   |  13 +
 4 files changed, 180 insertions(+), 4 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 4cf9aa4..e5e54e6 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o 
bochs.o vpc.o vvfat
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-y += vhdx.o
+block-obj-$(CONFIG_VHDX) += vhdx.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
 block-obj-y += snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
diff --git a/block/vhdx.c b/block/vhdx.c
index 56bc88e..13e486d 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -21,6 +21,7 @@
 #include "qemu/crc32c.h"
 #include "block/vhdx.h"
 
+#include 
 
 /* Several metadata and region table data entries are identified by
  * guids in  a MS-specific GUID format. */
@@ -156,11 +157,40 @@ typedef struct BDRVVHDXState {
 VHDXBatEntry *bat;
 uint64_t bat_offset;
 
+MSGUID session_guid;
+
+
 VHDXParentLocatorHeader parent_header;
 VHDXParentLocatorEntry *parent_entries;
 
 } BDRVVHDXState;
 
+/* Calculates new checksum.
+ *
+ * Zero is substituted during crc calculation for the original crc field
+ * crc_offset: byte offset in buf of the buffer crc
+ * buf: buffer pointer
+ * size: size of buffer (must be > crc_offset+4)
+ *
+ * Note: The resulting checksum is in the CPU endianness, not necessarily
+ *   in the file format endianness (LE).  Any header export to disk should
+ *   make sure that vhdx_header_le_export() is used to convert to the
+ *   correct endianness
+ */
+uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset)
+{
+uint32_t crc;
+
+assert(buf != NULL);
+assert(size > (crc_offset + 4));
+
+memset(buf + crc_offset, 0, sizeof(crc));
+crc =  crc32c(0x, buf, size);
+memcpy(buf + crc_offset, &crc, sizeof(crc));
+
+return crc;
+}
+
 uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size,
 int crc_offset)
 {
@@ -212,6 +242,24 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int 
crc_offset)
 
 
 /*
+ * This generates a UUID that is compliant with the MS GUIDs used
+ * in the VHDX spec (and elsewhere).
+ *
+ * We can do this with uuid_generate if uuid.h is present,
+ * however not all systems have uuid and the generation is
+ * pretty straightforward for the DCE + random usage case
+ *
+ */
+void vhdx_guid_generate(MSGUID *guid)
+{
+uuid_t uuid;
+assert(guid != NULL);
+
+uuid_generate(uuid);
+memcpy(guid, uuid, 16);
+}
+
+/*
  * Per the MS VHDX Specification, for every VHDX file:
  *  - The header section is fixed size - 1 MB
  *  - The header section is always the first "object"
@@ -249,6 +297,107 @@ static void vhdx_header_le_import(VHDXHeader *h)
 le64_to_cpus(&h->log_offset);
 }
 
+/* All VHDX structures on disk are little endian */
+static void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h)
+{
+assert(orig_h != NULL);
+assert(new_h != NULL);
+
+new_h->signature   = cpu_to_le32(orig_h->signature);
+new_h->checksum= cpu_to_le32(orig_h->checksum);
+new_h->sequence_number = cpu_to_le64(orig_h->sequence_number);
+
+memcpy(&new_h->file_write_guid, &orig_h->file_write_guid, sizeof(MSGUID));
+memcpy(&new_h->data_write_guid, &orig_h->data_write_guid, sizeof(MSGUID));
+memcpy(&new_h->log_guid,&orig_h->log_guid,sizeof(MSGUID));
+
+cpu_to_leguids(&new_h->file_write_guid);
+cpu_to_leguids(&new_h->data_write_guid);
+cpu_to_leguids(&new_h->log_guid);
+
+new_h->log_version = cpu_to_le16(orig_h->log_version);
+new_h->version = cpu_to_le16(orig_h->version);
+new_h->log_length  = cpu_to_le32(orig_h->log_length);
+new_h->log_offset  = cpu_to_le64(orig_h->log_offset);
+}
+
+/* Update the VHDX headers
+ *
+ * This follows the VHDX spec procedures for header updates.
+ *
+ *  - non-current header is updated with largest sequence number
+ */
+static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, bool rw)
+{
+int ret = 0;
+int hdr_idx = 0;
+uint64_t header_offset = VHDX_HEADER1_OFFSET;
+
+VHDXHeader *active_header;
+VHDXHeader *inactive_header;
+VHDXHeader header_le;
+

[Qemu-devel] [PATCH] misc: Fix new typos in comments and strings

2013-07-24 Thread Stefan Weil
All these typos were found by codespell.

sould -> should
emperical -> empirical
intialization -> initialization
successfuly -> successfully
gaurantee -> guarantee

Fix also another error (before before) in the same context.

Signed-off-by: Stefan Weil 
---
 block/vhdx.h   |2 +-
 docs/rdma.txt  |2 +-
 hw/virtio/virtio-balloon.c |4 ++--
 hw/xen/xen_pt.c|3 ++-
 migration-rdma.c   |4 ++--
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/block/vhdx.h b/block/vhdx.h
index c3b64c6..fb687ed 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -168,7 +168,7 @@ typedef struct QEMU_PACKED VHDXLogEntryHeader {
vhdx_header.  If not found in
vhdx_header, it is invalid */
 uint64_tflushed_file_offset;/* see spec for full details - this
-   sould be vhdx file size in bytes */
+   should be vhdx file size in bytes */
 uint64_tlast_file_offset;   /* size in bytes that all allocated
file structures fit into */
 } VHDXLogEntryHeader;
diff --git a/docs/rdma.txt b/docs/rdma.txt
index 45d1c8a..8d1e003 100644
--- a/docs/rdma.txt
+++ b/docs/rdma.txt
@@ -199,7 +199,7 @@ Version #1 requires that all server implementations of the 
protocol must
 check this field and register all requests found in the array of commands 
located
 in the data portion and return an equal number of results in the response.
 The maximum number of repeats is hard-coded to 4096. This is a conservative
-limit based on the maximum size of a SEND message along with emperical
+limit based on the maximum size of a SEND message along with empirical
 observations on the maximum future benefit of simultaneous page registrations.
 
 The 'type' field has 12 different command values:
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 3fa72a9..337cfa5 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -53,8 +53,8 @@ static const char *balloon_stat_names[] = {
 /*
  * reset_stats - Mark all items in the stats array as unset
  *
- * This function needs to be called at device intialization and before
- * before updating to a set of newly-generated stats.  This will ensure that no
+ * This function needs to be called at device initialization and before
+ * updating to a set of newly-generated stats.  This will ensure that no
  * stale values stick around in case the guest reports a subset of the 
supported
  * statistics.
  */
diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index d7ee774..d15a729 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -756,7 +756,8 @@ static int xen_pt_initfn(PCIDevice *d)
 out:
 memory_listener_register(&s->memory_listener, &address_space_memory);
 memory_listener_register(&s->io_listener, &address_space_io);
-XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered 
successfuly!\n",
+XEN_PT_LOG(d,
+   "Real physical device %02x:%02x.%d registered successfully!\n",
s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function);
 
 return 0;
diff --git a/migration-rdma.c b/migration-rdma.c
index d044830..4828738 100644
--- a/migration-rdma.c
+++ b/migration-rdma.c
@@ -2494,7 +2494,7 @@ static int qemu_rdma_close(void *opaque)
  *@size == 0 :
  *A 'hint' or 'advice' that means that we wish to speculatively
  *and asynchronously unregister this memory. In this case, there is no
- *gaurantee that the unregister will actually happen, for example,
+ *guarantee that the unregister will actually happen, for example,
  *if the memory is being actively transmitted. Additionally, the memory
  *may be re-registered at any future time if a write within the same
  *chunk was requested again, even if you attempted to unregister it
@@ -2570,7 +2570,7 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void 
*opaque,
 qemu_rdma_signal_unregister(rdma, index, chunk, 0);
 
 /*
- * TODO: Synchronous, gauranteed unregistration (should not occur 
during
+ * TODO: Synchronous, guaranteed unregistration (should not occur 
during
  * fast-path). Otherwise, unregisters will process on the next call to
  * qemu_rdma_drain_cq()
 if (size < 0) {
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 0/2] vdso for x86_64-linux-user

2013-07-24 Thread Richard Henderson
On 07/24/2013 06:39 AM, Peter Maydell wrote:
> On 24 July 2013 17:34, Richard Henderson  wrote:
>> On 07/23/2013 11:15 AM, Peter Maydell wrote:
>>> On 23 July 2013 21:27, Richard Henderson  wrote:
 This is a refresh of a patch I wrote in 2010, and have re-posted every
 6 months thereafter.  To my knowledge, it has never been reviewed.

 It supplies a replacement for the required x86-64 vdso.  Anyone trying
 to emulate x86_64-linux on a host other than same will quickly run into
 the lack of a gettimeofday syscall, which glibc assumes is always
 provided by the vdso.
>>>
>>> Do we really need to mess with building an x86 shared object
>>> and pulling it in, rather than the kind of ad-hoc way we
>>> handle the ARM commpage?
>>
>> Isn't the arm ad-hoc really the much larger and uglier hack?
> 
> Maaaybe, but it doesn't require a cross-compiler :-)

The 7k binary is checked in to the repository, so a cross-compiler
(or host compiler for x86_64, which is easier to come by) would
only be needed when the source changes.  ;-)


r~




Re: [Qemu-devel] VM can not boot after commit 235e898

2013-07-24 Thread Gleb Natapov
On Wed, Jul 24, 2013 at 06:26:41PM +0200, Alexander Graf wrote:
> >before. Are you saying configuring BIOS memslot differently solves the
> >problem?
> 
> Git bisect pointed to the commit mentioned in this email. The
> following patch also gets me a working guest again:
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 4fb4ccb..deca9e5 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1455,7 +1455,7 @@ int kvm_init(void)
>  s->irq_set_ioctl = KVM_IRQ_LINE_STATUS;
>  }
> 
> -#ifdef KVM_CAP_READONLY_MEM
> +#if 0 //def KVM_CAP_READONLY_MEM
>  kvm_readonly_mem_allowed =
>  (kvm_check_extension(s, KVM_CAP_READONLY_MEM) > 0);
>  #endif
> 
Can you disable emulate_invalid_state on 3.7? What happens on upstream kernel
(works for me obviously :)).

--
Gleb.



[Qemu-devel] [PATCH v3 08/14] loader: allow adding ROMs in done callbacks

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

Signed-off-by: Michael S. Tsirkin 
---
 hw/core/loader.c| 6 +-
 include/hw/loader.h | 1 +
 vl.c| 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index c2309e6..c68f757 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -778,10 +778,14 @@ int rom_load_all(void)
 memory_region_unref(section.mr);
 }
 qemu_register_reset(rom_reset, NULL);
-roms_loaded = 1;
 return 0;
 }
 
+void rom_load_done(void)
+{
+roms_loaded = 1;
+}
+
 void rom_set_fw(FWCfgState *f)
 {
 fw_cfg = f;
diff --git a/include/hw/loader.h b/include/hw/loader.h
index cdb7b4b..8f0d142 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -44,6 +44,7 @@ int rom_add_blob(const char *name, const void *blob, size_t 
len,
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
 size_t romsize, hwaddr addr);
 int rom_load_all(void);
+void rom_load_done(void);
 void rom_set_fw(FWCfgState *f);
 int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
 void *rom_ptr(hwaddr addr);
diff --git a/vl.c b/vl.c
index 25b8f2f..3d56ec0 100644
--- a/vl.c
+++ b/vl.c
@@ -4408,6 +4408,9 @@ int main(int argc, char **argv, char **envp)
 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
 qemu_run_machine_init_done_notifiers();
 
+/* Done notifiers can load ROMs */
+rom_load_done();
+
 qemu_system_reset(VMRESET_SILENT);
 if (loadvm) {
 if (load_vmstate(loadvm) < 0) {
-- 
MST




[Qemu-devel] [PATCH v3 13/14] hpet: add API to find it

2013-07-24 Thread Michael S. Tsirkin
Add API to find HPET using QOM.

Signed-off-by: Michael S. Tsirkin 
---
 hw/timer/hpet.c | 5 +
 include/hw/timer/hpet.h | 2 ++
 2 files changed, 7 insertions(+)

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




[Qemu-devel] [PATCH v3 07/14] loader: support for unmapped ROM blobs

2013-07-24 Thread Michael S. Tsirkin
Support ROM blobs not mapped into guest memory:
let user pass in MR for memory serving as the backing store.

Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Laszlo Ersek 
---
 hw/core/loader.c   | 32 +---
 hw/lm32/lm32_hwsetup.h |  2 +-
 include/hw/loader.h|  4 ++--
 3 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index c4dd665..c2309e6 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -576,6 +576,7 @@ struct Rom {
 size_t datasize;
 
 uint8_t *data;
+MemoryRegion *mr;
 int isrom;
 char *fw_dir;
 char *fw_file;
@@ -675,7 +676,7 @@ err:
 }
 
 int rom_add_blob(const char *name, const void *blob, size_t len,
- hwaddr addr)
+ hwaddr addr, MemoryRegion *mr)
 {
 Rom *rom;
 
@@ -685,6 +686,11 @@ int rom_add_blob(const char *name, const void *blob, 
size_t len,
 rom->romsize  = len;
 rom->datasize = len;
 rom->data = g_malloc0(rom->datasize);
+rom->mr   = mr;
+if (mr) {
+assert(memory_region_is_ram(mr));
+rom->isrom = memory_region_is_rom(mr);
+}
 memcpy(rom->data, blob, len);
 rom_insert(rom);
 return 0;
@@ -725,13 +731,21 @@ static void rom_reset(void *unused)
 Rom *rom;
 
 QTAILQ_FOREACH(rom, &roms, next) {
+if (rom->mr) {
+continue;
+}
 if (rom->fw_file) {
 continue;
 }
 if (rom->data == NULL) {
 continue;
 }
-cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize);
+if (rom->mr) {
+void *host = memory_region_get_ram_ptr(rom->mr);
+memcpy(host, rom->data, rom->datasize);
+} else {
+cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize);
+}
 if (rom->isrom) {
 /* rom needs to be written only once */
 g_free(rom->data);
@@ -781,6 +795,9 @@ static Rom *find_rom(hwaddr addr)
 if (rom->fw_file) {
 continue;
 }
+if (rom->mr) {
+continue;
+}
 if (rom->addr > addr) {
 continue;
 }
@@ -808,6 +825,9 @@ int rom_copy(uint8_t *dest, hwaddr addr, size_t size)
 if (rom->fw_file) {
 continue;
 }
+if (rom->mr) {
+continue;
+}
 if (rom->addr + rom->romsize < addr) {
 continue;
 }
@@ -867,7 +887,13 @@ void do_info_roms(Monitor *mon, const QDict *qdict)
 Rom *rom;
 
 QTAILQ_FOREACH(rom, &roms, next) {
-if (!rom->fw_file) {
+if (rom->mr) {
+monitor_printf(mon, "%s"
+   " size=0x%06zx name=\"%s\"\n",
+   rom->mr->name,
+   rom->romsize,
+   rom->name);
+} else if (!rom->fw_file) {
 monitor_printf(mon, "addr=" TARGET_FMT_plx
" size=0x%06zx mem=%s name=\"%s\"\n",
rom->addr, rom->romsize,
diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
index 3449bd8..d6914d6 100644
--- a/hw/lm32/lm32_hwsetup.h
+++ b/hw/lm32/lm32_hwsetup.h
@@ -73,7 +73,7 @@ static inline void hwsetup_free(HWSetup *hw)
 static inline void hwsetup_create_rom(HWSetup *hw,
 hwaddr base)
 {
-rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base);
+rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL);
 }
 
 static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index eb9c9a3..cdb7b4b 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -40,7 +40,7 @@ void pstrcpy_targphys(const char *name,
 int rom_add_file(const char *file, const char *fw_dir,
  hwaddr addr, int32_t bootindex);
 int rom_add_blob(const char *name, const void *blob, size_t len,
- hwaddr addr);
+ hwaddr addr, MemoryRegion *mr);
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
 size_t romsize, hwaddr addr);
 int rom_load_all(void);
@@ -52,7 +52,7 @@ void do_info_roms(Monitor *mon, const QDict *qdict);
 #define rom_add_file_fixed(_f, _a, _i)  \
 rom_add_file(_f, NULL, _a, _i)
 #define rom_add_blob_fixed(_f, _b, _l, _a)  \
-rom_add_blob(_f, _b, _l, _a)
+rom_add_blob(_f, _b, _l, _a, NULL)
 
 #define PC_ROM_MIN_VGA 0xc
 #define PC_ROM_MIN_OPTION  0xc8000
-- 
MST




[Qemu-devel] [PATCH v3 05/14] loader: use file path size from fw_cfg.h

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

Suggested-by: Laszlo Ersek 
Signed-off-by: Michael S. Tsirkin 
---
 hw/core/loader.c  | 2 +-
 include/hw/nvram/fw_cfg.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

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




Re: [Qemu-devel] [PATCH 0/2] vdso for x86_64-linux-user

2013-07-24 Thread Peter Maydell
On 24 July 2013 17:34, Richard Henderson  wrote:
> On 07/23/2013 11:15 AM, Peter Maydell wrote:
>> On 23 July 2013 21:27, Richard Henderson  wrote:
>>> This is a refresh of a patch I wrote in 2010, and have re-posted every
>>> 6 months thereafter.  To my knowledge, it has never been reviewed.
>>>
>>> It supplies a replacement for the required x86-64 vdso.  Anyone trying
>>> to emulate x86_64-linux on a host other than same will quickly run into
>>> the lack of a gettimeofday syscall, which glibc assumes is always
>>> provided by the vdso.
>>
>> Do we really need to mess with building an x86 shared object
>> and pulling it in, rather than the kind of ad-hoc way we
>> handle the ARM commpage?
>
> Isn't the arm ad-hoc really the much larger and uglier hack?

Maaaybe, but it doesn't require a cross-compiler :-)

-- PMM



Re: [Qemu-devel] [PATCH 0/2] vdso for x86_64-linux-user

2013-07-24 Thread Richard Henderson
On 07/23/2013 11:15 AM, Peter Maydell wrote:
> On 23 July 2013 21:27, Richard Henderson  wrote:
>> This is a refresh of a patch I wrote in 2010, and have re-posted every
>> 6 months thereafter.  To my knowledge, it has never been reviewed.
>>
>> It supplies a replacement for the required x86-64 vdso.  Anyone trying
>> to emulate x86_64-linux on a host other than same will quickly run into
>> the lack of a gettimeofday syscall, which glibc assumes is always
>> provided by the vdso.
> 
> Do we really need to mess with building an x86 shared object
> and pulling it in, rather than the kind of ad-hoc way we
> handle the ARM commpage?

Isn't the arm ad-hoc really the much larger and uglier hack?


r~




Re: [Qemu-devel] VM can not boot after commit 235e898

2013-07-24 Thread Alexander Graf

On 07/24/2013 06:17 PM, Gleb Natapov wrote:

On Wed, Jul 24, 2013 at 05:31:14PM +0200, Alexander Graf wrote:

On 07/24/2013 05:21 PM, Gleb Natapov wrote:

On Wed, Jul 24, 2013 at 05:16:09PM +0200, Paolo Bonzini wrote:

Il 24/07/2013 11:58, Alexander Graf ha scritto:

No QEMU or kvm crashes, no error message printed, I mean it just hangs, even no 
BIOS information are printed.
And "top" shows QEMU consumes 100% cpu.

When I define DEBUG_KVM in kvm-all.c, and run QEMU(this time I boot a normal OS 
disk),
# x86_64-softmmu/qemu-system-x86_64 -enable-kvm -hda 
/mnt/nfs/Images/debian-append.img
kvm_init_vcpu
kvm_cpu_exec()
handle_io
handle_io
handle_io
handle_io

Only 4 debug messages(handle_io) are printed, then nothing is shown, and "top" 
shows QEMU process uses 100% CPU.

After this we're running in an endless loop of:

  qemu-system-x86-9298  [003] ...1 162090.918845: kvm_emulate_insn: 
f:c489:66 ea 91 c4 0f 00 08 00 (prot16)
  qemu-system-x86-9298  [003] d..2 162090.918846: kvm_entry: vcpu 0

   (qemu) x /i $pc
   0x000fc489:  ljmpl  $0x8,$0xfc491

With current master, qemu-system-x86_64 -enable-kvm is broken on at least 3.7 
kernels (openSUSE 12.3).

Gleb, I don't remember all the glorious details of ljmpl, but would it have to 
raise an MMIO request for a read-only memory slot which it fails to do?

The point of KVM_CAP_READONLY_MEM should be that it doesn't.


Yes, it should not. Can you provide complete trace of kvm and kvmmmu
event up until failure?

Sure! These are all trace events up to the loop that I was able to
fetch from the "kvm" and "kvmmmu" event bucket in
/sys/kernel/debug/tracing.


You should start using trace-cmd :) It even disassembles for you.


  qemu-system-x86-13150 [000] d..2 185370.441825: kvm_entry: vcpu 0
  qemu-system-x86-13150 [000] d..2 185370.441826: kvm_exit: reason 
EXCEPTION_NMI rip 0xc486 info 0 8b0d
  qemu-system-x86-13150 [000] ...1 185370.441826: kvm_emulate_insn: 
f:c486:0f 22 c0 (real)

This mov CR0 that sets PE bit.


  qemu-system-x86-13150 [000] d..2 185370.441829: kvm_entry: vcpu 0
  qemu-system-x86-13150 [000] ...1 185370.441830: kvm_emulate_insn: 
f:c489:66 ea 91 c4 0f 00 08 00 (prot16)

Here jmp is emulated because vcpu state is invalid, but for some reason
emulation does not fail and does not succeed. Never saw such thing


It works just fine with older QEMU:

 qemu-system-x86-9448  [001] d..2 162748.223935: kvm_exit: reason 
IO_INSTRUCTION rip 0xc471 info 920040 0
 qemu-system-x86-9448  [001] ...1 162748.223936: kvm_pio: pio_write at 
0x92 size 1 count 1
 qemu-system-x86-9448  [001] ...1 162748.223936: kvm_userspace_exit: 
reason KVM_EXIT_IO (2)

 qemu-system-x86-9448  [001] d..2 162748.223939: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] d..2 162748.223940: kvm_exit: reason 
EXCEPTION_NMI rip 0xc473 info 0 8b0d
 qemu-system-x86-9448  [001] ...1 162748.223942: kvm_emulate_insn: 
f:c473:2e 0f 01 1e e0 d3 (real)

 qemu-system-x86-9448  [001] d..2 162748.223945: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] d..2 162748.223946: kvm_exit: reason 
EXCEPTION_NMI rip 0xc479 info 0 8b0d
 qemu-system-x86-9448  [001] ...1 162748.223947: kvm_emulate_insn: 
f:c479:2e 0f 01 16 a0 d3 (real)

 qemu-system-x86-9448  [001] d..2 162748.223948: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] d..2 162748.223948: kvm_exit: reason 
EXCEPTION_NMI rip 0xc47f info 0 8b0d
 qemu-system-x86-9448  [001] ...1 162748.223950: kvm_emulate_insn: 
f:c47f:0f 20 c0 (real)

 qemu-system-x86-9448  [001] d..2 162748.223951: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] d..2 162748.223951: kvm_exit: reason 
EXCEPTION_NMI rip 0xc486 info 0 8b0d
 qemu-system-x86-9448  [001] ...1 162748.223952: kvm_emulate_insn: 
f:c486:0f 22 c0 (real)

 qemu-system-x86-9448  [001] d..2 162748.223955: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] ...1 162748.223956: kvm_emulate_insn: 
f:c489:66 ea 91 c4 0f 00 08 00 (prot16)

 qemu-system-x86-9448  [001] d..2 162748.223959: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] ...1 162748.223960: kvm_emulate_insn: 
0:fc491:b8 10 00 00 00 (prot32)

 qemu-system-x86-9448  [001] d..2 162748.223961: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] ...1 162748.223961: kvm_emulate_insn: 
0:fc496:8e d8 (prot32)

 qemu-system-x86-9448  [001] d..2 162748.223963: kvm_entry: vcpu 0
 qemu-system-x86-9448  [001] ...1 162748.223964: kvm_emulate_insn: 
0:fc498:8e c0 (prot32)

 qemu-system-x86-9448  [001] d..2 162748.223965: kvm_entry: vcpu 0
[...]


before. Are you saying configuring BIOS memslot differently solves the
problem?


Git bisect pointed to the commit mentioned in this email. The following 
patch also gets me a working guest again:


diff --git a/kvm-all.c b/kvm-all.c
index 4fb4ccb..deca9e5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1455,7 +1455,7 @@ int kvm_init(void)
 s->irq_set_ioctl = KVM_IRQ_LINE_STATUS;
 }

-#ifdef KVM_CAP_READONLY_MEM
+#if 0 //def KVM_CAP_READONLY_MEM
 kvm_readonly_mem_allowed =

  1   2   3   >