[Qemu-devel] seabios for qemu 1.5

2013-04-24 Thread Gerd Hoffmann
  Hi,

 b44a7be17bdd270ea029a8e2ec0c2e80c6cd0444 virtio-scsi: Pack struct 
 virtio_scsi_{req_cmd,resp_cmd}
 5a7730db57ab0715223421e65b54fb50d6fefe5c virtio-scsi: Set _DRIVER_OK flag 
 before scsi target scanning

 Anthony + Gerd, can we expect an rev to pc-bios/bios.bin soon to pick up
 these seabios changes for vhost-scsi..?

I don't feel like placing a seabios git snapshot into qemu.

I think we should just cherry-pick everything we need for qemu 1.5 into
the 1.7.2-stable branch, roll out a 1.7.2.2 release and put that into
qemu 1.5.

So, what will be needed?

  (1) The two commits listed above.
  (2) The patch for the pvpanic device (assuming it gets
  merged for 1.5).

Anything else?

Hard freeze for qemu 1.5 is next Wednesday.

cheers,
  Gerd

PS: For qemu 1.6 (which will hopefully include the acpi table
reorganization) we will need a new release from the master
branch and thus a bit more careful release planning.




Re: [Qemu-devel] seabios for qemu 1.5

2013-04-24 Thread Amos Kong
On Wed, Apr 24, 2013 at 07:59:36AM +0200, Gerd Hoffmann wrote:
   Hi,
 
  b44a7be17bdd270ea029a8e2ec0c2e80c6cd0444 virtio-scsi: Pack struct 
  virtio_scsi_{req_cmd,resp_cmd}
  5a7730db57ab0715223421e65b54fb50d6fefe5c virtio-scsi: Set _DRIVER_OK flag 
  before scsi target scanning
 
  Anthony + Gerd, can we expect an rev to pc-bios/bios.bin soon to pick up
  these seabios changes for vhost-scsi..?
 
 I don't feel like placing a seabios git snapshot into qemu.
 
 I think we should just cherry-pick everything we need for qemu 1.5 into
 the 1.7.2-stable branch, roll out a 1.7.2.2 release and put that into
 qemu 1.5.
 
 So, what will be needed?
 
   (1) The two commits listed above.
   (2) The patch for the pvpanic device (assuming it gets
   merged for 1.5).
 
 Anything else?

Hi Gerd,

This bug fix is needed:

| commit 11a7234491cb2a027b0fa5e82af38a3e78b44c80
| Author: Kevin O'Connor ke...@koconnor.net
| Date:   Tue Mar 5 17:52:21 2013 +0800
| 
| Cache boot-fail-wait to avoid romfile access after POST.
| 
| Memory allocated with malloc_tmp() can't be used after the POST phase.
| So, access boot-fail-wait in post phase and store it for the boot
| phase to use.  This fixes the regression introduced by commit
| 59d6ca52.


 Hard freeze for qemu 1.5 is next Wednesday.
 
 cheers,
   Gerd
 
 PS: For qemu 1.6 (which will hopefully include the acpi table
 reorganization) we will need a new release from the master
 branch and thus a bit more careful release planning.
 

-- 
Amos.



Re: [Qemu-devel] [PATCH 1/2] cpu-exec: rid cs_base of TranslationBlock

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 03:48, liguang ha scritto:
 cs_base is only meaningful for target-i386/sparc,
 so, get rid of cs_base for other target

This is really ugly, we're trying to get less target-dependent code
outside target-*, not more.

Also, please limit the number of people that you CC.

Paolo

 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  cpu-exec.c  |   26 ++
  exec.c  |6 +++---
  hw/i386/kvmvapic.c  |6 ++
  include/exec/exec-all.h |5 +++--
  target-i386/cpu.h   |6 ++
  translate-all.c |   24 
  6 files changed, 40 insertions(+), 33 deletions(-)
 
 diff --git a/cpu-exec.c b/cpu-exec.c
 index 31c089d..f3c1d1c 100644
 --- a/cpu-exec.c
 +++ b/cpu-exec.c
 @@ -84,7 +84,7 @@ static void cpu_exec_nocache(CPUArchState *env, int 
 max_cycles,
  if (max_cycles  CF_COUNT_MASK)
  max_cycles = CF_COUNT_MASK;
  
 -tb = tb_gen_code(env, orig_tb-pc, orig_tb-cs_base, orig_tb-flags,
 +tb = tb_gen_code(env, orig_tb-pc, orig_tb-flags,
   max_cycles);
  cpu-current_tb = tb;
  /* execute the generated code */
 @@ -96,7 +96,6 @@ static void cpu_exec_nocache(CPUArchState *env, int 
 max_cycles,
  
  static TranslationBlock *tb_find_slow(CPUArchState *env,
target_ulong pc,
 -  target_ulong cs_base,
uint64_t flags)
  {
  TranslationBlock *tb, **ptb1;
 @@ -117,7 +116,12 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
  goto not_found;
  if (tb-pc == pc 
  tb-page_addr[0] == phys_page1 
 -tb-cs_base == cs_base 
 +#if defined(TARGET_I386)
 +tb-cs_base == env-segs[R_CS].base 
 +#endif
 +#if defined(TARGET_SPARC)
 +tb-cs_base == env-npc 
 +#endif
  tb-flags == flags) {
  /* check next page if needed */
  if (tb-page_addr[1] != -1) {
 @@ -136,7 +140,7 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
  }
   not_found:
 /* if no translated code available, then translate it now */
 -tb = tb_gen_code(env, pc, cs_base, flags, 0);
 +tb = tb_gen_code(env, pc, flags, 0);
  
   found:
  /* Move the last found TB to the head of the list */
 @@ -153,17 +157,23 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
  static inline TranslationBlock *tb_find_fast(CPUArchState *env)
  {
  TranslationBlock *tb;
 -target_ulong cs_base, pc;
 +target_ulong pc;
  int flags;
  
  /* we record a subset of the CPU state. It will
 always be the same before a given translated block
 is executed. */
 -cpu_get_tb_cpu_state(env, pc, cs_base, flags);
 +cpu_get_tb_cpu_state(env, pc, flags);
  tb = env-tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
 -if (unlikely(!tb || tb-pc != pc || tb-cs_base != cs_base ||
 +if (unlikely(!tb || tb-pc != pc ||
 +#if defined(TARGET_I386)
 + tb-cs_base != env-segs[R_CS].base ||
 +#endif
 +#if defined(TARGET_SPARC)
 + tb-cs_base != env-npc ||
 +#endif
   tb-flags != flags)) {
 -tb = tb_find_slow(env, pc, cs_base, flags);
 +tb = tb_find_slow(env, pc, flags);
  }
  return tb;
  }
 diff --git a/exec.c b/exec.c
 index fa1e0c3..a14db2c 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -1471,7 +1471,7 @@ static const MemoryRegionOps notdirty_mem_ops = {
  static void check_watchpoint(int offset, int len_mask, int flags)
  {
  CPUArchState *env = cpu_single_env;
 -target_ulong pc, cs_base;
 +target_ulong pc;
  target_ulong vaddr;
  CPUWatchpoint *wp;
  int cpu_flags;
 @@ -1495,8 +1495,8 @@ static void check_watchpoint(int offset, int len_mask, 
 int flags)
  env-exception_index = EXCP_DEBUG;
  cpu_loop_exit(env);
  } else {
 -cpu_get_tb_cpu_state(env, pc, cs_base, cpu_flags);
 -tb_gen_code(env, pc, cs_base, cpu_flags, 1);
 +cpu_get_tb_cpu_state(env, pc, cpu_flags);
 +tb_gen_code(env, pc, cpu_flags, 1);
  cpu_resume_from_signal(env, NULL);
  }
  }
 diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
 index ed9b448..8b4260e 100644
 --- a/hw/i386/kvmvapic.c
 +++ b/hw/i386/kvmvapic.c
 @@ -388,7 +388,6 @@ static void patch_instruction(VAPICROMState *s, X86CPU 
 *cpu, target_ulong ip)
  uint8_t opcode[2];
  uint32_t imm32;
  target_ulong current_pc = 0;
 -target_ulong current_cs_base = 0;
  int current_flags = 0;
  
  if (smp_cpus == 1) {
 @@ -399,8 +398,7 @@ static void patch_instruction(VAPICROMState *s, X86CPU 
 *cpu, target_ulong ip)
  
  if (!kvm_enabled()) {
  cpu_restore_state(env, env-mem_io_pc);
 -cpu_get_tb_cpu_state(env, current_pc, 

Re: [Qemu-devel] [PATCH v5 11/12] rdma: core logic

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 01:53, Michael R. Hines ha scritto:
 
 So, I started investigating the problem, and I noticed that whenever
 I disabled the limits of max_size, the throughput went back to
 the normal throughput (peak of 26 gbps).
 
 So, rather than change the default max_size calculation for TCP,
 which would improperly impact existing users of TCP migration,
 I introduced a new QEMUFileOps change to solve the problem.
 
 What do you think?

I'd prefer to remove this and understand it better for 1.6.

I'd be in favor of getting this in 1.5, but without this hook.

Paolo



Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread Peter Maydell
On 24 April 2013 02:48, liguang lig.f...@cn.fujitsu.com wrote:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com

I'm afraid this is definitely wrong. It has a less than
helpful name, but cs_base is actually just another 32/64 bits
of state that the target can use to distinguish translation
blocks, and some non-x86 targets do use it. For instance:


 --- a/target-sparc/cpu.h
 +++ b/target-sparc/cpu.h
 @@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
  #define TB_FLAG_AM_ENABLED (1  5)

  static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong *pc,
 -target_ulong *cs_base, int *flags)
 +int *flags)
  {
  *pc = env-pc;
  *cs_base = env-npc;

...surely this doesn't even compile after your changes?

thanks
-- PMM



Re: [Qemu-devel] [PATCH 1/2] cpu-exec: rid cs_base of TranslationBlock

2013-04-24 Thread Aurelien Jarno
On Wed, Apr 24, 2013 at 08:36:54AM +0200, Paolo Bonzini wrote:
 Il 24/04/2013 03:48, liguang ha scritto:
  cs_base is only meaningful for target-i386/sparc,
  so, get rid of cs_base for other target
 
 This is really ugly, we're trying to get less target-dependent code
 outside target-*, not more.

Fully agreed. It also breaks the interface between the target and
cpu-exec.c by assuming tb-cs_base will always be env-segs[R_CS].base.

The only cleanup that can be done here is to rename cs_base into flags2
to make it less target dependent, and the code in cpu-exec.c should just
guarantee to choose tbs which match both flags and flags2 without
actually caring about the meaning of the values.

Even that way, this is the kind of cleanup touching a lot of code
without real benefit, except maybe for sparc which currently abuse
cs_base.

 Also, please limit the number of people that you CC.
 
 Paolo
 
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
  ---
   cpu-exec.c  |   26 ++
   exec.c  |6 +++---
   hw/i386/kvmvapic.c  |6 ++
   include/exec/exec-all.h |5 +++--
   target-i386/cpu.h   |6 ++
   translate-all.c |   24 
   6 files changed, 40 insertions(+), 33 deletions(-)
  
  diff --git a/cpu-exec.c b/cpu-exec.c
  index 31c089d..f3c1d1c 100644
  --- a/cpu-exec.c
  +++ b/cpu-exec.c
  @@ -84,7 +84,7 @@ static void cpu_exec_nocache(CPUArchState *env, int 
  max_cycles,
   if (max_cycles  CF_COUNT_MASK)
   max_cycles = CF_COUNT_MASK;
   
  -tb = tb_gen_code(env, orig_tb-pc, orig_tb-cs_base, orig_tb-flags,
  +tb = tb_gen_code(env, orig_tb-pc, orig_tb-flags,
max_cycles);
   cpu-current_tb = tb;
   /* execute the generated code */
  @@ -96,7 +96,6 @@ static void cpu_exec_nocache(CPUArchState *env, int 
  max_cycles,
   
   static TranslationBlock *tb_find_slow(CPUArchState *env,
 target_ulong pc,
  -  target_ulong cs_base,
 uint64_t flags)
   {
   TranslationBlock *tb, **ptb1;
  @@ -117,7 +116,12 @@ static TranslationBlock *tb_find_slow(CPUArchState 
  *env,
   goto not_found;
   if (tb-pc == pc 
   tb-page_addr[0] == phys_page1 
  -tb-cs_base == cs_base 
  +#if defined(TARGET_I386)
  +tb-cs_base == env-segs[R_CS].base 
  +#endif
  +#if defined(TARGET_SPARC)
  +tb-cs_base == env-npc 
  +#endif
   tb-flags == flags) {
   /* check next page if needed */
   if (tb-page_addr[1] != -1) {
  @@ -136,7 +140,7 @@ static TranslationBlock *tb_find_slow(CPUArchState *env,
   }
not_found:
  /* if no translated code available, then translate it now */
  -tb = tb_gen_code(env, pc, cs_base, flags, 0);
  +tb = tb_gen_code(env, pc, flags, 0);
   
found:
   /* Move the last found TB to the head of the list */
  @@ -153,17 +157,23 @@ static TranslationBlock *tb_find_slow(CPUArchState 
  *env,
   static inline TranslationBlock *tb_find_fast(CPUArchState *env)
   {
   TranslationBlock *tb;
  -target_ulong cs_base, pc;
  +target_ulong pc;
   int flags;
   
   /* we record a subset of the CPU state. It will
  always be the same before a given translated block
  is executed. */
  -cpu_get_tb_cpu_state(env, pc, cs_base, flags);
  +cpu_get_tb_cpu_state(env, pc, flags);
   tb = env-tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
  -if (unlikely(!tb || tb-pc != pc || tb-cs_base != cs_base ||
  +if (unlikely(!tb || tb-pc != pc ||
  +#if defined(TARGET_I386)
  + tb-cs_base != env-segs[R_CS].base ||
  +#endif
  +#if defined(TARGET_SPARC)
  + tb-cs_base != env-npc ||
  +#endif
tb-flags != flags)) {
  -tb = tb_find_slow(env, pc, cs_base, flags);
  +tb = tb_find_slow(env, pc, flags);
   }
   return tb;
   }
  diff --git a/exec.c b/exec.c
  index fa1e0c3..a14db2c 100644
  --- a/exec.c
  +++ b/exec.c
  @@ -1471,7 +1471,7 @@ static const MemoryRegionOps notdirty_mem_ops = {
   static void check_watchpoint(int offset, int len_mask, int flags)
   {
   CPUArchState *env = cpu_single_env;
  -target_ulong pc, cs_base;
  +target_ulong pc;
   target_ulong vaddr;
   CPUWatchpoint *wp;
   int cpu_flags;
  @@ -1495,8 +1495,8 @@ static void check_watchpoint(int offset, int 
  len_mask, int flags)
   env-exception_index = EXCP_DEBUG;
   cpu_loop_exit(env);
   } else {
  -cpu_get_tb_cpu_state(env, pc, cs_base, cpu_flags);
  -tb_gen_code(env, pc, cs_base, cpu_flags, 1);
  +cpu_get_tb_cpu_state(env, pc, cpu_flags);
  +tb_gen_code(env, pc, cpu_flags, 1);
   

Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread li guang
在 2013-04-24三的 08:05 +0100,Peter Maydell写道:
 On 24 April 2013 02:48, liguang lig.f...@cn.fujitsu.com wrote:
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
 
 I'm afraid this is definitely wrong. It has a less than
 helpful name, but cs_base is actually just another 32/64 bits
 of state that the target can use to distinguish translation
 blocks, and some non-x86 targets do use it. For instance:

only sparc use it as a tmp buffer for pc.

 
 
  --- a/target-sparc/cpu.h
  +++ b/target-sparc/cpu.h
  @@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
   #define TB_FLAG_AM_ENABLED (1  5)
 
   static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong 
  *pc,
  -target_ulong *cs_base, int *flags)
  +int *flags)
   {
   *pc = env-pc;
   *cs_base = env-npc;
 
 ...surely this doesn't even compile after your changes?
 

seems no problem for me.

 thanks
 -- PMM





Re: [Qemu-devel] [PATCH 1/2] cpu-exec: rid cs_base of TranslationBlock

2013-04-24 Thread li guang
在 2013-04-24三的 09:11 +0200,Aurelien Jarno写道:
 On Wed, Apr 24, 2013 at 08:36:54AM +0200, Paolo Bonzini wrote:
  Il 24/04/2013 03:48, liguang ha scritto:
   cs_base is only meaningful for target-i386/sparc,
   so, get rid of cs_base for other target
  
  This is really ugly, we're trying to get less target-dependent code
  outside target-*, not more.

I think it's easy to be arch independent by just
call a generic function instead of #if defined(*),
and archs can implement their own specific in this function.


 
 Fully agreed. It also breaks the interface between the target and
 cpu-exec.c by assuming tb-cs_base will always be env-segs[R_CS].base.
 

I'm not going to assume that (maybe it's the fact),
I did some random tests, seems break nothing.

 The only cleanup that can be done here is to rename cs_base into flags2
 to make it less target dependent, and the code in cpu-exec.c should just
 guarantee to choose tbs which match both flags and flags2 without
 actually caring about the meaning of the values.
 
 Even that way, this is the kind of cleanup touching a lot of code
 without real benefit, except maybe for sparc which currently abuse
 cs_base.
 
  Also, please limit the number of people that you CC.
  
  Paolo
  
   Signed-off-by: liguang lig.f...@cn.fujitsu.com
   ---
cpu-exec.c  |   26 ++
exec.c  |6 +++---
hw/i386/kvmvapic.c  |6 ++
include/exec/exec-all.h |5 +++--
target-i386/cpu.h   |6 ++
translate-all.c |   24 
6 files changed, 40 insertions(+), 33 deletions(-)
   
   diff --git a/cpu-exec.c b/cpu-exec.c
   index 31c089d..f3c1d1c 100644
   --- a/cpu-exec.c
   +++ b/cpu-exec.c
   @@ -84,7 +84,7 @@ static void cpu_exec_nocache(CPUArchState *env, int 
   max_cycles,
if (max_cycles  CF_COUNT_MASK)
max_cycles = CF_COUNT_MASK;

   -tb = tb_gen_code(env, orig_tb-pc, orig_tb-cs_base, orig_tb-flags,
   +tb = tb_gen_code(env, orig_tb-pc, orig_tb-flags,
 max_cycles);
cpu-current_tb = tb;
/* execute the generated code */
   @@ -96,7 +96,6 @@ static void cpu_exec_nocache(CPUArchState *env, int 
   max_cycles,

static TranslationBlock *tb_find_slow(CPUArchState *env,
  target_ulong pc,
   -  target_ulong cs_base,
  uint64_t flags)
{
TranslationBlock *tb, **ptb1;
   @@ -117,7 +116,12 @@ static TranslationBlock *tb_find_slow(CPUArchState 
   *env,
goto not_found;
if (tb-pc == pc 
tb-page_addr[0] == phys_page1 
   -tb-cs_base == cs_base 
   +#if defined(TARGET_I386)
   +tb-cs_base == env-segs[R_CS].base 
   +#endif
   +#if defined(TARGET_SPARC)
   +tb-cs_base == env-npc 
   +#endif
tb-flags == flags) {
/* check next page if needed */
if (tb-page_addr[1] != -1) {
   @@ -136,7 +140,7 @@ static TranslationBlock *tb_find_slow(CPUArchState 
   *env,
}
 not_found:
   /* if no translated code available, then translate it now */
   -tb = tb_gen_code(env, pc, cs_base, flags, 0);
   +tb = tb_gen_code(env, pc, flags, 0);

 found:
/* Move the last found TB to the head of the list */
   @@ -153,17 +157,23 @@ static TranslationBlock *tb_find_slow(CPUArchState 
   *env,
static inline TranslationBlock *tb_find_fast(CPUArchState *env)
{
TranslationBlock *tb;
   -target_ulong cs_base, pc;
   +target_ulong pc;
int flags;

/* we record a subset of the CPU state. It will
   always be the same before a given translated block
   is executed. */
   -cpu_get_tb_cpu_state(env, pc, cs_base, flags);
   +cpu_get_tb_cpu_state(env, pc, flags);
tb = env-tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
   -if (unlikely(!tb || tb-pc != pc || tb-cs_base != cs_base ||
   +if (unlikely(!tb || tb-pc != pc ||
   +#if defined(TARGET_I386)
   + tb-cs_base != env-segs[R_CS].base ||
   +#endif
   +#if defined(TARGET_SPARC)
   + tb-cs_base != env-npc ||
   +#endif
 tb-flags != flags)) {
   -tb = tb_find_slow(env, pc, cs_base, flags);
   +tb = tb_find_slow(env, pc, flags);
}
return tb;
}
   diff --git a/exec.c b/exec.c
   index fa1e0c3..a14db2c 100644
   --- a/exec.c
   +++ b/exec.c
   @@ -1471,7 +1471,7 @@ static const MemoryRegionOps notdirty_mem_ops = {
static void check_watchpoint(int offset, int len_mask, int flags)
{
CPUArchState *env = cpu_single_env;
   -target_ulong pc, cs_base;
   +target_ulong pc;
target_ulong vaddr;
CPUWatchpoint *wp;
int cpu_flags;
   @@ -1495,8 +1495,8 @@ static void check_watchpoint(int offset, int 
   

Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread Peter Maydell
On 24 April 2013 08:15, li guang lig.f...@cn.fujitsu.com wrote:
 在 2013-04-24三的 08:05 +0100,Peter Maydell写道:
 On 24 April 2013 02:48, liguang lig.f...@cn.fujitsu.com wrote:
  Signed-off-by: liguang lig.f...@cn.fujitsu.com

 I'm afraid this is definitely wrong. It has a less than
 helpful name, but cs_base is actually just another 32/64 bits
 of state that the target can use to distinguish translation
 blocks, and some non-x86 targets do use it. For instance:

 only sparc use it as a tmp buffer for pc.

And x86 uses it. And tomorrow anybody could submit a patch
to another target which makes use of it, if they find they
need to do something and there's not enough room left in
'flags'. It's a generic mechanism which happens to be used
by two targets today.

  --- a/target-sparc/cpu.h
  +++ b/target-sparc/cpu.h
  @@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
   #define TB_FLAG_AM_ENABLED (1  5)
 
   static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong 
  *pc,
  -target_ulong *cs_base, int *flags)
  +int *flags)
   {
   *pc = env-pc;
   *cs_base = env-npc;

 ...surely this doesn't even compile after your changes?


 seems no problem for me.

You clearly have a problem with your compile and test
process then, because it is clear from the patch that
you've removed the cs_base argument from this function
but the function still has a use of 'cs_base' in it.

-- PMM



Re: [Qemu-devel] [PATCH 1/2] cpu-exec: rid cs_base of TranslationBlock

2013-04-24 Thread Peter Maydell
On 24 April 2013 08:25, li guang lig.f...@cn.fujitsu.com wrote:
 在 2013-04-24三的 09:11 +0200,Aurelien Jarno写道:
 On Wed, Apr 24, 2013 at 08:36:54AM +0200, Paolo Bonzini wrote:
  Il 24/04/2013 03:48, liguang ha scritto:
   cs_base is only meaningful for target-i386/sparc,
   so, get rid of cs_base for other target
 
  This is really ugly, we're trying to get less target-dependent code
  outside target-*, not more.

 I think it's easy to be arch independent by just
 call a generic function

We already have that, this is exactly what the target
cpu_get_tb_cpu_state() function is for! It abstracts
away the target's specific use of these fields, so the
common code can treat it as an opaque blob of state.

 I'm not going to assume that (maybe it's the fact),
 I did some random tests, seems break nothing.

You have absolutely broken things here -- if your random
tests didn't identify what then your testing process was
just not solid enough to find the corner cases.

-- PMM



Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread li guang
在 2013-04-24三的 08:28 +0100,Peter Maydell写道:
 On 24 April 2013 08:15, li guang lig.f...@cn.fujitsu.com wrote:
  在 2013-04-24三的 08:05 +0100,Peter Maydell写道:
  On 24 April 2013 02:48, liguang lig.f...@cn.fujitsu.com wrote:
   Signed-off-by: liguang lig.f...@cn.fujitsu.com
 
  I'm afraid this is definitely wrong. It has a less than
  helpful name, but cs_base is actually just another 32/64 bits
  of state that the target can use to distinguish translation
  blocks, and some non-x86 targets do use it. For instance:
 
  only sparc use it as a tmp buffer for pc.
 
 And x86 uses it. And tomorrow anybody could submit a patch
 to another target which makes use of it, if they find they
 need to do something and there's not enough room left in
 'flags'. It's a generic mechanism which happens to be used
 by two targets today.

I think even others want to use something like you said,
it should not 'cs_base', or, it's a bad name.

 
   --- a/target-sparc/cpu.h
   +++ b/target-sparc/cpu.h
   @@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
#define TB_FLAG_AM_ENABLED (1  5)
  
static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, 
   target_ulong *pc,
   -target_ulong *cs_base, int 
   *flags)
   +int *flags)
{
*pc = env-pc;
*cs_base = env-npc;
 
  ...surely this doesn't even compile after your changes?
 
 
  seems no problem for me.
 
 You clearly have a problem with your compile and test
 process then, because it is clear from the patch that
 you've removed the cs_base argument from this function
 but the function still has a use of 'cs_base' in it.

???, sorry, where do I miss 'cs_base' removing?

 
 -- PMM





Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread Peter Maydell
On 24 April 2013 08:32, li guang lig.f...@cn.fujitsu.com wrote:
 I think even others want to use something like you said,
 it should not 'cs_base', or, it's a bad name.

Yes, this is why I said has a less than helpful name.


   --- a/target-sparc/cpu.h
   +++ b/target-sparc/cpu.h
   @@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
#define TB_FLAG_AM_ENABLED (1  5)
  
static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, 
   target_ulong *pc,
   -target_ulong *cs_base, int 
   *flags)
   +int *flags)
{
*pc = env-pc;
*cs_base = env-npc;

 You clearly have a problem with your compile and test
 process then, because it is clear from the patch that
 you've removed the cs_base argument from this function
 but the function still has a use of 'cs_base' in it.

 ???, sorry, where do I miss 'cs_base' removing?

Last quoted line of source: *cs_base = env-npc.

-- PMM



Re: [Qemu-devel] [PATCH 0/3] block: block-backup live backup command

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 10:49:35AM -0600, Eric Blake wrote:
 On 04/23/2013 10:25 AM, Stefan Hajnoczi wrote:
  This series adds a new QMP command, block-backup, which takes a 
  point-in-time
  snapshot of a block device.  The snapshot is copied out to a target block
  device.  A simple example is:
  
block-backup device=virtio0 format=qcow2 target=backup-20130401.qcow2
 
  What's next for block-backup?
  -
  The following enhancements are left for future patches:
  
  1. QMP 'transaction' support.  It is handy to atomically snapshot multiple
 block devices.  We need qmp_transaction() support for this.  Wenchao Xia 
  is
 currently making qmp_transaction() extensible so new action types, like
 block-backup, can be added.
  
  2. Sync modes like drive-mirror (top, full, none).  This makes it possible 
  to
 preserve the backing file chain.
 
 Based on today's phone call, it sounds like this would mean adding
 optional parameters to the QMP command.  We already did that for
 drive-mirror (1.4 has more parameters than 1.3), but without a way to
 introspect when those parameters are available, the new parameters
 aren't quite as useful.  So we don't repeat that mistake, we need to
 decide whether this should still go into 1.5 with a plan of adding
 parameters for 1.6, or whether we should add a counterpart query-*
 command that makes it easy to determine how much of block-backup is
 supported, or [your suggestion here]

I have ideas for the QMP optional parameters discussion that I'll share
in another thread.

It's not a problem in this case because block-backup and the sync mode
optional parameter will be added in the 1.6 release cycle.

In other words, since QMP is versioned by QEMU release number it's fine
to have multiple commits that build up a QMP command - as long as they
fall within the same release.

Stefan



Re: [Qemu-devel] [PATCH 2/2] target-*/cpu.h: remove cs_base for other targets

2013-04-24 Thread li guang
在 2013-04-24三的 08:36 +0100,Peter Maydell写道:
 On 24 April 2013 08:32, li guang lig.f...@cn.fujitsu.com wrote:
  I think even others want to use something like you said,
  it should not 'cs_base', or, it's a bad name.
 
 Yes, this is why I said has a less than helpful name.
 
 
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -715,7 +715,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env);
 #define TB_FLAG_AM_ENABLED (1  5)
   
 static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, 
target_ulong *pc,
-target_ulong *cs_base, int 
*flags)
+int *flags)
 {
 *pc = env-pc;
 *cs_base = env-npc;
 
  You clearly have a problem with your compile and test
  process then, because it is clear from the patch that
  you've removed the cs_base argument from this function
  but the function still has a use of 'cs_base' in it.
 
  ???, sorry, where do I miss 'cs_base' removing?
 
 Last quoted line of source: *cs_base = env-npc.

OK, thanks!
that remove by overshoot script!





Re: [Qemu-devel] [PATCH v6 01/20] tcg-arm: Fix local stack frame

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:33PM -0700, Richard Henderson wrote:
 We were not allocating TCG_STATIC_CALL_ARGS_SIZE, so this meant that
 any helper with more than 4 arguments would clobber the saved regs.
 Realizing that we're supposed to have this memory pre-allocated means
 we can clean up the tcg_out_arg functions, which were trying to do
 more stack allocation.
 
 Allocate stack memory for the TCG temporaries while we're at it.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tcg/arm/tcg-target.c | 121 
 ---
  1 file changed, 47 insertions(+), 74 deletions(-)
 
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index 94c6ca4..eda6749 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -1017,64 +1017,35 @@ static const void * const qemu_st_helpers[4] = {
   * argreg is where we want to put this argument, arg is the argument itself.
   * Return value is the updated argreg ready for the next call.
   * Note that argreg 0..3 is real registers, 4+ on stack.
 - * When we reach the first stacked argument, we allocate space for it
 - * and the following stacked arguments using str r8, [sp, #-0x10]!.
 - * Following arguments are filled in with str r8, [sp, #0xNN].
 - * For more than 4 stacked arguments we'd need to know how much
 - * space to allocate when we pushed the first stacked argument.
 - * We don't need this, so don't implement it (and will assert if you try it.)
   *
   * We provide routines for arguments which are: immediate, 32 bit
   * value in register, 16 and 8 bit values in register (which must be zero
   * extended before use) and 64 bit value in a lo:hi register pair.
   */
 -#define DEFINE_TCG_OUT_ARG(NAME, ARGPARAM) \
 -static TCGReg NAME(TCGContext *s, TCGReg argreg, ARGPARAM) \
 -{  \
 -if (argreg  4) {  \
 -TCG_OUT_ARG_GET_ARG(argreg);   \
 -} else if (argreg == 4) {  \
 -TCG_OUT_ARG_GET_ARG(TCG_REG_R8);   \
 -tcg_out32(s, (COND_AL  28) | 0x052d8010);\
 -} else {   \
 -assert(argreg  8);\
 -TCG_OUT_ARG_GET_ARG(TCG_REG_R8);   \
 -tcg_out32(s, (COND_AL  28) | 0x058d8000 | (argreg - 4) * 4); \
 -}  \
 -return argreg + 1; \
 -}
 -
 -#define TCG_OUT_ARG_GET_ARG(A) tcg_out_dat_imm(s, COND_AL, ARITH_MOV, A, 0, 
 arg)
 -DEFINE_TCG_OUT_ARG(tcg_out_arg_imm32, uint32_t arg)
 -#undef TCG_OUT_ARG_GET_ARG
 -#define TCG_OUT_ARG_GET_ARG(A) tcg_out_ext8u(s, COND_AL, A, arg)
 -DEFINE_TCG_OUT_ARG(tcg_out_arg_reg8, TCGReg arg)
 -#undef TCG_OUT_ARG_GET_ARG
 -#define TCG_OUT_ARG_GET_ARG(A) tcg_out_ext16u(s, COND_AL, A, arg)
 -DEFINE_TCG_OUT_ARG(tcg_out_arg_reg16, TCGReg arg)
 -#undef TCG_OUT_ARG_GET_ARG
 -
 -/* We don't use the macro for this one to avoid an unnecessary reg-reg
 - * move when storing to the stack.
 - */
 -static TCGReg tcg_out_arg_reg32(TCGContext *s, TCGReg argreg, TCGReg arg)
 -{
 -if (argreg  4) {
 -tcg_out_mov_reg(s, COND_AL, argreg, arg);
 -} else if (argreg == 4) {
 -/* str arg, [sp, #-0x10]! */
 -tcg_out32(s, (COND_AL  28) | 0x052d0010 | (arg  12));
 -} else {
 -assert(argreg  8);
 -/* str arg, [sp, #0xNN] */
 -tcg_out32(s, (COND_AL  28) | 0x058d |
 -  (arg  12) | (argreg - 4) * 4);
 -}
 -return argreg + 1;
 -}
 -
 -static inline TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg,
 -   TCGReg arglo, TCGReg arghi)
 +#define DEFINE_TCG_OUT_ARG(NAME, ARGTYPE, MOV_ARG, EXT_ARG)\
 +static TCGReg NAME(TCGContext *s, TCGReg argreg, ARGTYPE arg)  \
 +{  \
 +if (argreg  4) {  \
 +MOV_ARG(s, COND_AL, argreg, arg);  \
 +} else {   \
 +int ofs = (argreg - 4) * 4;\
 +EXT_ARG;   \
 +assert(ofs + 4 = TCG_STATIC_CALL_ARGS_SIZE);  \
 +tcg_out_st32_12(s, COND_AL, arg, TCG_REG_CALL_STACK, ofs); \
 +}  \
 +return argreg + 1; \
 +}
 +
 

Re: [Qemu-devel] [PATCH v6 19/20] tcg-arm: Convert to CONFIG_QEMU_LDST_OPTIMIZATION

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:51PM -0700, Richard Henderson wrote:
 Move the slow path out of line, as the TODO's mention.
 This allows the fast path to be unconditional, which can
 speed up the fast path as well, depending on the core.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  configure   |   2 +-
  include/exec/exec-all.h |  17 +++
  tcg/arm/tcg-target.c| 309 
 +++-
  3 files changed, 220 insertions(+), 108 deletions(-)
 
 diff --git a/configure b/configure
 index 51a6c56..ececfe2 100755
 --- a/configure
 +++ b/configure
 @@ -3616,7 +3616,7 @@ echo libs_softmmu=$libs_softmmu  $config_host_mak
  echo ARCH=$ARCH  $config_host_mak
  
  case $cpu in
 -  i386|x86_64|ppc)
 +  arm|i386|x86_64|ppc)
  # The TCG interpreter currently does not support ld/st optimization.
  if test $tcg_interpreter = no ; then
  echo CONFIG_QEMU_LDST_OPTIMIZATION=y  $config_host_mak
 diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
 index e856191..6362074 100644
 --- a/include/exec/exec-all.h
 +++ b/include/exec/exec-all.h
 @@ -338,6 +338,23 @@ extern uintptr_t tci_tb_ptr;
  # elif defined (_ARCH_PPC)  !defined (_ARCH_PPC64)
  #  define GETRA() ((uintptr_t)__builtin_return_address(0))
  #  define GETPC_LDST() ((uintptr_t) ((*(int32_t *)(GETRA() - 4)) - 1))
 +# elif defined(__arm__)
 +/* We define two insns between the return address and the branch back to
 +   straight-line.  Find and decode that branch insn.  */
 +#  define GETRA()   ((uintptr_t)__builtin_return_address(0))
 +#  define GETPC_LDST()  tcg_getpc_ldst(GETRA())
 +static inline uintptr_t tcg_getpc_ldst(uintptr_t ra)
 +{
 +int32_t b;
 +ra += 8;/* skip the two insns */
 +b = *(int32_t *)ra; /* load the branch insn */
 +b = (b  8)  (8 - 2);/* extract the displacement */
 +ra += 8;/* branches are relative to pc+8 */
 +ra += b;/* apply the displacement */
 +ra -= 4;/* return a pointer into the current opcode,
 +   not the start of the next opcode  */
 +return ra;
 +}
  # else
  #  error CONFIG_QEMU_LDST_OPTIMIZATION needs GETPC_LDST() implementation!
  # endif
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index eb697f2..d6afa2f 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -419,6 +419,20 @@ static inline void tcg_out_dat_reg(TCGContext *s,
  (rn  16) | (rd  12) | shift | rm);
  }
  
 +static inline void tcg_out_nop(TCGContext *s)
 +{
 +if (use_armv7_instructions) {
 +/* Architected nop introduced in v6k.  */
 +/* ??? This is an MSR (imm) 0,0,0 insn.  Anyone know if this
 +   also Just So Happened to do nothing on pre-v6k so that we
 +   don't need to conditionalize it?  */
 +tcg_out32(s, 0xe320f000);
 +} else {
 +/* Prior to that the assembler uses mov r0, r0.  */
 +tcg_out_dat_reg(s, COND_AL, ARITH_MOV, 0, 0, 0, SHIFT_IMM_LSL(0));
 +}
 +}
 +
  static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm)
  {
  /* Simple reg-reg move, optimising out the 'do nothing' case */
 @@ -1200,6 +1214,134 @@ static void tcg_out_tlb_read(TCGContext *s, TCGReg 
 addrlo, TCGReg addrhi,
  TCG_REG_R1, addrhi, SHIFT_IMM_LSL(0));
  }
  }
 +
 +/* Record the context of a call to the out of line helper code for the slow
 +   path for a load or store, so that we can later generate the correct
 +   helper code.  */
 +static void add_qemu_ldst_label(TCGContext *s, int is_ld, int opc,
 +int data_reg, int data_reg2, int addrlo_reg,
 +int addrhi_reg, int mem_index,
 +uint8_t *raddr, uint8_t *label_ptr)
 +{
 +int idx;
 +TCGLabelQemuLdst *label;
 +
 +if (s-nb_qemu_ldst_labels = TCG_MAX_QEMU_LDST) {
 +tcg_abort();
 +}
 +
 +idx = s-nb_qemu_ldst_labels++;
 +label = (TCGLabelQemuLdst *)s-qemu_ldst_labels[idx];
 +label-is_ld = is_ld;
 +label-opc = opc;
 +label-datalo_reg = data_reg;
 +label-datahi_reg = data_reg2;
 +label-addrlo_reg = addrlo_reg;
 +label-addrhi_reg = addrhi_reg;
 +label-mem_index = mem_index;
 +label-raddr = raddr;
 +label-label_ptr[0] = label_ptr;
 +}
 +
 +static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
 +{
 +TCGReg argreg, data_reg, data_reg2;
 +uint8_t *start;
 +
 +reloc_pc24(lb-label_ptr[0], (tcg_target_long)s-code_ptr);
 +
 +argreg = tcg_out_arg_reg32(s, TCG_REG_R0, TCG_AREG0);
 +if (TARGET_LONG_BITS == 64) {
 +argreg = tcg_out_arg_reg64(s, argreg, lb-addrlo_reg, 
 lb-addrhi_reg);
 +} else {
 +argreg = tcg_out_arg_reg32(s, argreg, lb-addrlo_reg);
 +}
 +argreg = tcg_out_arg_imm32(s, argreg, lb-mem_index);
 +

Re: [Qemu-devel] [PATCH v6 09/20] tcg-arm: Implement deposit for armv7

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:41PM -0700, Richard Henderson wrote:
 We have BFI and BFC available for implementing it.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tcg/arm/tcg-target.c | 41 ++---
  tcg/arm/tcg-target.h |  5 -
  2 files changed, 42 insertions(+), 4 deletions(-)
 
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index dfcc8e6..09f11e1 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -145,9 +145,10 @@ static void patch_reloc(uint8_t *code_ptr, int type,
  }
  }
  
 -#define TCG_CT_CONST_ARM 0x100
 -#define TCG_CT_CONST_INV 0x200
 -#define TCG_CT_CONST_NEG 0x400
 +#define TCG_CT_CONST_ARM  0x100
 +#define TCG_CT_CONST_INV  0x200
 +#define TCG_CT_CONST_NEG  0x400
 +#define TCG_CT_CONST_ZERO 0x800
  
  /* parse target specific constraints */
  static int target_parse_constraint(TCGArgConstraint *ct, const char 
 **pct_str)
 @@ -165,6 +166,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, 
 const char **pct_str)
  case 'N': /* The gcc constraint letter is L, already used here.  */
  ct-ct |= TCG_CT_CONST_NEG;
  break;
 +case 'Z':
 +ct-ct |= TCG_CT_CONST_ZERO;
 +break;
  
  case 'r':
  ct-ct |= TCG_CT_REG;
 @@ -297,6 +301,8 @@ static inline int tcg_target_const_match(tcg_target_long 
 val,
  return 1;
  } else if ((ct  TCG_CT_CONST_NEG)  check_fit_imm(-val)) {
  return 1;
 +} else if ((ct  TCG_CT_CONST_ZERO)  val == 0) {
 +return 1;
  } else {
  return 0;
  }
 @@ -702,6 +708,28 @@ static inline void tcg_out_bswap32(TCGContext *s, int 
 cond, int rd, int rn)
  }
  }
  
 +bool tcg_target_deposit_valid(int ofs, int len)
 +{
 +/* ??? Without bfi, we could improve over generic code by combining
 +   the right-shift from a non-zero ofs with the orr.  We do run into
 +   problems when rd == rs, and the mask generated from ofs+len doesn't
 +   fit into an immediate.  We would have to be careful not to pessimize
 +   wrt the optimizations performed on the expanded code.  */
 +return use_armv7_instructions;
 +}
 +
 +static inline void tcg_out_deposit(TCGContext *s, int cond, TCGReg rd,
 +   TCGArg a1, int ofs, int len, bool 
 const_a1)
 +{
 +if (const_a1) {
 +/* bfi becomes bfc with rn == 15.  */
 +a1 = 15;
 +}
 +/* bfi/bfc */
 +tcg_out32(s, 0x07c00010 | (cond  28) | (rd  12) | a1
 +  | (ofs  7) | ((ofs + len - 1)  16));
 +}
 +
  static inline void tcg_out_ld32_12(TCGContext *s, int cond,
  int rd, int rn, tcg_target_long im)
  {
 @@ -1835,6 +1863,11 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode 
 opc,
  tcg_out_ext16u(s, COND_AL, args[0], args[1]);
  break;
  
 +case INDEX_op_deposit_i32:
 +tcg_out_deposit(s, COND_AL, args[0], args[2],
 +args[3], args[4], const_args[2]);
 +break;
 +
  default:
  tcg_abort();
  }
 @@ -1919,6 +1952,8 @@ static const TCGTargetOpDef arm_op_defs[] = {
  { INDEX_op_ext16s_i32, { r, r } },
  { INDEX_op_ext16u_i32, { r, r } },
  
 +{ INDEX_op_deposit_i32, { r, 0, rZ } },
 +
  { -1 },
  };
  
 diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
 index 354dd8a..209f585 100644
 --- a/tcg/arm/tcg-target.h
 +++ b/tcg/arm/tcg-target.h
 @@ -71,10 +71,13 @@ typedef enum {
  #define TCG_TARGET_HAS_eqv_i32  0
  #define TCG_TARGET_HAS_nand_i32 0
  #define TCG_TARGET_HAS_nor_i32  0
 -#define TCG_TARGET_HAS_deposit_i32  0
 +#define TCG_TARGET_HAS_deposit_i32  1
  #define TCG_TARGET_HAS_movcond_i32  1
  #define TCG_TARGET_HAS_muls2_i321
  
 +extern bool tcg_target_deposit_valid(int ofs, int len);
 +#define TCG_TARGET_deposit_i32_valid  tcg_target_deposit_valid
 +
  enum {
  TCG_AREG0 = TCG_REG_R6,
  };

Reviewed-by: Aurelien Jarno aurel...@aurel32.net

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH v6 16/20] tcg-arm: Improve scheduling of tcg_out_tlb_read

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:48PM -0700, Richard Henderson wrote:
 The schedule was fully serial, with no possibility for dual issue.
 The old schedule had a minimal issue of 7 cycles; the new schedule
 has a minimal issue of 5 cycles.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tcg/arm/tcg-target.c | 110 
 ++-
  1 file changed, 57 insertions(+), 53 deletions(-)
 
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index a96471c..375c1e1 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -182,18 +182,12 @@ static int target_parse_constraint(TCGArgConstraint 
 *ct, const char **pct_str)
  ct-ct |= TCG_CT_REG;
  tcg_regset_set32(ct-u.regs, 0, (1  TCG_TARGET_NB_REGS) - 1);
  #ifdef CONFIG_SOFTMMU
 -/* r0 and r1 will be overwritten when reading the tlb entry,
 +/* r0-r2 will be overwritten when reading the tlb entry,
 so don't use these. */
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R0);
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R1);
 -#if TARGET_LONG_BITS == 64
 -/* If we're passing env to the helper as r0 and need a regpair
 - * for the address then r2 will be overwritten as we're setting
 - * up the args to the helper.
 - */
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R2);
  #endif
 -#endif
  break;
  case 'L':
  ct-ct |= TCG_CT_REG;
 @@ -207,30 +201,16 @@ static int target_parse_constraint(TCGArgConstraint 
 *ct, const char **pct_str)
  
  /* qemu_st address  data_reg */
  case 's':
 -ct-ct |= TCG_CT_REG;
 -tcg_regset_set32(ct-u.regs, 0, (1  TCG_TARGET_NB_REGS) - 1);
 -/* r0 and r1 will be overwritten when reading the tlb entry
 -   (softmmu only) and doing the byte swapping, so don't
 -   use these. */
 -tcg_regset_reset_reg(ct-u.regs, TCG_REG_R0);
 -tcg_regset_reset_reg(ct-u.regs, TCG_REG_R1);
 -#if defined(CONFIG_SOFTMMU)  (TARGET_LONG_BITS == 64)
 -/* Avoid clashes with registers being used for helper args */
 -tcg_regset_reset_reg(ct-u.regs, TCG_REG_R2);
 -tcg_regset_reset_reg(ct-u.regs, TCG_REG_R3);
 -#endif
 -break;
  /* qemu_st64 data_reg2 */
  case 'S':
  ct-ct |= TCG_CT_REG;
  tcg_regset_set32(ct-u.regs, 0, (1  TCG_TARGET_NB_REGS) - 1);
 -/* r0 and r1 will be overwritten when reading the tlb entry
 -(softmmu only) and doing the byte swapping, so don't
 -use these. */
 +/* r0-r2 will be overwritten when reading the tlb entry (softmmu 
 only)
 +   and r0-r1 doing the byte swapping, so don't use these. */
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R0);
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R1);
 -#ifdef CONFIG_SOFTMMU
 -/* r2 is still needed to load data_reg, so don't use it. */
 +#if defined(CONFIG_SOFTMMU)
 +/* Avoid clashes with registers being used for helper args */
  tcg_regset_reset_reg(ct-u.regs, TCG_REG_R2);
  #if TARGET_LONG_BITS == 64
  /* Avoid clashes with registers being used for helper args */
 @@ -347,6 +327,8 @@ typedef enum {
  INSN_LDRSB_REG = 0x001000d0,
  INSN_STRB_IMM  = 0x0440,
  INSN_STRB_REG  = 0x0640,
 +
 +INSN_LDRD_IMM  = 0x004000d0,
  } ARMInsn;
  
  #define SHIFT_IMM_LSL(im)(((im)  7) | 0x00)
 @@ -805,15 +787,6 @@ static inline void tcg_out_ld32_12(TCGContext *s, int 
 cond, TCGReg rt,
  tcg_out_memop_12(s, cond, INSN_LDR_IMM, rt, rn, imm12, 1, 0);
  }
  
 -/* Offset pre-increment with base writeback.  */
 -static inline void tcg_out_ld32_12wb(TCGContext *s, int cond, TCGReg rt,
 - TCGReg rn, int imm12)
 -{
 -/* ldr with writeback and both register equals is UNPREDICTABLE */
 -assert(rd != rn);
 -tcg_out_memop_12(s, cond, INSN_LDR_IMM, rt, rn, imm12, 1, 1);
 -}
 -
  static inline void tcg_out_st32_12(TCGContext *s, int cond, TCGReg rt,
 TCGReg rn, int imm12)
  {
 @@ -1150,47 +1123,78 @@ static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg 
 argreg,
  
  #define TLB_SHIFT(CPU_TLB_ENTRY_BITS + CPU_TLB_BITS)
  
 -/* Load and compare a TLB entry, leaving the flags set.  Leaves R0 pointing
 +/* Load and compare a TLB entry, leaving the flags set.  Leaves R2 pointing
 to the tlb entry.  Clobbers R1 and TMP.  */
  
  static void tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
   int s_bits, int tlb_offset)
  {
 +TCGReg base = TCG_AREG0;
 +
  /* Should generate something like the following:
 - *  shr r8, addr_reg, #TARGET_PAGE_BITS
 - *  and r0, r8, #(CPU_TLB_SIZE - 1)   @ Assumption: CPU_TLB_BITS = 8
 - *  add r0, env, r0 lsl #CPU_TLB_ENTRY_BITS
 + * pre-v7:
 + *   shrtmp, addr_reg, #TARGET_PAGE_BITS  (1)
 + *   addr2, env, #off  0xff00
 +

Re: [Qemu-devel] [PATCH v6 17/20] tcg-arm: Delete the 'S' constraint

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:49PM -0700, Richard Henderson wrote:
 After the previous patch, 's' and 'S' are the same.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tcg/arm/tcg-target.c | 6 ++
  1 file changed, 2 insertions(+), 4 deletions(-)
 
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index 375c1e1..5fa3cb1 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -201,8 +201,6 @@ static int target_parse_constraint(TCGArgConstraint *ct, 
 const char **pct_str)
  
  /* qemu_st address  data_reg */
  case 's':
 -/* qemu_st64 data_reg2 */
 -case 'S':
  ct-ct |= TCG_CT_REG;
  tcg_regset_set32(ct-u.regs, 0, (1  TCG_TARGET_NB_REGS) - 1);
  /* r0-r2 will be overwritten when reading the tlb entry (softmmu 
 only)
 @@ -1928,7 +1926,7 @@ static const TCGTargetOpDef arm_op_defs[] = {
  { INDEX_op_qemu_st8, { s, s } },
  { INDEX_op_qemu_st16, { s, s } },
  { INDEX_op_qemu_st32, { s, s } },
 -{ INDEX_op_qemu_st64, { S, S, s } },
 +{ INDEX_op_qemu_st64, { s, s, s } },
  #else
  { INDEX_op_qemu_ld8u, { r, l, l } },
  { INDEX_op_qemu_ld8s, { r, l, l } },
 @@ -1940,7 +1938,7 @@ static const TCGTargetOpDef arm_op_defs[] = {
  { INDEX_op_qemu_st8, { s, s, s } },
  { INDEX_op_qemu_st16, { s, s, s } },
  { INDEX_op_qemu_st32, { s, s, s } },
 -{ INDEX_op_qemu_st64, { S, S, s, s } },
 +{ INDEX_op_qemu_st64, { s, s, s, s } },
  #endif
  
  { INDEX_op_bswap16_i32, { r, r } },

Reviewed-by: Aurelien Jarno aurel...@aurel32.net

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH v6 20/20] tcg-arm: Remove long jump from tcg_out_goto_label

2013-04-24 Thread Aurelien Jarno
On Tue, Apr 23, 2013 at 01:46:52PM -0700, Richard Henderson wrote:
 Branches within a TB will always be within 16MB.
 
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tcg/arm/tcg-target.c | 7 +--
  1 file changed, 1 insertion(+), 6 deletions(-)
 
 diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
 index d6afa2f..7216f7a 100644
 --- a/tcg/arm/tcg-target.c
 +++ b/tcg/arm/tcg-target.c
 @@ -1055,14 +1055,9 @@ static inline void tcg_out_goto_label(TCGContext *s, 
 int cond, int label_index)
  {
  TCGLabel *l = s-labels[label_index];
  
 -if (l-has_value)
 +if (l-has_value) {
  tcg_out_goto(s, cond, l-u.value);
 -else if (cond == COND_AL) {
 -tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4);
 -tcg_out_reloc(s, s-code_ptr, R_ARM_ABS32, label_index, 31337);
 -s-code_ptr += 4;
  } else {
 -/* Probably this should be preferred even for COND_AL... */
  tcg_out_reloc(s, s-code_ptr, R_ARM_PC24, label_index, 31337);
  tcg_out_b_noaddr(s, cond);
  }

Reviewed-by: Aurelien Jarno aurel...@aurel32.net

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] KVM call minutes for 2013-04-23

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 10:06:41AM -0600, Eric Blake wrote:
 On 04/23/2013 08:45 AM, Juan Quintela wrote:
we can change drive_mirror to use a new command to see if there
are the new features.
 
 drive-mirror changed in 1.4 to add optional buf-size parameter; right
 now, libvirt is forced to limit itself to 1.3 interface (no buf-size or
 granularity) because there is no introspection and no query-* command
 that witnesses that the feature is present.  Idea was that we need to
 add a new query-drive-mirror-capabilities (name subject to bikeshedding)
 command into 1.5 that would let libvirt know that buf-size/granularity
 is usable (done right, it would also prevent the situation of buf-size
 being a write-only interface where it is set when starting the mirror
 but can not be queried later to see what size is in use).
 
 Unclear whether anyone was signing up to tackle the addition of a query
 command counterpart for drive-mirror in time for 1.5.

Seems like the trivial solution is a query-command-capabilities QMP
command.

  query-command-capabilities drive-mirror
  = ['buf-size']

It should only be a few lines of code and can be used for other commands
that add optional parameters in the future.  In other words:

typedef struct mon_cmd_t {
...
const char **capabilities; /* drive-mirror uses [buf-size, NULL] */
};

  
if we have a stable c-api we can do test cases that work. 
 
 Having such a testsuite would make a stable C API more important.

Writing tests in Python has been productive, see qemu-iotests 041 and
friends.  The tests spawn QEMU guests and use QMP to interact:

  result = self.vm.qmp('query-block')
  self.assert_qmp(result, 'return[0]/inserted/file', target_img)

Using this XPath-style syntax it's very easy to access the JSON.

QEMU users tend not to use C, except libvirt.  Even libvirt implements
the QMP protocol dynamically and can handle optional arguments well.

I don't think a static C API makes sense when we have an extensible JSON
protocol.  Let's use the extensibility to our advantage.

Stefan



[Qemu-devel] [PULL] libcacard and ccid fixes

2013-04-24 Thread Alon Levy
The following changes since commit bb71623811686ce3c34ce724f073f5c5dd95f51b:

  Move TPM passthrough specific command line options to backend structure 
(2013-04-23 10:40:40 -0500)

are available in the git repository at:

  git://people.freedesktop.org/~alon/qemu libcacard_ccid.1

for you to fetch changes up to 203a368e66f5211b832e17b85c6f5dacfc8d7bf9:

  libcacard/cac: change big switch functions to single return point (2013-04-24 
10:57:48 +0300)


Alon Levy (15):
  dev-smartcard-reader: white space fixes
  dev-smartcard-reader: nicer debug messages
  dev-smartcard-reader: remove aborts (never triggered, but just in case)
  dev-smartcard-reader: support windows guest
  dev-smartcard-reader: reuse usb.h definitions
  libcacard: change default ATR
  ccid-card-passthru: add atr check
  ccid-card-passthru, dev-smartcard-reader: add debug environment variables
  dev-smartcard-reader: define structs for CCID_Parameter internals
  dev-smartcard-reader: change default protocol to T=0
  dev-smartcard-reader: copy atr protocol to ccid parameters
  libcacard/vreader: add debugging messages for apdu
  libcacard: move atr setting from macro to function
  dev-smartcard-reader: empty implementation for Mechanical (fail correctly)
  libcacard/cac: change big switch functions to single return point

Jim Meyering (2):
  ccid: make backend_enum_table static const and adjust users
  ccid: declare DEFAULT_ATR table to be static const

Marc-André Lureau (11):
  libcacard: correct T0 historical bytes size
  ccid-card-emul: do not crash if backend is not provided
  libcacard: use system config directory for nss db on win32
  util: move socket_init() to osdep.c
  build-sys: must link with -fstack-protector
  libcacard: fix mingw64 cross-compilation
  libcacard: split vscclient main() from socket reading
  libcacard: vscclient to use QemuThread for portability
  libcacard: teach vscclient to use GMainLoop for portability
  libcacard: remove sql: prefix
  libcacard: remove default libcoolkey loading

 Makefile  |   8 +-
 Makefile.objs |   1 +
 configure |   8 +-
 hw/usb/ccid-card-emulated.c   |   9 +-
 hw/usb/ccid-card-passthru.c   |  63 +-
 hw/usb/dev-smartcard-reader.c | 243 +++-
 include/qemu-common.h |   5 +
 libcacard/cac.c   |  80 ---
 libcacard/cac.h   |   8 +
 libcacard/vcard_emul_nss.c|  47 ++--
 libcacard/vcardt.c|  40 
 libcacard/vcardt.h|   5 -
 libcacard/vcardt_internal.h   |   6 +
 libcacard/vreader.c   |  77 +++
 libcacard/vscclient.c | 506 +-
 rules.mak |   4 +-
 util/cutils.c |  23 ++
 util/osdep.c  |  23 ++
 util/qemu-sockets.c   |  24 --
 19 files changed, 838 insertions(+), 342 deletions(-)
 create mode 100644 libcacard/vcardt.c
 create mode 100644 libcacard/vcardt_internal.h



[Qemu-devel] [PATCH RESEND v4 0/8] virtio-rng refactoring.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Tested-by: Cornelia Huck cornelia.h...@de.ibm.com
Acked-by: Amit Shah amit.s...@redhat.com

There are no modifications, just rebased.

This is the last backend of the refactoring (*and must be applied at last,
because it would break virtio-9p*).

Basically it creates virtio-rng-device which extends virtio-device.
Then a virtio-rng-device can be connected on a virtio-bus.
virtio-rng-pci, virtio-rng-s390, virtio-rng-ccw are created too, they extend
respectively virtio-pci, virtio-s390-device, virtio-ccw-device and have a
virtio-rng-device.

When rng option is NULL, a default rng backend is created as before. But after
this refactoring, this default-backend will be the child of virtio-rng-device
instead of virtio-rng-*.

You can checkout my branch here:

git://project.greensocs.com/qemu-virtio.git virtio-rng-v4

Note that it is nearly the same series as virtio-blk and virtio-scsi
refactoring, and is rebased on top of virtio-9p-v4 I posted before.

I made basic tests (with linux guests) on:
 * qemu-system-i386

Cornelia tested it on s390 and ccw.

Changes v3 - v4:
* Remove some QOM casts on opaque.
* Fix the commit message of the last patch.
* Rebased.
Changes v2 - v3:
* Added CCW device.
* Changes name: virtio-rng = virtio-rng-device.
* Rebased.

Thanks,

Fred

KONRAD Frederic (8):
  virtio-rng: don't use pointer for configuration.
  virtio-rng: add virtio-rng device.
  virtio-rng-pci: switch to the new API.
  virtio-rng-s390: switch to the new API.
  virtio-rng-ccw: switch to the new API.
  virtio-rng: cleanup: init and exit functions.
  virtio-rng: cleanup: remove qdev field.
  virtio-rng: cleanup: use QOM casts.

 hw/s390x/s390-virtio-bus.c |  39 ++-
 hw/s390x/s390-virtio-bus.h |  12 +++-
 hw/s390x/virtio-ccw.c  |  49 ++---
 hw/s390x/virtio-ccw.h  |  12 +++-
 hw/virtio/virtio-pci.c | 156 -
 hw/virtio/virtio-pci.h |  14 +++-
 hw/virtio/virtio-rng.c | 116 +-
 include/hw/virtio/virtio-rng.h |  20 --
 include/hw/virtio/virtio.h |   2 -
 9 files changed, 239 insertions(+), 181 deletions(-)

-- 
1.7.11.7




[Qemu-devel] [PATCH RESEND v4 2/8] virtio-rng: add virtio-rng device.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

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

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390x/virtio-ccw.c  |   3 +-
 hw/virtio/virtio-pci.c |   8 +--
 hw/virtio/virtio-rng.c | 108 ++---
 include/hw/virtio/virtio-rng.h |  14 ++
 4 files changed, 117 insertions(+), 16 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 56539d3..7fdc8c3 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -958,8 +958,7 @@ static void virtio_ccw_rng_initfn(Object *obj)
 static Property virtio_ccw_rng_properties[] = {
 DEFINE_PROP_STRING(devno, VirtioCcwDevice, bus_id),
 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
-DEFINE_PROP_UINT64(max-bytes, VirtioCcwDevice, rng.max_bytes, INT64_MAX),
-DEFINE_PROP_UINT32(period, VirtioCcwDevice, rng.period_ms, 1  16),
+DEFINE_VIRTIO_RNG_PROPERTIES(VirtioCcwDevice, rng),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index a1f15a8..4860db1 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -989,13 +989,7 @@ static void virtio_rng_initfn(Object *obj)
 
 static Property virtio_rng_properties[] = {
 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-/* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s.  If
-   you have an entropy source capable of generating more entropy than this
-   and you can pass it through via virtio-rng, then hats off to you.  Until
-   then, this is unlimited for all practical purposes.
-*/
-DEFINE_PROP_UINT64(max-bytes, VirtIOPCIProxy, rng.max_bytes, INT64_MAX),
-DEFINE_PROP_UINT32(period, VirtIOPCIProxy, rng.period_ms, 1  16),
+DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 05b4d57..b70975b 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -130,17 +130,27 @@ static void check_rate_limit(void *opaque)
qemu_get_clock_ms(vm_clock) + s-conf.period_ms);
 }
 
-
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
+static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
+VirtIORNGConf *conf,
+VirtIORNG **pvrng)
 {
-VirtIORNG *vrng;
+VirtIORNG *vrng = *pvrng;
 VirtIODevice *vdev;
 Error *local_err = NULL;
 
-vdev = virtio_common_init(virtio-rng, VIRTIO_ID_RNG, 0,
-  sizeof(VirtIORNG));
-
-vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+/*
+ * We have two cases here: the old virtio-rng-x device, and the
+ * refactored virtio-rng.
+ * This will disappear later in the serie.
+ */
+if (vrng == NULL) {
+vdev = virtio_common_init(virtio-rng, VIRTIO_ID_RNG, 0,
+  sizeof(VirtIORNG));
+vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+} else {
+vdev = VIRTIO_DEVICE(vrng);
+virtio_init(vdev, virtio-rng, VIRTIO_ID_RNG, 0);
+}
 
 vrng-rng = conf-rng;
 if (vrng-rng == NULL) {
@@ -156,6 +166,7 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, 
VirtIORNGConf *conf)
 }
 
 vrng-vq = virtio_add_queue(vdev, 8, handle_input);
+
 vrng-vdev.get_features = get_features;
 
 vrng-qdev = dev;
@@ -176,6 +187,15 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, 
VirtIORNGConf *conf)
 return vdev;
 }
 
+/*
+ * This two functions will be removed later in the serie.
+ */
+VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
+{
+VirtIORNG *vdev = NULL;
+return virtio_rng_common_init(dev, conf, vdev);
+}
+
 void virtio_rng_exit(VirtIODevice *vdev)
 {
 VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
@@ -185,3 +205,77 @@ void virtio_rng_exit(VirtIODevice *vdev)
 unregister_savevm(vrng-qdev, virtio-rng, vrng);
 virtio_cleanup(vdev);
 }
+
+static int virtio_rng_device_init(VirtIODevice *vdev)
+{
+DeviceState *qdev = DEVICE(vdev);
+VirtIORNG *vrng = VIRTIO_RNG(vdev);
+
+if (vrng-conf.rng == NULL) {
+vrng-conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+object_property_add_child(OBJECT(qdev),
+  default-backend,
+  OBJECT(vrng-conf.default_backend),
+  NULL);
+
+object_property_set_link(OBJECT(qdev),
+ OBJECT(vrng-conf.default_backend),
+ rng, NULL);
+}
+
+if (virtio_rng_common_init(qdev, (vrng-conf), vrng) == NULL) {
+return -1;
+}
+return 0;
+}
+
+static int virtio_rng_device_exit(DeviceState *qdev)
+{
+VirtIORNG *vrng = 

[Qemu-devel] [PATCH RESEND v4 4/8] virtio-rng-s390: switch to the new API.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Here the virtio-rng-s390 is modified for the new API. The device
virtio-rng-s390 extends virtio-s390-device as before. It creates and
connects a virtio-rng during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390x/s390-virtio-bus.c | 39 +++
 hw/s390x/s390-virtio-bus.h | 12 +++-
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index dabbc2e..95c9275 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -262,16 +262,31 @@ static void s390_vhost_scsi_instance_init(Object *obj)
 }
 #endif
 
-static int s390_virtio_rng_init(VirtIOS390Device *dev)
+
+static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
 {
-VirtIODevice *vdev;
+VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
+DeviceState *vdev = DEVICE(dev-vdev);
 
-vdev = virtio_rng_init((DeviceState *)dev, dev-rng);
-if (!vdev) {
+qdev_set_parent_bus(vdev, BUS(s390_dev-bus));
+if (qdev_init(vdev)  0) {
 return -1;
 }
 
-return s390_virtio_device_init(dev, vdev);
+object_property_set_link(OBJECT(dev),
+ OBJECT(dev-vdev.conf.default_backend), rng,
+ NULL);
+
+return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
+
+static void s390_virtio_rng_instance_init(Object *obj)
+{
+VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
+object_initialize(OBJECT(dev-vdev), TYPE_VIRTIO_RNG);
+object_property_add_child(obj, virtio-backend, OBJECT(dev-vdev), NULL);
+object_property_add_link(obj, rng, TYPE_RNG_BACKEND,
+ (Object **)dev-vdev.conf.rng, NULL);
 }
 
 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
@@ -523,14 +538,6 @@ static const TypeInfo s390_virtio_serial = {
 .class_init= s390_virtio_serial_class_init,
 };
 
-static void s390_virtio_rng_initfn(Object *obj)
-{
-VirtIOS390Device *dev = VIRTIO_S390_DEVICE(obj);
-
-object_property_add_link(obj, rng, TYPE_RNG_BACKEND,
- (Object **)dev-rng.rng, NULL);
-}
-
 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 {
 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
@@ -539,10 +546,10 @@ static void s390_virtio_rng_class_init(ObjectClass 
*klass, void *data)
 }
 
 static const TypeInfo s390_virtio_rng = {
-.name  = virtio-rng-s390,
+.name  = TYPE_VIRTIO_RNG_S390,
 .parent= TYPE_VIRTIO_S390_DEVICE,
-.instance_size = sizeof(VirtIOS390Device),
-.instance_init = s390_virtio_rng_initfn,
+.instance_size = sizeof(VirtIORNGS390),
+.instance_init = s390_virtio_rng_instance_init,
 .class_init= s390_virtio_rng_class_init,
 };
 
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index d7c47db..991f9e2 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -93,7 +93,6 @@ struct VirtIOS390Device {
 uint8_t feat_len;
 VirtIODevice *vdev;
 uint32_t host_features;
-VirtIORNGConf rng;
 VirtioBusState bus;
 };
 
@@ -176,4 +175,15 @@ typedef struct VHostSCSIS390 {
 } VHostSCSIS390;
 #endif
 
+/* virtio-rng-s390 */
+
+#define TYPE_VIRTIO_RNG_S390 virtio-rng-s390
+#define VIRTIO_RNG_S390(obj) \
+OBJECT_CHECK(VirtIORNGS390, (obj), TYPE_VIRTIO_RNG_S390)
+
+typedef struct VirtIORNGS390 {
+VirtIOS390Device parent_obj;
+VirtIORNG vdev;
+} VirtIORNGS390;
+
 #endif
-- 
1.7.11.7




[Qemu-devel] [PATCH RESEND v4 1/8] virtio-rng: don't use pointer for configuration.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

The configuration field must not be a pointer as it will be used for
virtio-rng properties. So *conf is replaced by conf.

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

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index fcc223a..05b4d57 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -124,10 +124,10 @@ static void check_rate_limit(void *opaque)
 {
 VirtIORNG *s = opaque;
 
-s-quota_remaining = s-conf-max_bytes;
+s-quota_remaining = s-conf.max_bytes;
 virtio_rng_process(s);
 qemu_mod_timer(s-rate_limit_timer,
-   qemu_get_clock_ms(vm_clock) + s-conf-period_ms);
+   qemu_get_clock_ms(vm_clock) + s-conf.period_ms);
 }
 
 
@@ -159,16 +159,16 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, 
VirtIORNGConf *conf)
 vrng-vdev.get_features = get_features;
 
 vrng-qdev = dev;
-vrng-conf = conf;
+memcpy((vrng-conf), conf, sizeof(struct VirtIORNGConf));
 
-assert(vrng-conf-max_bytes = INT64_MAX);
-vrng-quota_remaining = vrng-conf-max_bytes;
+assert(vrng-conf.max_bytes = INT64_MAX);
+vrng-quota_remaining = vrng-conf.max_bytes;
 
 vrng-rate_limit_timer = qemu_new_timer_ms(vm_clock,
check_rate_limit, vrng);
 
 qemu_mod_timer(vrng-rate_limit_timer,
-   qemu_get_clock_ms(vm_clock) + vrng-conf-period_ms);
+   qemu_get_clock_ms(vm_clock) + vrng-conf.period_ms);
 
 register_savevm(dev, virtio-rng, -1, 1, virtio_rng_save,
 virtio_rng_load, vrng);
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index c9cadc2..c578c00 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -33,7 +33,7 @@ typedef struct VirtIORNG {
 /* Only one vq - guest puts buffer(s) on it when it needs entropy */
 VirtQueue *vq;
 
-VirtIORNGConf *conf;
+VirtIORNGConf conf;
 
 RngBackend *rng;
 
-- 
1.7.11.7




[Qemu-devel] [PATCH RESEND v4 3/8] virtio-rng-pci: switch to the new API.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Here the virtio-rng-pci is modified for the new API. The device
virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device
during the init. The properties are not changed.

The virtio_pci_reset function, is removed as no longer used.
The virtio_pci_rst function, is renamed virtio_pci_reset.

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

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 4860db1..1269a22 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -257,15 +257,6 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy 
*proxy)
 proxy-ioeventfd_started = false;
 }
 
-static void virtio_pci_reset(DeviceState *d)
-{
-VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
-virtio_pci_stop_ioeventfd(proxy);
-virtio_reset(proxy-vdev);
-msix_unuse_all_vectors(proxy-pci_dev);
-proxy-flags = ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
-}
-
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
 VirtIOPCIProxy *proxy = opaque;
@@ -943,79 +934,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
 msix_uninit_exclusive_bar(pci_dev);
 }
 
-static int virtio_rng_init_pci(PCIDevice *pci_dev)
-{
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-VirtIODevice *vdev;
-
-if (proxy-rng.rng == NULL) {
-proxy-rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-object_property_add_child(OBJECT(pci_dev),
-  default-backend,
-  OBJECT(proxy-rng.default_backend),
-  NULL);
-
-object_property_set_link(OBJECT(pci_dev),
- OBJECT(proxy-rng.default_backend),
- rng, NULL);
-}
-
-vdev = virtio_rng_init(pci_dev-qdev, proxy-rng);
-if (!vdev) {
-return -1;
-}
-virtio_init_pci(proxy, vdev);
-return 0;
-}
-
-static void virtio_rng_exit_pci(PCIDevice *pci_dev)
-{
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-virtio_pci_stop_ioeventfd(proxy);
-virtio_rng_exit(proxy-vdev);
-virtio_exit_pci(pci_dev);
-}
-
-static void virtio_rng_initfn(Object *obj)
-{
-PCIDevice *pci_dev = PCI_DEVICE(obj);
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-object_property_add_link(obj, rng, TYPE_RNG_BACKEND,
- (Object **)proxy-rng.rng, NULL);
-}
-
-static Property virtio_rng_properties[] = {
-DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_rng_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-k-init = virtio_rng_init_pci;
-k-exit = virtio_rng_exit_pci;
-k-vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-k-device_id = PCI_DEVICE_ID_VIRTIO_RNG;
-k-revision = VIRTIO_PCI_ABI_VERSION;
-k-class_id = PCI_CLASS_OTHERS;
-dc-reset = virtio_pci_reset;
-dc-props = virtio_rng_properties;
-}
-
-static const TypeInfo virtio_rng_info = {
-.name  = virtio-rng-pci,
-.parent= TYPE_PCI_DEVICE,
-.instance_size = sizeof(VirtIOPCIProxy),
-.instance_init = virtio_rng_initfn,
-.class_init= virtio_rng_class_init,
-};
-
 #ifdef CONFIG_VIRTFS
 static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
 {
@@ -1137,11 +1055,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
 virtio_exit_pci(pci_dev);
 }
 
-/*
- * This will be renamed virtio_pci_reset at the end of the series.
- * virtio_pci_reset is still in use at this moment.
- */
-static void virtio_pci_rst(DeviceState *qdev)
+static void virtio_pci_reset(DeviceState *qdev)
 {
 VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
 VirtioBusState *bus = VIRTIO_BUS(proxy-bus);
@@ -1161,7 +1075,7 @@ static void virtio_pci_class_init(ObjectClass *klass, 
void *data)
 k-vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
 k-revision = VIRTIO_PCI_ABI_VERSION;
 k-class_id = PCI_CLASS_OTHERS;
-dc-reset = virtio_pci_rst;
+dc-reset = virtio_pci_reset;
 }
 
 static const TypeInfo virtio_pci_info = {
@@ -1550,6 +1464,64 @@ static const TypeInfo virtio_net_pci_info = {
 .class_init= virtio_net_pci_class_init,
 };
 
+/* virtio-rng-pci */
+
+static Property virtio_rng_pci_properties[] = {
+DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORngPCI, vdev.conf),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_rng_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
+

[Qemu-devel] [PATCH RESEND v4 6/8] virtio-rng: cleanup: init and exit functions.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove old init and exit function as they are no longer needed.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/virtio/virtio-rng.c | 87 +++---
 include/hw/virtio/virtio.h |  2 --
 2 files changed, 21 insertions(+), 68 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index b70975b..805dd18 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -130,47 +130,45 @@ static void check_rate_limit(void *opaque)
qemu_get_clock_ms(vm_clock) + s-conf.period_ms);
 }
 
-static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
-VirtIORNGConf *conf,
-VirtIORNG **pvrng)
+static int virtio_rng_device_init(VirtIODevice *vdev)
 {
-VirtIORNG *vrng = *pvrng;
-VirtIODevice *vdev;
+DeviceState *qdev = DEVICE(vdev);
+VirtIORNG *vrng = VIRTIO_RNG(vdev);
 Error *local_err = NULL;
 
-/*
- * We have two cases here: the old virtio-rng-x device, and the
- * refactored virtio-rng.
- * This will disappear later in the serie.
- */
-if (vrng == NULL) {
-vdev = virtio_common_init(virtio-rng, VIRTIO_ID_RNG, 0,
-  sizeof(VirtIORNG));
-vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-} else {
-vdev = VIRTIO_DEVICE(vrng);
-virtio_init(vdev, virtio-rng, VIRTIO_ID_RNG, 0);
+if (vrng-conf.rng == NULL) {
+vrng-conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+object_property_add_child(OBJECT(qdev),
+  default-backend,
+  OBJECT(vrng-conf.default_backend),
+  NULL);
+
+object_property_set_link(OBJECT(qdev),
+ OBJECT(vrng-conf.default_backend),
+ rng, NULL);
 }
 
-vrng-rng = conf-rng;
+virtio_init(vdev, virtio-rng, VIRTIO_ID_RNG, 0);
+
+vrng-rng = vrng-conf.rng;
 if (vrng-rng == NULL) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, rng, a valid object);
-return NULL;
+return -1;
 }
 
 rng_backend_open(vrng-rng, local_err);
 if (local_err) {
 qerror_report_err(local_err);
 error_free(local_err);
-return NULL;
+return -1;
 }
 
 vrng-vq = virtio_add_queue(vdev, 8, handle_input);
 
 vrng-vdev.get_features = get_features;
 
-vrng-qdev = dev;
-memcpy((vrng-conf), conf, sizeof(struct VirtIORNGConf));
+vrng-qdev = qdev;
 
 assert(vrng-conf.max_bytes = INT64_MAX);
 vrng-quota_remaining = vrng-conf.max_bytes;
@@ -181,52 +179,9 @@ static VirtIODevice *virtio_rng_common_init(DeviceState 
*dev,
 qemu_mod_timer(vrng-rate_limit_timer,
qemu_get_clock_ms(vm_clock) + vrng-conf.period_ms);
 
-register_savevm(dev, virtio-rng, -1, 1, virtio_rng_save,
+register_savevm(qdev, virtio-rng, -1, 1, virtio_rng_save,
 virtio_rng_load, vrng);
 
-return vdev;
-}
-
-/*
- * This two functions will be removed later in the serie.
- */
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
-{
-VirtIORNG *vdev = NULL;
-return virtio_rng_common_init(dev, conf, vdev);
-}
-
-void virtio_rng_exit(VirtIODevice *vdev)
-{
-VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-
-qemu_del_timer(vrng-rate_limit_timer);
-qemu_free_timer(vrng-rate_limit_timer);
-unregister_savevm(vrng-qdev, virtio-rng, vrng);
-virtio_cleanup(vdev);
-}
-
-static int virtio_rng_device_init(VirtIODevice *vdev)
-{
-DeviceState *qdev = DEVICE(vdev);
-VirtIORNG *vrng = VIRTIO_RNG(vdev);
-
-if (vrng-conf.rng == NULL) {
-vrng-conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-object_property_add_child(OBJECT(qdev),
-  default-backend,
-  OBJECT(vrng-conf.default_backend),
-  NULL);
-
-object_property_set_link(OBJECT(qdev),
- OBJECT(vrng-conf.default_backend),
- rng, NULL);
-}
-
-if (virtio_rng_common_init(qdev, (vrng-conf), vrng) == NULL) {
-return -1;
-}
 return 0;
 }
 
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index d3f1436..efd29b1 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -261,7 +261,6 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, 
virtio_serial_conf *serial);
 typedef struct VirtIOSCSIConf VirtIOSCSIConf;
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *conf);
 typedef struct VirtIORNGConf VirtIORNGConf;
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf);
 #ifdef CONFIG_VIRTFS
 VirtIODevice 

[Qemu-devel] [PATCH RESEND v4 5/8] virtio-rng-ccw: switch to the new API.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

Here the virtio-rng-ccw is modified for the new API. The device
virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390x/virtio-ccw.c | 48 +---
 hw/s390x/virtio-ccw.h | 12 +++-
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 7fdc8c3..930531b 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -709,28 +709,21 @@ static void vhost_ccw_scsi_instance_init(Object *obj)
 }
 #endif
 
-static int virtio_ccw_rng_init(VirtioCcwDevice *dev)
+static int virtio_ccw_rng_init(VirtioCcwDevice *ccw_dev)
 {
-VirtIODevice *vdev;
-
-if (dev-rng.rng == NULL) {
-dev-rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-object_property_add_child(OBJECT(dev), default-backend,
-  OBJECT(dev-rng.default_backend), NULL);
-object_property_set_link(OBJECT(dev), OBJECT(dev-rng.default_backend),
- rng, NULL);
-}
-vdev = virtio_rng_init((DeviceState *)dev, dev-rng);
-if (!vdev) {
+VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
+DeviceState *vdev = DEVICE(dev-vdev);
+
+qdev_set_parent_bus(vdev, BUS(ccw_dev-bus));
+if (qdev_init(vdev)  0) {
 return -1;
 }
-return virtio_ccw_device_init(dev, vdev);
-}
 
-static int virtio_ccw_rng_exit(VirtioCcwDevice *dev)
-{
-virtio_rng_exit(dev-vdev);
-return virtio_ccw_exit(dev);
+object_property_set_link(OBJECT(dev),
+ OBJECT(dev-vdev.conf.default_backend), rng,
+ NULL);
+
+return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
 }
 
 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
@@ -947,18 +940,19 @@ static const TypeInfo vhost_ccw_scsi = {
 };
 #endif
 
-static void virtio_ccw_rng_initfn(Object *obj)
+static void virtio_ccw_rng_instance_init(Object *obj)
 {
-VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(obj);
-
+VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
+object_initialize(OBJECT(dev-vdev), TYPE_VIRTIO_RNG);
+object_property_add_child(obj, virtio-backend, OBJECT(dev-vdev), NULL);
 object_property_add_link(obj, rng, TYPE_RNG_BACKEND,
- (Object **)dev-rng.rng, NULL);
+ (Object **)dev-vdev.conf.rng, NULL);
 }
 
 static Property virtio_ccw_rng_properties[] = {
 DEFINE_PROP_STRING(devno, VirtioCcwDevice, bus_id),
 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
-DEFINE_VIRTIO_RNG_PROPERTIES(VirtioCcwDevice, rng),
+DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw, vdev.conf),
 DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -968,16 +962,16 @@ static void virtio_ccw_rng_class_init(ObjectClass *klass, 
void *data)
 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
 
 k-init = virtio_ccw_rng_init;
-k-exit = virtio_ccw_rng_exit;
+k-exit = virtio_ccw_exit;
 dc-reset = virtio_ccw_reset;
 dc-props = virtio_ccw_rng_properties;
 }
 
 static const TypeInfo virtio_ccw_rng = {
-.name  = virtio-rng-ccw,
+.name  = TYPE_VIRTIO_RNG_CCW,
 .parent= TYPE_VIRTIO_CCW_DEVICE,
-.instance_size = sizeof(VirtioCcwDevice),
-.instance_init = virtio_ccw_rng_initfn,
+.instance_size = sizeof(VirtIORNGCcw),
+.instance_init = virtio_ccw_rng_instance_init,
 .class_init= virtio_ccw_rng_class_init,
 };
 
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 84055e7..8599248 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -77,7 +77,6 @@ struct VirtioCcwDevice {
 VirtIODevice *vdev;
 char *bus_id;
 uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
-VirtIORNGConf rng;
 VirtioBusState bus;
 /* Guest provided values: */
 hwaddr indicators;
@@ -160,6 +159,17 @@ typedef struct VirtIONetCcw {
 VirtIONet vdev;
 } VirtIONetCcw;
 
+/* virtio-rng-ccw */
+
+#define TYPE_VIRTIO_RNG_CCW virtio-rng-ccw
+#define VIRTIO_RNG_CCW(obj) \
+OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW)
+
+typedef struct VirtIORNGCcw {
+VirtioCcwDevice parent_obj;
+VirtIORNG vdev;
+} VirtIORNGCcw;
+
 VirtualCssBus *virtual_css_bus_init(void);
 void virtio_ccw_device_update_status(SubchDev *sch);
 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch);
-- 
1.7.11.7




[Qemu-devel] [PATCH RESEND v4 8/8] virtio-rng: cleanup: use QOM casts.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

As the virtio-rng-pci, virtio-rng-s390 and virtio-rng-ccw are
switched to the new API, we can use QOM casts.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
Reviewed-by: Andreas Färber afaer...@suse.de
---
 hw/virtio/virtio-rng.c | 27 +++
 include/hw/virtio/virtio-rng.h |  2 +-
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index a1dbd1e..96e8075 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -18,8 +18,9 @@
 
 static bool is_guest_ready(VirtIORNG *vrng)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
 if (virtio_queue_ready(vrng-vq)
- (vrng-vdev.status  VIRTIO_CONFIG_S_DRIVER_OK)) {
+ (vdev-status  VIRTIO_CONFIG_S_DRIVER_OK)) {
 return true;
 }
 return false;
@@ -39,6 +40,7 @@ static void virtio_rng_process(VirtIORNG *vrng);
 static void chr_read(void *opaque, const void *buf, size_t size)
 {
 VirtIORNG *vrng = opaque;
+VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
 VirtQueueElement elem;
 size_t len;
 int offset;
@@ -60,7 +62,7 @@ static void chr_read(void *opaque, const void *buf, size_t 
size)
 
 virtqueue_push(vrng-vq, elem, len);
 }
-virtio_notify(vrng-vdev, vrng-vq);
+virtio_notify(vdev, vrng-vq);
 }
 
 static void virtio_rng_process(VirtIORNG *vrng)
@@ -86,7 +88,7 @@ static void virtio_rng_process(VirtIORNG *vrng)
 
 static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+VirtIORNG *vrng = VIRTIO_RNG(vdev);
 virtio_rng_process(vrng);
 }
 
@@ -97,19 +99,20 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t f)
 
 static void virtio_rng_save(QEMUFile *f, void *opaque)
 {
-VirtIORNG *vrng = opaque;
+VirtIODevice *vdev = opaque;
 
-virtio_save(vrng-vdev, f);
+virtio_save(vdev, f);
 }
 
 static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 {
 VirtIORNG *vrng = opaque;
+VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
 
 if (version_id != 1) {
 return -EINVAL;
 }
-virtio_load(vrng-vdev, f);
+virtio_load(vdev, f);
 
 /* We may have an element ready but couldn't process it due to a quota
  * limit.  Make sure to try again after live migration when the quota may
@@ -122,12 +125,12 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int 
version_id)
 
 static void check_rate_limit(void *opaque)
 {
-VirtIORNG *s = opaque;
+VirtIORNG *vrng = opaque;
 
-s-quota_remaining = s-conf.max_bytes;
-virtio_rng_process(s);
-qemu_mod_timer(s-rate_limit_timer,
-   qemu_get_clock_ms(vm_clock) + s-conf.period_ms);
+vrng-quota_remaining = vrng-conf.max_bytes;
+virtio_rng_process(vrng);
+qemu_mod_timer(vrng-rate_limit_timer,
+   qemu_get_clock_ms(vm_clock) + vrng-conf.period_ms);
 }
 
 static int virtio_rng_device_init(VirtIODevice *vdev)
@@ -166,7 +169,7 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
 
 vrng-vq = virtio_add_queue(vdev, 8, handle_input);
 
-vrng-vdev.get_features = get_features;
+vdev-get_features = get_features;
 
 assert(vrng-conf.max_bytes = INT64_MAX);
 vrng-quota_remaining = vrng-conf.max_bytes;
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 4347818..debaa15 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -30,7 +30,7 @@ struct VirtIORNGConf {
 };
 
 typedef struct VirtIORNG {
-VirtIODevice vdev;
+VirtIODevice parent_obj;
 
 /* Only one vq - guest puts buffer(s) on it when it needs entropy */
 VirtQueue *vq;
-- 
1.7.11.7




[Qemu-devel] [PATCH RESEND v4 7/8] virtio-rng: cleanup: remove qdev field.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

The qdev field is no longer needed, just drop it.

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

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 805dd18..a1dbd1e 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -168,8 +168,6 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
 
 vrng-vdev.get_features = get_features;
 
-vrng-qdev = qdev;
-
 assert(vrng-conf.max_bytes = INT64_MAX);
 vrng-quota_remaining = vrng-conf.max_bytes;
 
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 973d809..4347818 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -32,8 +32,6 @@ struct VirtIORNGConf {
 typedef struct VirtIORNG {
 VirtIODevice vdev;
 
-DeviceState *qdev;
-
 /* Only one vq - guest puts buffer(s) on it when it needs entropy */
 VirtQueue *vq;
 
-- 
1.7.11.7




Re: [Qemu-devel] [PULL 0/9] SCSI updates for 2013-04-13

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 06:56, Stefan Weil ha scritto:
 Hi Paolo,
 
 the latest QEMU build is broken when CONFIG_VHOST_SCSI is undefined.

--verbose, please. :)

$ ../configure --disable-vhost-scsi
$ grep VHOST_SC */config-* config-*
$

works here.

Paolo



[Qemu-devel] [PATCH v4 0/7] virtio-refactoring cleanup.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This is the last part of the refactoring.

The step 4 replaces the function pointers contained in VirtIODevice structure by
the function pointers contained in VirtioDeviceClass.

The step 5 removes virtiobindings, and use the VirtioBusClass.

I tested the changes on i386 only with virtio-blk on linux guest.

You can test here (it's on top of virtio-rng-v4 I sent earlier):
git://project.greensocs.com/qemu-virtio.git virtio-cleanup-v4

Changes v3 - v4:
* Don't use device_plugged callback for s390 and ccw.
* Added unused prototype removing.
* Rebased.

Changes v2 - v3:
* Fix PCI hot-unplug.
* Add CCW devices.
* A lot of rebasing.

Thanks,
Fred

KONRAD Frederic (7):
  virtio-bus: add new functions.
  virtio-bus: make virtio_x_bus_new static.
  virtio-pci: cleanup.
  virtio: remove the function pointer.
  virtio: remove virtiobindings.
  virtio: cleanup: init and exit function.
  virtio: drop unused function prototypes.

 hw/9pfs/virtio-9p-device.c  |   2 -
 hw/block/dataplane/virtio-blk.c |  15 +++---
 hw/block/virtio-blk.c   |   9 +---
 hw/char/virtio-serial-bus.c |   8 +--
 hw/net/vhost_net.c  |  17 +++---
 hw/net/virtio-net.c |  11 +---
 hw/s390x/s390-virtio-bus.c  |  21 +++-
 hw/s390x/s390-virtio-bus.h  |   2 -
 hw/s390x/virtio-ccw.c   |  26 --
 hw/s390x/virtio-ccw.h   |   2 -
 hw/scsi/vhost-scsi.c|  18 +++
 hw/scsi/virtio-scsi.c   |   8 +--
 hw/virtio/vhost.c   |  31 ++-
 hw/virtio/virtio-balloon.c  |   8 +--
 hw/virtio/virtio-bus.c  |  40 --
 hw/virtio/virtio-pci.c  | 112 +++-
 hw/virtio/virtio-pci.h  |   3 --
 hw/virtio/virtio-rng.c  |   4 +-
 hw/virtio/virtio.c  | 109 +++---
 include/hw/virtio/virtio-bus.h  |   9 ++--
 include/hw/virtio/virtio.h  |  59 +
 21 files changed, 184 insertions(+), 330 deletions(-)

-- 
1.7.11.7




[Qemu-devel] [PATCH v4 4/7] virtio: remove the function pointer.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove the function pointer in VirtIODevice, and use only
VirtioDeviceClass function pointer.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/9pfs/virtio-9p-device.c  |  2 --
 hw/block/virtio-blk.c   |  5 -
 hw/char/virtio-serial-bus.c |  6 --
 hw/net/virtio-net.c |  9 -
 hw/s390x/s390-virtio-bus.c  |  9 -
 hw/s390x/virtio-ccw.c   | 14 ++
 hw/scsi/vhost-scsi.c|  4 
 hw/scsi/virtio-scsi.c   |  6 --
 hw/virtio/virtio-balloon.c  |  4 
 hw/virtio/virtio-pci.c  | 41 -
 hw/virtio/virtio-rng.c  |  2 --
 hw/virtio/virtio.c  | 43 ---
 include/hw/virtio/virtio.h  | 24 
 13 files changed, 62 insertions(+), 107 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 62a291b..dc6f4e4 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -92,9 +92,7 @@ static int virtio_9p_device_init(VirtIODevice *vdev)
 s-ctx.uid = -1;
 
 s-ops = fse-ops;
-vdev-get_features = virtio_9p_get_features;
 s-config_size = sizeof(struct virtio_9p_config) + len;
-vdev-get_config = virtio_9p_get_config;
 s-fid_list = NULL;
 qemu_co_rwlock_init(s-rename_lock);
 
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 9fdf009..efad690 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -652,11 +652,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
 virtio_init(vdev, virtio-blk, VIRTIO_ID_BLOCK,
 sizeof(struct virtio_blk_config));
 
-vdev-get_config = virtio_blk_update_config;
-vdev-set_config = virtio_blk_set_config;
-vdev-get_features = virtio_blk_get_features;
-vdev-set_status = virtio_blk_set_status;
-vdev-reset = virtio_blk_reset;
 s-bs = blk-conf.bs;
 s-conf = blk-conf;
 memcpy((s-blk), blk, sizeof(struct VirtIOBlkConf));
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 35c996d..6a5b8b6 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -954,12 +954,6 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
  */
 mark_port_added(vser, 0);
 
-vdev-get_features = get_features;
-vdev-get_config = get_config;
-vdev-set_config = set_config;
-vdev-set_status = set_status;
-vdev-reset = vser_reset;
-
 vser-post_load = NULL;
 
 /*
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 4d2cdd2..0a0d516 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1283,15 +1283,6 @@ static int virtio_net_device_init(VirtIODevice *vdev)
 virtio_init(VIRTIO_DEVICE(n), virtio-net, VIRTIO_ID_NET,
   n-config_size);
 
-vdev-get_config = virtio_net_get_config;
-vdev-set_config = virtio_net_set_config;
-vdev-get_features = virtio_net_get_features;
-vdev-set_features = virtio_net_set_features;
-vdev-bad_features = virtio_net_bad_features;
-vdev-reset = virtio_net_reset;
-vdev-set_status = virtio_net_set_status;
-vdev-guest_notifier_mask = virtio_net_guest_notifier_mask;
-vdev-guest_notifier_pending = virtio_net_guest_notifier_pending;
 n-max_queues = MAX(n-nic_conf.queues, 1);
 n-vqs = g_malloc0(sizeof(VirtIONetQueue) * n-max_queues);
 n-vqs[0].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index 0cfbff6..f7a2f4b 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -136,12 +136,13 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, 
VirtIODevice *vdev)
 dev_len = VIRTIO_DEV_OFFS_CONFIG;
 dev_len += s390_virtio_device_num_vq(dev) * VIRTIO_VQCONFIG_LEN;
 dev_len += dev-feat_len * 2;
-dev_len += vdev-config_len;
+dev_len += virtio_bus_get_vdev_config_len(dev-bus);
 
 bus-dev_offs += dev_len;
 
 virtio_bind_device(vdev, virtio_s390_bindings, DEVICE(dev));
-dev-host_features = vdev-get_features(vdev, dev-host_features);
+dev-host_features = virtio_bus_get_vdev_features(dev-bus,
+  dev-host_features);
 s390_virtio_device_sync(dev);
 s390_virtio_reset_idx(dev);
 if (dev-qdev.hotplugged) {
@@ -368,9 +369,7 @@ void s390_virtio_device_sync(VirtIOS390Device *dev)
 cur_offs += dev-feat_len * 2;
 
 /* Sync config space */
-if (dev-vdev-get_config) {
-dev-vdev-get_config(dev-vdev, dev-vdev-config);
-}
+virtio_bus_get_vdev_config(dev-bus, dev-vdev-config);
 
 cpu_physical_memory_write(cur_offs,
   dev-vdev-config, dev-vdev-config_len);
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 0591dc2..e14351c 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -235,9 +235,7 

[Qemu-devel] [PATCH v4 7/7] virtio: drop unused function prototypes.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This removes the unused prototypes in virtio.h.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 include/hw/virtio/virtio.h | 10 --
 1 file changed, 10 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 0f240c7..ae7a4c4 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -210,18 +210,8 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf 
*conf,
   struct virtio_net_conf *net,
   uint32_t host_features);
 typedef struct virtio_serial_conf virtio_serial_conf;
-VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *serial);
 typedef struct VirtIOSCSIConf VirtIOSCSIConf;
-VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *conf);
 typedef struct VirtIORNGConf VirtIORNGConf;
-#ifdef CONFIG_VIRTFS
-VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
-#endif
-
-
-void virtio_net_exit(VirtIODevice *vdev);
-void virtio_serial_exit(VirtIODevice *vdev);
-void virtio_scsi_exit(VirtIODevice *vdev);
 
 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
DEFINE_PROP_BIT(indirect_desc, _state, _field, \
-- 
1.7.11.7




[Qemu-devel] [PATCH v4 1/7] virtio-bus: add new functions.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This add two functions:
   * virtio_bus_set_vdev_config.
   * virtio_bus_set_vdev_feature.

Needed by virtio-ccw.

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

diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index 1596a1c..dd10849 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -124,6 +124,18 @@ uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
 return k-get_features(bus-vdev, requested_features);
 }
 
+/* Set the features of the plugged device. */
+void virtio_bus_set_vdev_features(VirtioBusState *bus,
+  uint32_t requested_features)
+{
+VirtioDeviceClass *k;
+assert(bus-vdev != NULL);
+k = VIRTIO_DEVICE_GET_CLASS(bus-vdev);
+if (k-set_features != NULL) {
+k-set_features(bus-vdev, requested_features);
+}
+}
+
 /* Get bad features of the plugged device. */
 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
 {
@@ -148,6 +160,17 @@ void virtio_bus_get_vdev_config(VirtioBusState *bus, 
uint8_t *config)
 }
 }
 
+/* Set config of the plugged device. */
+void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config)
+{
+VirtioDeviceClass *k;
+assert(bus-vdev != NULL);
+k = VIRTIO_DEVICE_GET_CLASS(bus-vdev);
+if (k-set_config != NULL) {
+k-set_config(bus-vdev, config);
+}
+}
+
 static const TypeInfo virtio_bus_info = {
 .name = TYPE_VIRTIO_BUS,
 .parent = TYPE_BUS,
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index 311e8c7..ec82238 100644
--- a/include/hw/virtio/virtio-bus.h
+++ b/include/hw/virtio/virtio-bus.h
@@ -86,9 +86,14 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
 /* Get the features of the plugged device. */
 uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
 uint32_t requested_features);
+/* Set the features of the plugged device. */
+void virtio_bus_set_vdev_features(VirtioBusState *bus,
+  uint32_t requested_features);
 /* Get bad features of the plugged device. */
 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
 /* Get config of the plugged device. */
 void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
+/* Set config of the plugged device. */
+void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
 
 #endif /* VIRTIO_BUS_H */
-- 
1.7.11.7




[Qemu-devel] [PATCH v4 2/7] virtio-bus: make virtio_x_bus_new static.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

virtio_x_bus_new are only used in file scope.
So this make them static.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/s390x/s390-virtio-bus.c | 4 +++-
 hw/s390x/s390-virtio-bus.h | 2 --
 hw/s390x/virtio-ccw.c  | 4 +++-
 hw/s390x/virtio-ccw.h  | 2 --
 hw/virtio/virtio-pci.c | 4 +++-
 hw/virtio/virtio-pci.h | 1 -
 6 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index 95c9275..0cfbff6 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -47,6 +47,8 @@
 
 #define VIRTIO_EXT_CODE   0x2603
 
+static void virtio_s390_bus_new(VirtioBusState *bus, VirtIOS390Device *dev);
+
 static const TypeInfo s390_virtio_bus_info = {
 .name = TYPE_S390_VIRTIO_BUS,
 .parent = TYPE_BUS,
@@ -664,7 +666,7 @@ static const TypeInfo s390_virtio_bridge_info = {
 
 /* virtio-s390-bus */
 
-void virtio_s390_bus_new(VirtioBusState *bus, VirtIOS390Device *dev)
+static void virtio_s390_bus_new(VirtioBusState *bus, VirtIOS390Device *dev)
 {
 DeviceState *qdev = DEVICE(dev);
 BusState *qbus;
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index 991f9e2..ac81bd8 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -79,8 +79,6 @@ typedef struct VirtioBusClass VirtioS390BusClass;
 
 typedef struct VirtIOS390Device VirtIOS390Device;
 
-void virtio_s390_bus_new(VirtioBusState *bus, VirtIOS390Device *dev);
-
 typedef struct VirtIOS390DeviceClass {
 DeviceClass qdev;
 int (*init)(VirtIOS390Device *dev);
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 930531b..0591dc2 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -27,6 +27,8 @@
 #include virtio-ccw.h
 #include trace.h
 
+static void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev);
+
 static int virtual_css_bus_reset(BusState *qbus)
 {
 /* This should actually be modelled via the generic css */
@@ -1060,7 +1062,7 @@ static const TypeInfo virtual_css_bridge_info = {
 
 /* virtio-ccw-bus */
 
-void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev)
+static void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev)
 {
 DeviceState *qdev = DEVICE(dev);
 BusState *qbus;
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 8599248..04ba1b9 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -60,8 +60,6 @@ typedef struct VirtioBusClass VirtioCcwBusClass;
 
 typedef struct VirtioCcwDevice VirtioCcwDevice;
 
-void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev);
-
 typedef struct VirtIOCCWDeviceClass {
 DeviceClass parent_class;
 int (*init)(VirtioCcwDevice *dev);
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1269a22..6278427 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -98,6 +98,8 @@
 /* HACK for virtio to determine if it's running a big endian guest */
 bool virtio_is_big_endian(void);
 
+static void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
+
 /* virtio device */
 /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */
 static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
@@ -1524,7 +1526,7 @@ static const TypeInfo virtio_rng_pci_info = {
 
 /* virtio-pci-bus */
 
-void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev)
+static void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev)
 {
 DeviceState *qdev = DEVICE(dev);
 BusState *qbus;
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index ac71824..35ae6ac 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -201,7 +201,6 @@ struct VirtIORngPCI {
 };
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
-void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION  0
-- 
1.7.11.7




[Qemu-devel] [PATCH v4 3/7] virtio-pci: cleanup.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove the init, exit functions as they are no longer used.

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

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6278427..c87ec10 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -885,57 +885,6 @@ static const VirtIOBindings virtio_pci_bindings = {
 .vmstate_change = virtio_pci_vmstate_change,
 };
 
-void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
-{
-uint8_t *config;
-uint32_t size;
-
-proxy-vdev = vdev;
-
-config = proxy-pci_dev.config;
-
-if (proxy-class_code) {
-pci_config_set_class(config, proxy-class_code);
-}
-pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
- pci_get_word(config + PCI_VENDOR_ID));
-pci_set_word(config + PCI_SUBSYSTEM_ID, vdev-device_id);
-config[PCI_INTERRUPT_PIN] = 1;
-
-if (vdev-nvectors 
-msix_init_exclusive_bar(proxy-pci_dev, vdev-nvectors, 1)) {
-vdev-nvectors = 0;
-}
-
-proxy-pci_dev.config_write = virtio_write_config;
-
-size = VIRTIO_PCI_REGION_SIZE(proxy-pci_dev) + vdev-config_len;
-if (size  (size-1))
-size = 1  qemu_fls(size);
-
-memory_region_init_io(proxy-bar, virtio_pci_config_ops, proxy,
-  virtio-pci, size);
-pci_register_bar(proxy-pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
- proxy-bar);
-
-if (!kvm_has_many_ioeventfds()) {
-proxy-flags = ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
-}
-
-virtio_bind_device(vdev, virtio_pci_bindings, DEVICE(proxy));
-proxy-host_features |= 0x1  VIRTIO_F_NOTIFY_ON_EMPTY;
-proxy-host_features |= 0x1  VIRTIO_F_BAD_FEATURE;
-proxy-host_features = vdev-get_features(vdev, proxy-host_features);
-}
-
-static void virtio_exit_pci(PCIDevice *pci_dev)
-{
-VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-memory_region_destroy(proxy-bar);
-msix_uninit_exclusive_bar(pci_dev);
-}
-
 #ifdef CONFIG_VIRTFS
 static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
 {
@@ -1054,7 +1003,8 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
 {
 VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
 virtio_pci_stop_ioeventfd(proxy);
-virtio_exit_pci(pci_dev);
+memory_region_destroy(proxy-bar);
+msix_uninit_exclusive_bar(pci_dev);
 }
 
 static void virtio_pci_reset(DeviceState *qdev)
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 35ae6ac..917bcc5 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -200,8 +200,6 @@ struct VirtIORngPCI {
 VirtIORNG vdev;
 };
 
-void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
-
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION  0
 
-- 
1.7.11.7




[Qemu-devel] [PATCH v4 5/7] virtio: remove virtiobindings.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This remove virtio-bindings, and use class instead.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/block/dataplane/virtio-blk.c | 15 -
 hw/net/vhost_net.c  | 17 --
 hw/s390x/s390-virtio-bus.c  |  8 ---
 hw/s390x/virtio-ccw.c   |  8 ---
 hw/scsi/vhost-scsi.c| 14 +++-
 hw/virtio/vhost.c   | 31 +++---
 hw/virtio/virtio-bus.c  | 17 --
 hw/virtio/virtio-pci.c  | 13 ---
 hw/virtio/virtio.c  | 49 +++--
 include/hw/virtio/virtio-bus.h  |  4 
 include/hw/virtio/virtio.h  | 19 
 11 files changed, 73 insertions(+), 122 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 5baef23..0356665 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -23,6 +23,7 @@
 #include hw/virtio/virtio-blk.h
 #include virtio-blk.h
 #include block/aio.h
+#include hw/virtio/virtio-bus.h
 
 enum {
 SEG_MAX = 126,  /* maximum number of I/O segments */
@@ -455,6 +456,8 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
 
 void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s-vdev)));
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
 VirtQueue *vq;
 int i;
 
@@ -470,8 +473,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
 s-ctx = aio_context_new();
 
 /* Set up guest notifier (irq) */
-if (s-vdev-binding-set_guest_notifiers(s-vdev-binding_opaque, 1,
-  true) != 0) {
+if (k-set_guest_notifiers(qbus-parent, 1, true) != 0) {
 fprintf(stderr, virtio-blk failed to set guest notifier, 
 ensure -enable-kvm is set\n);
 exit(1);
@@ -479,8 +481,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
 s-guest_notifier = virtio_queue_get_guest_notifier(vq);
 
 /* Set up virtqueue notify */
-if (s-vdev-binding-set_host_notifier(s-vdev-binding_opaque,
-0, true) != 0) {
+if (k-set_host_notifier(qbus-parent, 0, true) != 0) {
 fprintf(stderr, virtio-blk failed to set host notifier\n);
 exit(1);
 }
@@ -508,6 +509,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
 
 void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s-vdev)));
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
 if (!s-started || s-stopping) {
 return;
 }
@@ -527,12 +530,12 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
 ioq_cleanup(s-ioqueue);
 
 aio_set_event_notifier(s-ctx, s-host_notifier, NULL, NULL);
-s-vdev-binding-set_host_notifier(s-vdev-binding_opaque, 0, false);
+k-set_host_notifier(qbus-parent, 0, false);
 
 aio_context_unref(s-ctx);
 
 /* Clean up guest notifier (irq) */
-s-vdev-binding-set_guest_notifiers(s-vdev-binding_opaque, 1, false);
+k-set_guest_notifiers(qbus-parent, 1, false);
 
 vring_teardown(s-vring);
 s-started = false;
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 8c5384c..006576d 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -37,6 +37,7 @@
 #include stdio.h
 
 #include hw/virtio/vhost.h
+#include hw/virtio/virtio-bus.h
 
 struct vhost_net {
 struct vhost_dev dev;
@@ -211,9 +212,12 @@ static void vhost_net_stop_one(struct vhost_net *net,
 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 int total_queues)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 int r, i = 0;
 
-if (!dev-binding-set_guest_notifiers) {
+if (!k-set_guest_notifiers) {
 error_report(binding does not support guest notifiers);
 r = -ENOSYS;
 goto err;
@@ -227,9 +231,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 }
 }
 
-r = dev-binding-set_guest_notifiers(dev-binding_opaque,
-  total_queues * 2,
-  true);
+r = k-set_guest_notifiers(qbus-parent, total_queues * 2, true);
 if (r  0) {
 error_report(Error binding guest notifier: %d, -r);
 goto err;
@@ -247,11 +249,12 @@ err:
 void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
 int total_queues)
 {
+BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
+VirtioBusState *vbus = VIRTIO_BUS(qbus);
+VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 int i, r;
 
-r = dev-binding-set_guest_notifiers(dev-binding_opaque,
-  total_queues * 

[Qemu-devel] [PATCH v4 6/7] virtio: cleanup: init and exit function.

2013-04-24 Thread fred . konrad
From: KONRAD Frederic fred.kon...@greensocs.com

This clean the init and the exit functions and rename virtio_common_cleanup
to virtio_cleanup.

Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
---
 hw/block/virtio-blk.c   |  4 ++--
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c |  2 +-
 hw/scsi/virtio-scsi.c   |  2 +-
 hw/virtio/virtio-balloon.c  |  4 ++--
 hw/virtio/virtio-rng.c  |  2 +-
 hw/virtio/virtio.c  | 17 +
 include/hw/virtio/virtio.h  |  6 +-
 8 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index efad690..cf12469 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -661,7 +661,7 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
 s-vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
 if (!virtio_blk_data_plane_create(vdev, blk, s-dataplane)) {
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return -1;
 }
 #endif
@@ -689,7 +689,7 @@ static int virtio_blk_device_exit(DeviceState *dev)
 qemu_del_vm_change_state_handler(s-change);
 unregister_savevm(dev, virtio-blk, s);
 blockdev_mark_auto_del(s-bs);
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return 0;
 }
 
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 6a5b8b6..3787ad2 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -1001,7 +1001,7 @@ static int virtio_serial_device_exit(DeviceState *dev)
 qemu_free_timer(vser-post_load-timer);
 g_free(vser-post_load);
 }
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return 0;
 }
 
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 0a0d516..2aea5a1 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1374,7 +1374,7 @@ static int virtio_net_device_exit(DeviceState *qdev)
 
 g_free(n-vqs);
 qemu_del_nic(n-nic);
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 
 return 0;
 }
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 630e459..84b3ac7 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -640,7 +640,7 @@ int virtio_scsi_common_exit(VirtIOSCSICommon *vs)
 VirtIODevice *vdev = VIRTIO_DEVICE(vs);
 
 g_free(vs-cmd_vqs);
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return 0;
 }
 
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 95fb3b0..d669756 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -348,7 +348,7 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
virtio_balloon_stat, s);
 
 if (ret  0) {
-virtio_common_cleanup(VIRTIO_DEVICE(s));
+virtio_cleanup(VIRTIO_DEVICE(s));
 return -1;
 }
 
@@ -377,7 +377,7 @@ static int virtio_balloon_device_exit(DeviceState *qdev)
 balloon_stats_destroy_timer(s);
 qemu_remove_balloon_handler(s);
 unregister_savevm(qdev, virtio-balloon, s);
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return 0;
 }
 
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 82d7a74..cb787c7 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -192,7 +192,7 @@ static int virtio_rng_device_exit(DeviceState *qdev)
 qemu_del_timer(vrng-rate_limit_timer);
 qemu_free_timer(vrng-rate_limit_timer);
 unregister_savevm(qdev, virtio-rng, vrng);
-virtio_common_cleanup(vdev);
+virtio_cleanup(vdev);
 return 0;
 }
 
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index e66dab1..0f88c25 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -910,19 +910,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 return 0;
 }
 
-void virtio_common_cleanup(VirtIODevice *vdev)
+void virtio_cleanup(VirtIODevice *vdev)
 {
 qemu_del_vm_change_state_handler(vdev-vmstate);
 g_free(vdev-config);
 g_free(vdev-vq);
 }
 
-void virtio_cleanup(VirtIODevice *vdev)
-{
-virtio_common_cleanup(vdev);
-g_free(vdev);
-}
-
 static void virtio_vmstate_change(void *opaque, int running, RunState state)
 {
 VirtIODevice *vdev = opaque;
@@ -972,15 +966,6 @@ void virtio_init(VirtIODevice *vdev, const char *name,
  vdev);
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size)
-{
-VirtIODevice *vdev;
-vdev = g_malloc0(struct_size);
-virtio_init(vdev, name, device_id, config_size);
-return vdev;
-}
-
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
 {
 return vdev-vq[n].vring.desc;
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index e72e348..0f240c7 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -147,7 +147,7 @@ 

Re: [Qemu-devel] Adding Disk-Level Introspection to QEMU

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 01:40:19PM -0400, Wolfgang Richter wrote:
 
 --
 Wolf
 
 On Apr 23, 2013, at 1:22 PM, Eric Blake ebl...@redhat.com wrote:
 
  On 04/23/2013 11:12 AM, Wolfgang Richter wrote:
  I'm interested in adding introspection of disk writes to QEMU for various
  applications and research potential.
  
  What I mean by introspection of disk writes is that, when enabled, each
  write
  passing through QEMU to backing storage would also be copied to an
  introspection channel for further analysis.
  
  Sounds like you would be benefited by the block-backup series, with an
  NBD server as the point where you inject your introspection.
  
  https://lists.gnu.org/archive/html/qemu-devel/2013-04/msg04629.html
  
  The existing drive-mirror command can also target an NBD destination,
  with similar effects.
 
 Yes, OK as a new member to the list I saw the block-backup series and was 
 starting to have similar thoughts.  I'll port my code (analysis side) to work 
 with it (or drive-mirror).
 
 Has there been any performance analysis of drive-mirror (impact on executing 
 guest)?

It slows down guest I/O for a couple of reasons:

1. Writes now require a read from the original device followed by a
   write to the target device.  Only after this completes is the write
   allowed to proceed.

2. Overlapping read/write requests are serialized to maintain
   consistency between the guests I/Os and the block-backup I/Os.

But on second thought, I don't think block-backup fits the bill.  You
don't care about the original data, you care about what new data the
guest is writing.

I think what you really want is a tap block driver which mirrors
writes to a target device (typically a NBD volume).  You can model this
on blkverify or check out Benoit Canet's quorum patches.

Stefan



Re: [Qemu-devel] Adding Disk-Level Introspection to QEMU

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 03:11:26PM -0400, Wolfgang Richter wrote:
 On Tue, Apr 23, 2013 at 2:31 PM, Wolfgang Richter w...@cs.cmu.edu wrote:
 
  On Tue, Apr 23, 2013 at 2:21 PM, Stefan Hajnoczi stefa...@gmail.comwrote:
 
  Eric's suggestion to use NBD makes sense to me.  The block-backup code
  can be extended fairly easier using sync mode=none (do not perform a
  background copy of the entire disk) and by disabling the bitmap
  (essentially tap mode).
 
 
 Also, as another thought, I think I can actually use the bitmap to implement
 an optimization.  In my code, I already use a bitmap to determine which
 sectors I want to introspect (ignoring portions of the disk greatly reduces
 required bandwidth and overhead; swap space for example isn't generally
 interesting unless you can interpret memory as well).   So I think I can
 adapt
 my code here as well.

Cool.  By the way, do you actually care about the data being written or
just which sectors were touched?

Stefan



Re: [Qemu-devel] [Xen-devel] guest cannot boot up successfully using qemu.git in Xen

2013-04-24 Thread Liu, SongtaoX
latest commit:bb71623811686ce3c34ce724f073f5c5dd95f51b in qemu.git works for 
this issue.
guest could boot up normally.
Thanks.



Regards
Carl(Songtao)


-Original Message-
From: Stefano Stabellini [mailto:stefano.stabell...@eu.citrix.com] 
Sent: Monday, April 22, 2013 5:50 PM
To: Liu, SongtaoX
Cc: xen-de...@lists.xen.org; qemu-devel@nongnu.org; Xu, YongweiX; Ren, Yongjie; 
Paolo Bonzini; qemu-devel@nongnu.org; Sander Eikelenboom; Gerd Hoffmann
Subject: Re: [Xen-devel] guest cannot boot up successfully using qemu.git in Xen

On Mon, 22 Apr 2013, Liu, SongtaoX wrote:
 I encountered a problem that the guest cannot boot up successfully using 
 qemu.git in Xen.
 after creating the guest by xl cr xlexample.hvm, xl list shows the 
 guest's vcpu has no status, and xl vnc $dom_id cannot connect to the guest.
 
 The qemu.git source is from git://git.qemu.org/qemu.git
 
 The qemu compile steps:
 ./configure --enable-xen --target-list=x86_64-softmmu 
 --extra-cflags=-I/xen-unstable.hg/tools/include 
 -I/xen-unstable.hg/tools/libxc -I/xen-unstable.hg/tools/xenstore 
 --extra-ldflags=-L/xen-unstable.hg/tools/libxc 
 -L/xen-unstable.hg/tools/xenstore
 make
 make install
 
 The xlexample.hvm includes the two lines:
 device_model_override= '/usr/local/bin/qemu-system-x86_64'
 device_model_version= 'qemu-xen'
 
 Using git bisect, the commit: 0ca5aa4f4c4a8bcc73988dd52a536241d35e5223 
 introduced the problem.
 
 commit 0ca5aa4f4c4a8bcc73988dd52a536241d35e5223
 Author: Paolo Bonzini pbonz...@redhat.com
 Date:   Wed Apr 10 15:23:27 2013 +0200
 
 qemu-char: another io_add_watch_poll fix
 
 After attaching the source, we have to remove the reference we hold
 to it, because we do not hold anymore a pointer to the source.
 
 If we do not do this, removing the source will not finalize it and
 will not drop the real I/O watch source.
 
 This showed up when backporting the new flow control patches to older
 versions of QEMU that still used select.  The whole select then failed
 with EBADF (poll instead will reporting POLLNVAL on a single pollfd)
 and QEMU froze.
 
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 Message-id: 1365600207-21685-1-git-send-email-pbonz...@redhat.com
 Signed-off-by: Anthony Liguori aligu...@us.ibm.com


Sander already reported this issue:

http://marc.info/?l=qemu-develm=136614022215765w=2

Some patches were posted to fix the issue, it should just be a matter of time 
before they are committed.



Re: [Qemu-devel] Adding Disk-Level Introspection to QEMU

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 10:37, Stefan Hajnoczi ha scritto:
  Has there been any performance analysis of drive-mirror (impact on 
  executing guest)?

What Stefan wrote is about block-backup.

drive-mirror has a limited impact on guest performance, but it doesn't
pass the writes through to the channel.  Instead, it uses a dirty bitmap
that it periodically scans to copy new data to the destination.

 It slows down guest I/O for a couple of reasons:
 
 1. Writes now require a read from the original device followed by a
write to the target device.  Only after this completes is the write
allowed to proceed.
 
 2. Overlapping read/write requests are serialized to maintain
consistency between the guests I/Os and the block-backup I/Os.
 
 But on second thought, I don't think block-backup fits the bill.  You
 don't care about the original data, you care about what new data the
 guest is writing.

Right.  However, when block-backup gets in, I will try to change
drive-mirror to use an active method.  I don't have a timeframe for
this, though.

Paolo



Re: [Qemu-devel] [PATCH V3 5/5] block: make all steps in qmp_transaction() as callback

2013-04-24 Thread Stefan Hajnoczi
On Fri, Apr 19, 2013 at 08:57:10AM +0800, Wenchao Xia wrote:
 diff --git a/blockdev.c b/blockdev.c
 index 051be98..b336794 100644
 --- a/blockdev.c
 +++ b/blockdev.c
 @@ -779,14 +779,41 @@ void qmp_blockdev_snapshot_sync(const char *device, 
 const char *snapshot_file,
  
  
  /* New and old BlockDriverState structs for group snapshots */
 -typedef struct BlkTransactionStates {
 +
 +typedef struct BlkTransactionStates BlkTransactionStates;
 +
 +/* Only prepare() may fail. In a single transaction, only one of commit() or
 +   rollback() will be called. */

Please document that clean() is always called - after either commit() or
rollback().

 +const BdrvActionOps external_snapshot_ops = {

static

 @@ -909,32 +950,36 @@ void qmp_transaction(BlockdevActionList *dev_list, 
 Error **errp)
  /* We don't do anything in this loop that commits us to the snapshot */
  while (NULL != dev_entry) {
  BlockdevAction *dev_info = NULL;
 +ExternalSnapshotStates *ext;
  
  dev_info = dev_entry-value;
  dev_entry = dev_entry-next;
  
 -states = g_malloc0(sizeof(BlkTransactionStates));
 -QSIMPLEQ_INSERT_TAIL(snap_bdrv_states, states, entry);
 -
  switch (dev_info-kind) {
  case BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC:
 -external_snapshot_prepare(dev_info, states, errp);
 -if (error_is_set(local_err)) {
 -error_propagate(errp, local_err);
 -goto delete_and_fail;
 -}
 +ext = g_malloc0(sizeof(ExternalSnapshotStates));
 +states = ext-common;
 +states-ops = external_snapshot_ops;
  break;
  default:
  abort();
  }

Code duplication can be avoided like this:

typedef struct BdrvActionOps {
/* Size of state struct, in bytes */
size_t instance_size;
/* Prepare the work, must NOT be NULL. */
void (*prepare)(BlkTransactionStates *common, Error **errp);
/* Commit the changes, must NOT be NULL. */
void (*commit)(BlkTransactionStates *common);
/* Rollback the changes on fail, can be NULL. */
void (*rollback)(BlkTransactionStates *common);
/* Clean up resource in the end, can be NULL. */
void (*clean)(BlkTransactionStates *common);
} BdrvActionOps;

static const BdrvActionOps actions[] = {
[BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = {
.instance_size = sizeof(ExternalSnapshotStates),
.prepare  = external_snapshot_prepare,
.commit   = external_snapshot_commit,
.rollback = external_snapshot_rollback,
},
};

Then the state struct is allocated as follows:

assert(dev_info-kind  ARRAY_SIZE(actions));
const BdrvActionOps *ops = actions[dev_info-kind];
states = g_malloc0(ops-instance_size);
states-ops = ops;

No switch statement is necessary and the states setup doesn't need to be
duplicated when new actions are added.



Re: [Qemu-devel] Adding Disk-Level Introspection to QEMU

2013-04-24 Thread Paolo Bonzini
Il 23/04/2013 20:31, Wolfgang Richter ha scritto:
 On Tue, Apr 23, 2013 at 2:21 PM, Stefan Hajnoczi stefa...@gmail.com
 mailto:stefa...@gmail.com wrote:
 
 The tracing subsystem is geared towards tracepoint instrumentation
 rather than binary dumps.
 
 Can you share some specific applications?
 
 
 Well, my main application is in exposing a cloud-inotify service by
 interpreting
 sector writes in real-time and publishing the updates as file system
 manipulations.
 By using introspection we don't need agents running inside the guest.
 
 Example: guest writes to sector 5786907; I reverse-map that sector and
 notice
 it belongs to '/etc/passwd' within that guest; I immediately emit a message
 (currently using Redis pub-sub functionality) to any interested
 subscribers that
 '/etc/passwd' changed within this guest running on a certain host within the
 datacenter.

If you are okay with writes being bundled and you are able to handle
reordered writes within a small timeframe (usually 0.1-1s), then you can
use drive-mirror with an NBD destination.

Paolo



[Qemu-devel] [PATCH 2/5] console: add device link to QemuConsoles

2013-04-24 Thread Gerd Hoffmann
So it is possible to figure which qemu console displays which device.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/arm/musicpal.c|2 +-
 hw/display/blizzard.c|2 +-
 hw/display/cirrus_vga.c  |4 ++--
 hw/display/exynos4210_fimd.c |2 +-
 hw/display/g364fb.c  |2 +-
 hw/display/jazz_led.c|2 +-
 hw/display/milkymist-vgafb.c |2 +-
 hw/display/omap_lcdc.c   |2 +-
 hw/display/pl110.c   |2 +-
 hw/display/pxa2xx_lcd.c  |2 +-
 hw/display/qxl.c |4 ++--
 hw/display/sm501.c   |2 +-
 hw/display/ssd0303.c |2 +-
 hw/display/ssd0323.c |2 +-
 hw/display/tc6393xb.c|2 +-
 hw/display/tcx.c |4 ++--
 hw/display/vga-isa-mm.c  |2 +-
 hw/display/vga-isa.c |2 +-
 hw/display/vga-pci.c |2 +-
 hw/display/vmware_vga.c  |7 ---
 hw/unicore32/puv3.c  |2 +-
 include/ui/console.h |3 ++-
 ui/console.c |   15 ++-
 23 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index f33ba9a..fbaf2be 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -616,7 +616,7 @@ static int musicpal_lcd_init(SysBusDevice *dev)
   musicpal-lcd, MP_LCD_SIZE);
 sysbus_init_mmio(dev, s-iomem);
 
-s-con = graphic_console_init(musicpal_gfx_ops, s);
+s-con = graphic_console_init(DEVICE(dev), musicpal_gfx_ops, s);
 qemu_console_resize(s-con, 128*3, 64*3);
 
 qdev_init_gpio_in(dev-qdev, musicpal_lcd_gpio_brigthness_in, 3);
diff --git a/hw/display/blizzard.c b/hw/display/blizzard.c
index 1ca3355..4a466c8 100644
--- a/hw/display/blizzard.c
+++ b/hw/display/blizzard.c
@@ -956,7 +956,7 @@ void *s1d13745_init(qemu_irq gpio_int)
 
 s-fb = g_malloc(0x18);
 
-s-con = graphic_console_init(blizzard_ops, s);
+s-con = graphic_console_init(NULL, blizzard_ops, s);
 surface = qemu_console_surface(s-con);
 
 switch (surface_bits_per_pixel(surface)) {
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index db232af..6e47956 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -2910,7 +2910,7 @@ static int vga_initfn(ISADevice *dev)
 vga_common_init(s);
 cirrus_init_common(d-cirrus_vga, CIRRUS_ID_CLGD5430, 0,
isa_address_space(dev), isa_address_space_io(dev));
-s-con = graphic_console_init(s-hw_ops, s);
+s-con = graphic_console_init(DEVICE(dev), s-hw_ops, s);
 rom_add_vga(VGABIOS_CIRRUS_FILENAME);
 /* XXX ISA-LFB support */
 /* FIXME not qdev yet */
@@ -2957,7 +2957,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
  vga_common_init(s-vga);
  cirrus_init_common(s, device_id, 1, pci_address_space(dev),
 pci_address_space_io(dev));
- s-vga.con = graphic_console_init(s-vga.hw_ops, s-vga);
+ s-vga.con = graphic_console_init(DEVICE(dev), s-vga.hw_ops, s-vga);
 
  /* setup PCI */
 
diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c
index e6e7b27..6cb5016 100644
--- a/hw/display/exynos4210_fimd.c
+++ b/hw/display/exynos4210_fimd.c
@@ -1905,7 +1905,7 @@ static int exynos4210_fimd_init(SysBusDevice *dev)
 memory_region_init_io(s-iomem, exynos4210_fimd_mmio_ops, s,
 exynos4210.fimd, FIMD_REGS_SIZE);
 sysbus_init_mmio(dev, s-iomem);
-s-console = graphic_console_init(exynos4210_fimd_ops, s);
+s-console = graphic_console_init(DEVICE(dev), exynos4210_fimd_ops, s);
 
 return 0;
 }
diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 03810e9..2a4047e 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -484,7 +484,7 @@ static void g364fb_init(DeviceState *dev, G364State *s)
 {
 s-vram = g_malloc0(s-vram_size);
 
-s-con = graphic_console_init(g364fb_ops, s);
+s-con = graphic_console_init(dev, g364fb_ops, s);
 
 memory_region_init_io(s-mem_ctrl, g364fb_ctrl_ops, s, ctrl, 0x18);
 memory_region_init_ram_ptr(s-mem_vram, vram,
diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c
index 6306d8c..52035fc 100644
--- a/hw/display/jazz_led.c
+++ b/hw/display/jazz_led.c
@@ -267,7 +267,7 @@ static int jazz_led_init(SysBusDevice *dev)
 memory_region_init_io(s-iomem, led_ops, s, led, 1);
 sysbus_init_mmio(dev, s-iomem);
 
-s-con = graphic_console_init(jazz_led_ops, s);
+s-con = graphic_console_init(DEVICE(dev), jazz_led_ops, s);
 
 return 0;
 }
diff --git a/hw/display/milkymist-vgafb.c b/hw/display/milkymist-vgafb.c
index 716997c..3828296 100644
--- a/hw/display/milkymist-vgafb.c
+++ b/hw/display/milkymist-vgafb.c
@@ -283,7 +283,7 @@ static int milkymist_vgafb_init(SysBusDevice *dev)
 milkymist-vgafb, R_MAX * 4);
 sysbus_init_mmio(dev, s-regs_region);
 
-s-con = graphic_console_init(vgafb_ops, s);
+s-con = graphic_console_init(DEVICE(dev), vgafb_ops, s);
 
  

[Qemu-devel] [PATCH 4/5] console: switch ppm_save to qemu_open

2013-04-24 Thread Gerd Hoffmann
... so it works with fdset.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index e3ab985..3835316 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -269,18 +269,20 @@ static void ppm_save(const char *filename, struct 
DisplaySurface *ds,
 {
 int width = pixman_image_get_width(ds-image);
 int height = pixman_image_get_height(ds-image);
+int fd;
 FILE *f;
 int y;
 int ret;
 pixman_image_t *linebuf;
 
 trace_ppm_save(filename, ds);
-f = fopen(filename, wb);
-if (!f) {
+fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+if (fd == -1) {
 error_setg(errp, failed to open file '%s': %s, filename,
strerror(errno));
 return;
 }
+f = fdopen(fd, wb);
 ret = fprintf(f, P6\n%d %d\n%d\n, width, height, 255);
 if (ret  0) {
 linebuf = NULL;
-- 
1.7.9.7




Re: [Qemu-devel] [PATCH v4 0/7] publish etc/acpi/APIC in fw_cfg

2013-04-24 Thread Laszlo Ersek
On 04/18/13 22:22, Laszlo Ersek wrote:
 v4:
 - patches 1-6 are unchanged and carry Michael's ACK,
 - patch 7 is rendered dependent on a new configure switch (default off)
   [Michael Tsirkin].
 
 v3:
 - rebased to current master 24a6e7f4,
 - added Michael's S-o-b to 6/7 [Eric Blake],
 - added Dave Frodin's relicensing ACK to 7/7, originally sent to Michael
   in private [Michael Tsirkin],
 - slightly reworded 7/7's commit message where it credits Michael's
   prototype [Eric Blake].
 
 v2:
 - address (1) in
   http://thread.gmane.org/gmane.comp.emulators.qemu/206146/focus=206195:
 
   - rebase to Paolo's recent series
 http://thread.gmane.org/gmane.comp.emulators.qemu/206196/focus=206278,
 
   - patch 2 is new, fixes style of function parameter references in a
 comment [mst],
 
   - patch 6 is new, moves a macro definition [mst],
 
   - patch 7 should be structured more logically now, plus the commit
 message has grown some bits related to licensing [mst].
 acpi_table_fill_hdr() is kept distinct from the -acpitable switch's
 implementation on purpose, similarly to pc_acpi_install() in v1.
 
 - Tested APIC / DSDT / RSDT against contents saved from v1.
 
 v1 blurb:
 
   This series exports the MADT (APIC) ACPI table under the new
   etc/acpi/APIC fw_cfg file. I sought to follow the requirements set
   forth in [1], the new table is only visible in the patched/patched
   case. I cross-tested { master, patched } qemu with { master, patched }
   seabios (the APIC, DSDT and RSDT tables) using guest acpidump and
   dmesg.
 
   The -acpitable command line option is purposely ignored based on the
   last paragraph of [2]; the user isn't supposed to pass APIC with that
   option.
 
   checkpatch.pl complains a little but (as last time) it's a false
   alarm.
 
   The series is bisectable.
 
   [1] http://thread.gmane.org/gmane.comp.emulators.qemu/202005/focus=202072
   [2] http://thread.gmane.org/gmane.comp.bios.coreboot.seabios/5960/focus=6008
 
 Laszlo Ersek (6):
   refer to FWCfgState explicitly
   acpi_table_install(): fix funcparam formatting in leading comment
   hw/acpi: extract standard table headers as a standalone structure
   hw/acpi: export default ACPI headers using the type just introduced
   hw/acpi: export acpi_checksum()
   hw/i386: build ACPI MADT (APIC) for fw_cfg clients
 
 Michael S. Tsirkin (1):
   hw/i386/pc.c: move IO_APIC_DEFAULT_ADDRESS to include/hw/i386/apic.h
 
  configure  |   12 
  hw/i386/Makefile.objs  |1 +
  hw/i386/acpi.h |9 +++
  hw/i386/multiboot.h|4 +-
  include/hw/acpi/acpi.h |   15 +
  include/hw/i386/apic.h |2 +
  include/hw/i386/pc.h   |   19 +++---
  include/hw/loader.h|3 +-
  hw/acpi/core.c |   91 ++-
  hw/acpi/piix4.c|2 +-
  hw/core/loader.c   |2 +-
  hw/i386/acpi.c |  159 
 
  hw/i386/multiboot.c|2 +-
  hw/i386/pc.c   |   49 +++
  hw/i386/pc_piix.c  |2 +-
  hw/sparc/sun4m.c   |6 +-
  hw/sparc64/sun4u.c |2 +-
  17 files changed, 303 insertions(+), 77 deletions(-)
  create mode 100644 hw/i386/acpi.h
  create mode 100644 hw/i386/acpi.c

Ping... When may I expect reviews for this?

(1) AIUI,
- Michael hasn't acked this series, but he didn't NAK it either -- the
two of us disagree on his most recent review, but that shouldn't be
reason for others not to look at the series,
- he's alrady cooking a series based on this one.

(2) I'm aware that we're in soft freeze for 1.5 now. I'm just saying I
won't touch the HPET or SRAT until this MADT series is sufficiently
acked. I need to be able to trust the structure if I want it to carry
the HPET and the SRAT too. (I don't insist in the slightest on
(co-)owning this task, ie. there's no time pressure from my side. I'm
just pointing out a dependency.)

Thanks
Laszlo



Re: [Qemu-devel] [PATCH 11/11] savevm: remove backward compatibility from bdrv_snapshot_find()

2013-04-24 Thread Pavel Hrdina

On 24.4.2013 05:51, Wenchao Xia wrote:




I think that my whole series is almost done and it would be quickly
accepted and applied upstream. I'll send today the v2 and we will see.

Pavel


   OK, I'll review v2 too to make it faster.


Hi, Pavel
   Sorry for query your progress, I hope to catch up qemu 1.5, so
wonder whether V2 is ready.
   If you agree, I will use your logic in my bdrv_snapshot_find() to
progress. But still, if you can upstream your version quickly, or form
a clean patch for this function, I am happy to rebase on it.:



Hi Wenchao,

np, I have the v2 almost ready and today I'll send that v2 into upstream 
for review.




[Qemu-devel] [PATCH 3/5] console: add qemu_console_lookup_by_device

2013-04-24 Thread Gerd Hoffmann
Look up the QemuConsole for a given device, using the new link.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |1 +
 ui/console.c |   19 +++
 2 files changed, 20 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index 22670d8..c74e791 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -300,6 +300,7 @@ void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
+QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
diff --git a/ui/console.c b/ui/console.c
index 4102e8c..e3ab985 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1596,6 +1596,25 @@ QemuConsole *qemu_console_lookup_by_index(unsigned int 
index)
 return consoles[index];
 }
 
+QemuConsole *qemu_console_lookup_by_device(DeviceState *dev)
+{
+Error *local_err = NULL;
+Object *obj;
+int i;
+
+for (i = 0; i  nb_consoles; i++) {
+if (!consoles[i]) {
+continue;
+}
+obj = object_property_get_link(OBJECT(consoles[i]),
+   device, local_err);
+if (DEVICE(obj) == dev) {
+return consoles[i];
+}
+}
+return NULL;
+}
+
 bool qemu_console_is_visible(QemuConsole *con)
 {
 return (con == active_console) || (con-dcls  0);
-- 
1.7.9.7




Re: [Qemu-devel] [PATCH v4 7/7] hw/i386: build ACPI MADT (APIC) for fw_cfg clients

2013-04-24 Thread Michael S. Tsirkin
On Fri, Apr 19, 2013 at 12:58:03PM +0200, Laszlo Ersek wrote:
 On 04/18/13 22:30, Michael S. Tsirkin wrote:
  On Thu, Apr 18, 2013 at 10:22:24PM +0200, Laszlo Ersek wrote:
  This patch reuses some code from SeaBIOS, which was originally under
  LGPLv2 and then relicensed to GPLv3 or LGPLv3, in QEMU under GPLv2+. This
  relicensing has been acked by all contributors that had contributed to the
  code since the v2-v3 relicense. ACKs approving the v2+ relicensing are
  listed below. The list might include ACKs from people not holding
  copyright on any parts of the reused code, but it's better to err on the
  side of caution and include them.
 
  Affected SeaBIOS files (GPLv2+ license headers added)
  http://thread.gmane.org/gmane.comp.bios.coreboot.seabios/5949:
 
   src/acpi-dsdt-cpu-hotplug.dsl|   15 +++
   src/acpi-dsdt-dbug.dsl   |   15 +++
   src/acpi-dsdt-hpet.dsl   |   15 +++
   src/acpi-dsdt-isa.dsl|   15 +++
   src/acpi-dsdt-pci-crs.dsl|   15 +++
   src/acpi.c   |   14 +-
   src/acpi.h   |   14 ++
   src/ssdt-misc.dsl|   15 +++
   src/ssdt-pcihp.dsl   |   15 +++
   src/ssdt-proc.dsl|   15 +++
   tools/acpi_extract.py|   13 -
   tools/acpi_extract_preprocess.py |   13 -
   12 files changed, 171 insertions(+), 3 deletions(-)
 
  Each one of the listed people agreed to the following:
 
  If you allow the use of your contribution in QEMU under the
  terms of GPLv2 or later as proposed by this patch,
  please respond to this mail including the line:
 
  Acked-by: Name email address
 
Acked-by: Gerd Hoffmann kra...@redhat.com
Acked-by: Jan Kiszka jan.kis...@siemens.com
Acked-by: Jason Baron jba...@akamai.com
Acked-by: David Woodhouse david.woodho...@intel.com
Acked-by: Gleb Natapov g...@redhat.com
Acked-by: Marcelo Tosatti mtosa...@redhat.com
Acked-by: Dave Frodin dave.fro...@se-eng.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Acked-by: Kevin O'Connor ke...@koconnor.net
Acked-by: Laszlo Ersek ler...@redhat.com
Acked-by: Kenji Kaneshige kaneshige.ke...@jp.fujitsu.com
Acked-by: Isaku Yamahata yamah...@valinux.co.jp
Acked-by: Magnus Christensson magnus.christens...@intel.com
Acked-by: Hu Tao hu...@cn.fujitsu.com
Acked-by: Eduardo Habkost ehabk...@redhat.com
 
  The patch incorporates ideas/suggestions from Michael Tsirkin's prototype
  code:
  - hw/i386/pc.c is too big, create new file hw/i386/acpi.c with
i386-specific ACPI table stuff,
  - separate preparation of individual tables from their installation as
fw_cfg files,
  - install these fw_cfg files inside pc_memory_init(), which is shared by
piix4/q35,
  - add the above licensing-related block to the commit message.
 
  Signed-off-by: Laszlo Ersek ler...@redhat.com
  ---
   configure |   12 
   hw/i386/Makefile.objs |1 +
   hw/i386/acpi.h|9 +++
   hw/i386/acpi.c|  159 
  +
   hw/i386/pc.c  |   23 +++
   5 files changed, 204 insertions(+), 0 deletions(-)
   create mode 100644 hw/i386/acpi.h
   create mode 100644 hw/i386/acpi.c
 
  diff --git a/configure b/configure
  index ed49f91..45a5f55 100755
  --- a/configure
  +++ b/configure
  @@ -241,6 +241,7 @@ gtk=
   gtkabi=2.0
   tpm=no
   libssh2=
  +dynamic_acpi=no
   
   # parse CC options first
   for opt do
  @@ -928,6 +929,10 @@ for opt do
 ;;
 --enable-libssh2) libssh2=yes
 ;;
  +  --disable-dynamic-acpi) dynamic_acpi=no
  +  ;;
  +  --enable-dynamic-acpi) dynamic_acpi=yes
  +  ;;
 *) echo ERROR: unknown option $opt; show_help=yes
 ;;
 esac
  @@ -1195,6 +1200,8 @@ echo   --gcov=GCOV  use specified gcov 
  [$gcov_tool]
   echo   --enable-tpm enable TPM support
   echo   --disable-libssh2disable ssh block device support
   echo   --enable-libssh2 enable ssh block device support
  +echo   --disable-dynamic-acpi   disable dynamic ACPI table generation 
  (default)
  +echo   --enable-dynamic-acpienable dynamic ACPI table generation 
  (work in progress)
   echo 
   echo NOTE: The object files are built at the place where configure is 
  launched
   exit 1
  @@ -3573,6 +3580,7 @@ echo gcov enabled  $gcov
   echo TPM support   $tpm
   echo libssh2 support   $libssh2
   echo TPM passthrough   $tpm_passthrough
  +echo dynamic ACPI tables $dynamic_acpi
   
   if test $sdl_too_old = yes; then
   echo - Your SDL version is too old - please upgrade to have SDL support
  @@ -3958,6 +3966,10 @@ if test $virtio_blk_data_plane = yes ; then
 echo 'CONFIG_VIRTIO_BLK_DATA_PLANE=$(CONFIG_VIRTIO)'  $config_host_mak
   fi
   
  +if test $dynamic_acpi = yes; then
  +  echo CONFIG_DYN_ACPI=y  

[Qemu-devel] [PATCH 1/5] console: qom-ify QemuConsole

2013-04-24 Thread Gerd Hoffmann
Just the minimal bits to turn QemuConsoles into Objects.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |   15 +++
 ui/console.c |   15 ++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index e591d74..c8a274d 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -2,6 +2,7 @@
 #define CONSOLE_H
 
 #include ui/qemu-pixman.h
+#include qom/object.h
 #include qapi/qmp/qdict.h
 #include qemu/notify.h
 #include monitor/monitor.h
@@ -106,6 +107,20 @@ void kbd_put_keysym(int keysym);
 
 /* consoles */
 
+#define TYPE_QEMU_CONSOLE qemu-console
+#define QEMU_CONSOLE(obj) \
+OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
+#define QEMU_CONSOLE_GET_CLASS(obj) \
+OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
+#define QEMU_CONSOLE_CLASS(klass) \
+OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
+
+typedef struct QemuConsoleClass QemuConsoleClass;
+
+struct QemuConsoleClass {
+ObjectClass parent_class;
+};
+
 #define QEMU_BIG_ENDIAN_FLAG0x01
 #define QEMU_ALLOCATED_FLAG 0x02
 
diff --git a/ui/console.c b/ui/console.c
index 4f9219e..e9f3080 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -113,6 +113,8 @@ typedef enum {
 } console_type_t;
 
 struct QemuConsole {
+Object parent;
+
 int index;
 console_type_t console_type;
 DisplayState *ds;
@@ -1197,12 +1199,14 @@ static void text_console_update(void *opaque, 
console_ch_t *chardata)
 
 static QemuConsole *new_console(DisplayState *ds, console_type_t console_type)
 {
+Object *obj;
 QemuConsole *s;
 int i;
 
 if (nb_consoles = MAX_CONSOLES)
 return NULL;
-s = g_malloc0(sizeof(QemuConsole));
+obj = object_new(TYPE_QEMU_CONSOLE);
+s = QEMU_CONSOLE(obj);
 if (!active_console || ((active_console-console_type != GRAPHIC_CONSOLE) 

 (console_type == GRAPHIC_CONSOLE))) {
 active_console = s;
@@ -1920,8 +1924,17 @@ static void qemu_chr_parse_vc(QemuOpts *opts, 
ChardevBackend *backend,
 }
 }
 
+static const TypeInfo qemu_console_info = {
+.name = TYPE_QEMU_CONSOLE,
+.parent = TYPE_OBJECT,
+.instance_size = sizeof(QemuConsole),
+.class_size = sizeof(QemuConsoleClass),
+};
+
+
 static void register_types(void)
 {
+type_register_static(qemu_console_info);
 register_char_driver_qapi(vc, CHARDEV_BACKEND_KIND_VC,
   qemu_chr_parse_vc);
 }
-- 
1.7.9.7




[Qemu-devel] [PULL 0/5] console: qom-ify consoles

2013-04-24 Thread Gerd Hoffmann
  Hi,

Here are the console patches, targeting 1.5.  It's just the QemuConsole
QOM-ification and two little fixes.

I'll go hold back the screendump monitor patch until the dust from the
qom api discussions has settled and it is clear which route we are
taking wrt new vs. extended commands.  Which implies it most likely is
1.6 material.

please pull,
  Gerd

The following changes since commit bb71623811686ce3c34ce724f073f5c5dd95f51b:

  Move TPM passthrough specific command line options to backend structure 
(2013-04-23 10:40:40 -0500)

are available in the git repository at:

  git://git.kraxel.org/qemu pixman.v12

for you to fetch changes up to c7b02648d878828dd88868f59b5d666dbbbf1d6d:

  console: zap ds arg from register_displaychangelistener (2013-04-24 10:37:59 
+0200)


Gerd Hoffmann (5):
  console: qom-ify QemuConsole
  console: add device link to QemuConsoles
  console: add qemu_console_lookup_by_device
  console: switch ppm_save to qemu_open
  console: zap ds arg from register_displaychangelistener

 hw/arm/musicpal.c|2 +-
 hw/display/blizzard.c|2 +-
 hw/display/cirrus_vga.c  |4 +--
 hw/display/exynos4210_fimd.c |2 +-
 hw/display/g364fb.c  |2 +-
 hw/display/jazz_led.c|2 +-
 hw/display/milkymist-vgafb.c |2 +-
 hw/display/omap_lcdc.c   |2 +-
 hw/display/pl110.c   |2 +-
 hw/display/pxa2xx_lcd.c  |2 +-
 hw/display/qxl.c |6 ++--
 hw/display/sm501.c   |2 +-
 hw/display/ssd0303.c |2 +-
 hw/display/ssd0323.c |2 +-
 hw/display/tc6393xb.c|2 +-
 hw/display/tcx.c |4 +--
 hw/display/vga-isa-mm.c  |2 +-
 hw/display/vga-isa.c |2 +-
 hw/display/vga-pci.c |2 +-
 hw/display/vmware_vga.c  |7 +++--
 hw/unicore32/puv3.c  |2 +-
 include/ui/console.h |   22 --
 ui/cocoa.m   |2 +-
 ui/console.c |   65 --
 ui/curses.c  |2 +-
 ui/gtk.c |2 +-
 ui/sdl.c |2 +-
 ui/spice-display.c   |2 +-
 ui/vnc.c |2 +-
 29 files changed, 109 insertions(+), 45 deletions(-)



[Qemu-devel] [PATCH 5/5] console: zap ds arg from register_displaychangelistener

2013-04-24 Thread Gerd Hoffmann
We don't have multiple DisplayStates any more,
so passing it in as argument is not needed.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/display/qxl.c |2 +-
 include/ui/console.h |3 +--
 ui/cocoa.m   |2 +-
 ui/console.c |   10 +-
 ui/curses.c  |2 +-
 ui/gtk.c |2 +-
 ui/sdl.c |2 +-
 ui/spice-display.c   |2 +-
 ui/vnc.c |2 +-
 9 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index f8bd7ff..a14296c 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -2080,7 +2080,7 @@ static int qxl_init_primary(PCIDevice *dev)
 qxl-ssd.dcl.ops = display_listener_ops;
 qxl-ssd.dcl.con = vga-con;
 ds = qemu_console_displaystate(vga-con);
-register_displaychangelistener(ds, qxl-ssd.dcl);
+register_displaychangelistener(qxl-ssd.dcl);
 return rc;
 }
 
diff --git a/include/ui/console.h b/include/ui/console.h
index c74e791..3e00c99 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -221,8 +221,7 @@ static inline int is_buffer_shared(DisplaySurface *surface)
 return !(surface-flags  QEMU_ALLOCATED_FLAG);
 }
 
-void register_displaychangelistener(DisplayState *ds,
-DisplayChangeListener *dcl);
+void register_displaychangelistener(DisplayChangeListener *dcl);
 void update_displaychangelistener(DisplayChangeListener *dcl,
   uint64_t interval);
 void unregister_displaychangelistener(DisplayChangeListener *dcl);
diff --git a/ui/cocoa.m b/ui/cocoa.m
index d51462a..1971d9c 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1030,7 +1030,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
 
 // register vga output callbacks
 dcl-ops = dcl_ops;
-register_displaychangelistener(ds, dcl);
+register_displaychangelistener(dcl);
 
 // register cleanup function
 atexit(cocoa_cleanup);
diff --git a/ui/console.c b/ui/console.c
index 3835316..a13fb64 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -178,6 +178,7 @@ static int nb_consoles = 0;
 
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
 static void dpy_refresh(DisplayState *s);
+static DisplayState *get_alloc_displaystate(void);
 
 static void gui_update(void *opaque)
 {
@@ -1309,15 +1310,14 @@ void qemu_free_displaysurface(DisplaySurface *surface)
 g_free(surface);
 }
 
-void register_displaychangelistener(DisplayState *ds,
-DisplayChangeListener *dcl)
+void register_displaychangelistener(DisplayChangeListener *dcl)
 {
 QemuConsole *con;
 
 trace_displaychangelistener_register(dcl, dcl-ops-dpy_name);
-dcl-ds = ds;
-QLIST_INSERT_HEAD(ds-listeners, dcl, next);
-gui_setup_refresh(ds);
+dcl-ds = get_alloc_displaystate();
+QLIST_INSERT_HEAD(dcl-ds-listeners, dcl, next);
+gui_setup_refresh(dcl-ds);
 if (dcl-con) {
 dcl-con-dcls++;
 con = dcl-con;
diff --git a/ui/curses.c b/ui/curses.c
index a85a7da..289a955 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -359,7 +359,7 @@ void curses_display_init(DisplayState *ds, int full_screen)
 
 dcl = (DisplayChangeListener *) g_malloc0(sizeof(DisplayChangeListener));
 dcl-ops = dcl_ops;
-register_displaychangelistener(ds, dcl);
+register_displaychangelistener(dcl);
 
 invalidate = 1;
 }
diff --git a/ui/gtk.c b/ui/gtk.c
index 4110342..42e3c0a 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1470,7 +1470,7 @@ void gtk_display_init(DisplayState *ds)
 
 gtk_widget_show_all(s-window);
 
-register_displaychangelistener(ds, s-dcl);
+register_displaychangelistener(s-dcl);
 
 global_state = s;
 }
diff --git a/ui/sdl.c b/ui/sdl.c
index c9f2928..39a42d6 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -937,7 +937,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, 
int no_frame)
 
 dcl = g_malloc0(sizeof(DisplayChangeListener));
 dcl-ops = dcl_ops;
-register_displaychangelistener(ds, dcl);
+register_displaychangelistener(dcl);
 
 mouse_mode_notifier.notify = sdl_mouse_mode_change;
 qemu_add_mouse_mode_change_notifier(mouse_mode_notifier);
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 53c19be..82d8b9f 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -625,7 +625,7 @@ void qemu_spice_display_init(DisplayState *ds)
 
 ssd-dcl.ops = display_listener_ops;
 ssd-dcl.con = qemu_console_lookup_by_index(0);
-register_displaychangelistener(ds, ssd-dcl);
+register_displaychangelistener(ssd-dcl);
 
 qemu_spice_create_host_primary(ssd);
 }
diff --git a/ui/vnc.c b/ui/vnc.c
index 8ee66b7..86fe1dd 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2832,7 +2832,7 @@ void vnc_display_init(DisplayState *ds)
 vnc_start_worker_thread();
 
 vs-dcl.ops = dcl_ops;
-register_displaychangelistener(ds, vs-dcl);
+register_displaychangelistener(vs-dcl);
 }
 
 
-- 
1.7.9.7




[Qemu-devel] [PATCH] sheepdog: fix loadvm operation

2013-04-24 Thread Liu Yuan
From: Liu Yuan tailai...@taobao.com

Currently the 'loadvm' opertaion works as following:
1. switch to the snapshot
2. mark current working VDI as a snapshot
3. rely on sd_create_branch to create a new working VDI based on the snapshot

This works not the same as other format as QCOW2. For e.g,

qemu  savevm # get a live snapshot snap1
qemu  savevm # snap2
qemu  loadvm 1 # This will steally create snap3 of the working VDI

Which will result in following snapshot chain:

base -- snap1 -- snap2 -- snap3
  ^
  |
  working VDI

snap3 was unnecessarily created and might be annoying users.

This patch discard the unnecessary 'snap3' creation. and implement
rollback(loadvm) operation to the specified snapshot by
1. switch to the snapshot
2. delete working VDI
3. rely on sd_create_branch to create a new working VDI based on the snapshot

The snapshot chain for above example will be:

base -- snap1 -- snap2
  ^
  |
  working VDI

Cc: qemu-devel@nongnu.org
Cc: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp
Cc: Kevin Wolf kw...@redhat.com
Cc: Stefan Hajnoczi stefa...@redhat.com
Signed-off-by: Liu Yuan tailai...@taobao.com
---
 block/sheepdog.c |   42 +-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 2fe0783..811f10d 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -36,6 +36,7 @@
 #define SD_OP_GET_VDI_INFO   0x14
 #define SD_OP_READ_VDIS  0x15
 #define SD_OP_FLUSH_VDI  0x16
+#define SD_OP_DEL_VDI0x17
 
 #define SD_FLAG_CMD_WRITE0x01
 #define SD_FLAG_CMD_COW  0x02
@@ -1553,7 +1554,7 @@ static int sd_create_branch(BDRVSheepdogState *s)
 
 buf = g_malloc(SD_INODE_SIZE);
 
-ret = do_sd_create(s, s-name, s-inode.vdi_size, s-inode.vdi_id, vid, 
1);
+ret = do_sd_create(s, s-name, s-inode.vdi_size, s-inode.vdi_id, vid, 
0);
 if (ret) {
 goto out;
 }
@@ -1869,6 +1870,40 @@ cleanup:
 return ret;
 }
 
+/* Delete current working VDI by the name */
+static int sd_delete(BDRVSheepdogState *s, char *name)
+{
+unsigned int wlen = SD_MAX_VDI_LEN;
+SheepdogVdiReq hdr = {
+.opcode = SD_OP_DEL_VDI,
+.vdi_id = s-inode.vdi_id,
+.data_length = wlen,
+.flags = SD_FLAG_CMD_WRITE,
+};
+SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)hdr;
+int fd, ret;
+
+fd = connect_to_sdog(s);
+if (fd  0) {
+return fd;
+}
+
+ret = send_co_req(fd, (SheepdogReq *)hdr, name, wlen);
+closesocket(fd);
+if (!ret || rsp-result != SD_RES_SUCCESS) {
+error_report(%s, %s, sd_strerror(rsp-result), name);
+return -1;
+}
+
+return 0;
+}
+
+/*
+ * We implement rollback(loadvm) operation to the specified snapshot by
+ * 1) switch to the snapshot
+ * 2) delete working VDI
+ * 3) rely on sd_create_branch to create a new working VDI based on the 
snapshot
+ */
 static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
 {
 BDRVSheepdogState *s = bs-opaque;
@@ -1924,6 +1959,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const 
char *snapshot_id)
 
 s-is_snapshot = true;
 
+ret = sd_delete(s, vdi);
+if (ret) {
+error_report(Failed to delete %s, s-name);
+}
+
 g_free(buf);
 g_free(old_s);
 
-- 
1.7.9.5




Re: [Qemu-devel] [Qemu-trivial] [PATCH] configure: Undefine _FORTIFY_SOURCE prior using it

2013-04-24 Thread Markus Armbruster
Michal Privoznik mpriv...@redhat.com writes:

 On 06.02.2013 16:09, Paolo Bonzini wrote:
 Il 06/02/2013 15:49, Stefan Hajnoczi ha scritto:
 I don't think that's necessary. The 2nd level is the highest one
 [1] or [2].
 It seems like in my case it's compiler who's defining the macro:

 $ echo int main() {return 0;} | gcc -D_FORTIFY_SOURCE=2 -x c -
 command-line:0:0: warning: _FORTIFY_SOURCE redefined [enabled
 by default]
 stdin:1:0: note: this is the location of the previous definition

 in which case we must undefine it. However, if the _FORTIFY_SOURCE is
 defined by environment, I think we should not override it. So maybe need
 a different approach. Anyway, with current state I cannot
 compile. I am using
 gcc version 4.7.2 (Gentoo 4.7.2 p1.3, pie-0.5.5)
 It would be nice to fix this for QEMU 1.4 but my gcc FORTIFY_SOURCE foo
 is not strong enough to know what the best approach is here.

 Reviews from anyone else?
 
 I would prefer to avoid having _FORTIFY_SOURCE completely, and let
 distros do it.  Alternatively, tie it to a new --enable switch which
 would do -U -D.
 
 But if there is a real problem for 1.4 the patch looks good.
 
 Paolo
 

 Sorry for resurrecting such old thread, but what's the conclusion then?

Thread petered out without a conclusion?

 I keep hitting this problem and I am tired of having one single patch on
 the top of HEAD. And I bet others ran into this as well.

Few things focus discussions as well as a patch does.  Suggest to post
one to get things going again.



[Qemu-devel] [PATCH 1/2] input: make QEMUPutLEDEntry + QEMUPutMouseEntry private

2013-04-24 Thread Gerd Hoffmann
There is no need for anybody outside ui/input.c to access the
struct elements.  Move the definitions, leaving only the typedefs
in the header files.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |   19 ++-
 ui/input.c   |   18 ++
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index e591d74..5cc5d0c 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -28,23 +28,8 @@ typedef void QEMUPutKBDEvent(void *opaque, int keycode);
 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int 
buttons_state);
 
-typedef struct QEMUPutMouseEntry {
-QEMUPutMouseEvent *qemu_put_mouse_event;
-void *qemu_put_mouse_event_opaque;
-int qemu_put_mouse_event_absolute;
-char *qemu_put_mouse_event_name;
-
-int index;
-
-/* used internally by qemu for handling mice */
-QTAILQ_ENTRY(QEMUPutMouseEntry) node;
-} QEMUPutMouseEntry;
-
-typedef struct QEMUPutLEDEntry {
-QEMUPutLEDEvent *put_led;
-void *opaque;
-QTAILQ_ENTRY(QEMUPutLEDEntry) next;
-} QEMUPutLEDEntry;
+typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
+typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
 
 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
 void qemu_remove_kbd_event_handler(void);
diff --git a/ui/input.c b/ui/input.c
index ecfeb43..d8793e7 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -29,6 +29,24 @@
 #include qmp-commands.h
 #include qapi-types.h
 
+struct QEMUPutMouseEntry {
+QEMUPutMouseEvent *qemu_put_mouse_event;
+void *qemu_put_mouse_event_opaque;
+int qemu_put_mouse_event_absolute;
+char *qemu_put_mouse_event_name;
+
+int index;
+
+/* used internally by qemu for handling mice */
+QTAILQ_ENTRY(QEMUPutMouseEntry) node;
+};
+
+struct QEMUPutLEDEntry {
+QEMUPutLEDEvent *put_led;
+void *opaque;
+QTAILQ_ENTRY(QEMUPutLEDEntry) next;
+};
+
 static QEMUPutKBDEvent *qemu_put_kbd_event;
 static void *qemu_put_kbd_event_opaque;
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = 
QTAILQ_HEAD_INITIALIZER(led_handlers);
-- 
1.7.9.7




[Qemu-devel] [PATCH 2/2] input: introduce keyboard handler list

2013-04-24 Thread Gerd Hoffmann
Add a linked list of keyboard handlers.  Added handlers will go
to the head of the list.  Removed handlers will be zapped from
the list.  The head of the list will be used for events.

This fixes the keyboard-dead-after-usb-kbd-unplug issue, key events
will be re-routed to the ps/2 kbd instead of being discarded.

[ v2: fix cut+paste bug found my Markus ]

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/input/hid.c |4 ++--
 include/hw/input/hid.h |1 +
 include/ui/console.h   |6 --
 ui/input.c |   37 +
 4 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index 5fbde98..14b3125 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -415,7 +415,7 @@ void hid_free(HIDState *hs)
 {
 switch (hs-kind) {
 case HID_KEYBOARD:
-qemu_remove_kbd_event_handler();
+qemu_remove_kbd_event_handler(hs-kbd.eh_entry);
 break;
 case HID_MOUSE:
 case HID_TABLET:
@@ -431,7 +431,7 @@ void hid_init(HIDState *hs, int kind, HIDEventFunc event)
 hs-event = event;
 
 if (hs-kind == HID_KEYBOARD) {
-qemu_add_kbd_event_handler(hid_keyboard_event, hs);
+hs-kbd.eh_entry = qemu_add_kbd_event_handler(hid_keyboard_event, hs);
 } else if (hs-kind == HID_MOUSE) {
 hs-ptr.eh_entry = qemu_add_mouse_event_handler(hid_pointer_event, hs,
 0, QEMU HID Mouse);
diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h
index 56c71ed..2567879 100644
--- a/include/hw/input/hid.h
+++ b/include/hw/input/hid.h
@@ -31,6 +31,7 @@ typedef struct HIDKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int32_t keys;
+QEMUPutKbdEntry *eh_entry;
 } HIDKeyboardState;
 
 struct HIDState {
diff --git a/include/ui/console.h b/include/ui/console.h
index 5cc5d0c..1c82f51 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -29,10 +29,12 @@ typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int 
buttons_state);
 
 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
+typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
-void qemu_remove_kbd_event_handler(void);
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/ui/input.c b/ui/input.c
index d8793e7..8ca1a03 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -41,18 +41,25 @@ struct QEMUPutMouseEntry {
 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
 };
 
+struct QEMUPutKbdEntry {
+QEMUPutKBDEvent *put_kbd;
+void *opaque;
+QTAILQ_ENTRY(QEMUPutKbdEntry) next;
+};
+
 struct QEMUPutLEDEntry {
 QEMUPutLEDEvent *put_led;
 void *opaque;
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 };
 
-static QEMUPutKBDEvent *qemu_put_kbd_event;
-static void *qemu_put_kbd_event_opaque;
-static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = 
QTAILQ_HEAD_INITIALIZER(led_handlers);
+static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
+QTAILQ_HEAD_INITIALIZER(led_handlers);
+static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
+QTAILQ_HEAD_INITIALIZER(kbd_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
 QTAILQ_HEAD_INITIALIZER(mouse_handlers);
-static NotifierList mouse_mode_notifiers = 
+static NotifierList mouse_mode_notifiers =
 NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
 
 static const int key_defs[] = {
@@ -304,16 +311,20 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, 
int64_t hold_time,
muldiv64(get_ticks_per_sec(), hold_time, 1000));
 }
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void 
*opaque)
 {
-qemu_put_kbd_event_opaque = opaque;
-qemu_put_kbd_event = func;
+QEMUPutKbdEntry *entry;
+
+entry = g_malloc0(sizeof(QEMUPutKbdEntry));
+entry-put_kbd = func;
+entry-opaque = opaque;
+QTAILQ_INSERT_HEAD(kbd_handlers, entry, next);
+return entry;
 }
 
-void qemu_remove_kbd_event_handler(void)
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 {
-qemu_put_kbd_event_opaque = NULL;
-qemu_put_kbd_event = NULL;
+QTAILQ_REMOVE(kbd_handlers, entry, next);
 }
 
 static void check_mode_change(void)
@@ -397,11 +408,13 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
+QEMUPutKbdEntry *entry = QTAILQ_FIRST(kbd_handlers);
+
 if 

[Qemu-devel] [RESEND PATCH 0/2] input: kbd handler list

2013-04-24 Thread Gerd Hoffmann
  Hi,

Tiny series which adds a list for keyboard handlers,
simliar to the one we have for mice.  Lingering
unmodified in a git branch for a while, just noticed
it isn't in yet, so I'm resending it.

please apply,
  Gerd

Gerd Hoffmann (2):
  input: make QEMUPutLEDEntry + QEMUPutMouseEntry private
  input: introduce keyboard handler list

 hw/input/hid.c |4 ++--
 include/hw/input/hid.h |1 +
 include/ui/console.h   |   27 ++--
 ui/input.c |   55 +---
 4 files changed, 53 insertions(+), 34 deletions(-)

-- 
1.7.9.7




[Qemu-devel] [PATCH 2/3] vnc: Support for LED state extension

2013-04-24 Thread Lei Li
Signed-off-by: Lei Li li...@linux.vnet.ibm.com
---
 ui/vnc.c |   45 +
 ui/vnc.h |4 +++-
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index f574962..44189d7 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1522,6 +1522,42 @@ static void press_key(VncState *vs, int keysym)
 kbd_put_keycode(keycode | SCANCODE_UP);
 }
 
+static int current_led_state(VncState *vs)
+{
+int ledstate = 0;
+
+if (vs-modifiers_state[0x46]) {
+ledstate |= QEMU_SCROLL_LOCK_LED;
+}
+if (vs-modifiers_state[0x45]) {
+ledstate |= QEMU_NUM_LOCK_LED;
+}
+if (vs-modifiers_state[0x3a]) {
+ledstate |= QEMU_CAPS_LOCK_LED;
+}
+
+return ledstate;
+}
+
+static void vnc_led_state_change(VncState *vs)
+{
+int ledstate = 0;
+
+if (!vnc_has_feature(vs, VNC_FEATURE_LED_STATE)) {
+return;
+}
+
+ledstate = current_led_state(vs);
+vnc_lock_output(vs);
+vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);
+vnc_write_u8(vs, 0);
+vnc_write_u16(vs, 1);
+vnc_framebuffer_update(vs, 0, 0, 1, 1, VNC_ENCODING_LED_STATE);
+vnc_write_u8(vs, ledstate);
+vnc_unlock_output(vs);
+vnc_flush(vs);
+}
+
 static void kbd_leds(void *opaque, int ledstate)
 {
 VncState *vs = opaque;
@@ -1540,6 +1576,11 @@ static void kbd_leds(void *opaque, int ledstate)
 if (vs-modifiers_state[0x46] != scr) {
 vs-modifiers_state[0x46] = scr;
 }
+
+/* Sending the current led state message to the client */
+if (ledstate != current_led_state(vs)) {
+vnc_led_state_change(vs);
+}
 }
 
 static void do_key_event(VncState *vs, int down, int keycode, int sym)
@@ -1893,6 +1934,9 @@ static void set_encodings(VncState *vs, int32_t 
*encodings, size_t n_encodings)
 case VNC_ENCODING_WMVi:
 vs-features |= VNC_FEATURE_WMVI_MASK;
 break;
+case VNC_ENCODING_LED_STATE:
+vs-features |= VNC_FEATURE_LED_STATE_MASK;
+break;
 case VNC_ENCODING_COMPRESSLEVEL0 ... VNC_ENCODING_COMPRESSLEVEL0 + 9:
 vs-tight.compression = (enc  0x0F);
 break;
@@ -1908,6 +1952,7 @@ static void set_encodings(VncState *vs, int32_t 
*encodings, size_t n_encodings)
 }
 vnc_desktop_resize(vs);
 check_pointer_type_change(vs-mouse_mode_notifier, NULL);
+vnc_led_state_change(vs);
 }
 
 static void set_pixel_conversion(VncState *vs)
diff --git a/ui/vnc.h b/ui/vnc.h
index ad1dec2..e873377 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -384,6 +384,7 @@ enum {
 #define VNC_ENCODING_EXT_KEY_EVENT0XFEFE /* -258 */
 #define VNC_ENCODING_AUDIO0XFEFD /* -259 */
 #define VNC_ENCODING_TIGHT_PNG0xFEFC /* -260 */
+#define VNC_ENCODING_LED_STATE0XFEFB /* -261 */
 #define VNC_ENCODING_WMVi 0x574D5669
 
 /*
@@ -422,6 +423,7 @@ enum {
 #define VNC_FEATURE_TIGHT_PNG8
 #define VNC_FEATURE_ZRLE 9
 #define VNC_FEATURE_ZYWRLE  10
+#define VNC_FEATURE_LED_STATE   11
 
 #define VNC_FEATURE_RESIZE_MASK  (1  VNC_FEATURE_RESIZE)
 #define VNC_FEATURE_HEXTILE_MASK (1  VNC_FEATURE_HEXTILE)
@@ -434,7 +436,7 @@ enum {
 #define VNC_FEATURE_TIGHT_PNG_MASK   (1  VNC_FEATURE_TIGHT_PNG)
 #define VNC_FEATURE_ZRLE_MASK(1  VNC_FEATURE_ZRLE)
 #define VNC_FEATURE_ZYWRLE_MASK  (1  VNC_FEATURE_ZYWRLE)
-
+#define VNC_FEATURE_LED_STATE_MASK   (1  VNC_FEATURE_LED_STATE)
 
 /* Client - Server message IDs */
 #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT   0
-- 
1.7.7.6




[Qemu-devel] [PATCH 3/3] doc: document the Pseudo-encoding of LED state

2013-04-24 Thread Lei Li
Signed-off-by: Lei Li li...@linux.vnet.ibm.com
---
 docs/vnc-ledstate-Pseudo-encoding.txt |   40 +
 1 files changed, 40 insertions(+), 0 deletions(-)
 create mode 100644 docs/vnc-ledstate-Pseudo-encoding.txt

diff --git a/docs/vnc-ledstate-Pseudo-encoding.txt 
b/docs/vnc-ledstate-Pseudo-encoding.txt
new file mode 100644
index 000..0c312cf
--- /dev/null
+++ b/docs/vnc-ledstate-Pseudo-encoding.txt
@@ -0,0 +1,40 @@
+VNC LED state Pseudo-encoding
+=
+
+Introduction
+
+
+This document describes the Pseudo-encoding of LED state for RFB which
+is the protocol used in VNC as reference link below:
+
+http://tigervnc.svn.sourceforge.net/viewvc/tigervnc/rfbproto/rfbproto.rst?content-type=text/plain
+
+When accessing a guest by console through VNC, there might be mismatch
+between the lock keys notification LED on the computer running the VNC
+client session and the current status of the lock keys on the guest
+machine.
+
+To solve this problem it attempts to add LED state Pseudo-encoding
+extension to VNC protocol to deal with setting LED state.
+
+Pseudo-encoding
+---
+
+This Pseudo-encoding requested by client declares to server that it supports
+LED state extensions to the protocol.
+
+The Pseudo-encoding number for LED state defined as:
+
+=== ===
+Number  Name
+=== ===
+-261'LED state Pseudo-encoding'_
+=== ===
+
+LED state Pseudo-enconding
+--
+
+The LED state Pseudo-encoding describes the encoding of LED state which
+consists of 3 bits, each bit represents the Caps, Num, and Scroll lock
+key respectively. '1' indicates that the LED should be on and '0' should
+be off.
-- 
1.7.7.6




[Qemu-devel] [PATCH 1/3] vnc: Add SCROLL lock key to kbd_leds

2013-04-24 Thread Lei Li
Signed-off-by: Lei Li li...@linux.vnet.ibm.com
---
 ui/vnc.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 8ee66b7..f574962 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1525,10 +1525,11 @@ static void press_key(VncState *vs, int keysym)
 static void kbd_leds(void *opaque, int ledstate)
 {
 VncState *vs = opaque;
-int caps, num;
+int caps, num, scr;
 
 caps = ledstate  QEMU_CAPS_LOCK_LED ? 1 : 0;
 num  = ledstate  QEMU_NUM_LOCK_LED  ? 1 : 0;
+scr  = ledstate  QEMU_SCROLL_LOCK_LED ? 1 : 0;
 
 if (vs-modifiers_state[0x3a] != caps) {
 vs-modifiers_state[0x3a] = caps;
@@ -1536,6 +1537,9 @@ static void kbd_leds(void *opaque, int ledstate)
 if (vs-modifiers_state[0x45] != num) {
 vs-modifiers_state[0x45] = num;
 }
+if (vs-modifiers_state[0x46] != scr) {
+vs-modifiers_state[0x46] = scr;
+}
 }
 
 static void do_key_event(VncState *vs, int down, int keycode, int sym)
-- 
1.7.7.6




[Qemu-devel] [PATCH 0/3 v3] Support for LED state extension to Qemu VNC server

2013-04-24 Thread Lei Li
Hi guys,

This patch series tries to add support for LED state
extension to Qemu VNC server. The proposal has been sent
few days ago as link below:

http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg01421.html

The previous version as link:

http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg03988.html

Pleae let me know if there is anything else need be improved.

Thanks!


Changes since v2:
  - Address the comments from Anthony includes:
- Just send 1 instead of the actual width and height.
- Improve the document by adding the Pseudo-encoding number
  and simplify the description of the LED state encoding.

Changes since v1:
  - Address the comments from Anthony includes:
- Use Pseudo-encoding for led state;
- Get rid of send_ext_leds_state_ack;
- Add document for the led state Pseudo-encoding.




Re: [Qemu-devel] [PATCH 17/21] introduce memory_region_get_address() and use it in kvm/ioapic

2013-04-24 Thread Paolo Bonzini
 So how about:
  MemoryRegionSection memory_region_find(MemoryRegion *address_space,
hwaddr addr, uint64_t size);
 becomes
  MemoryRegionSection address_space_find_region_by_addr(
AddressSpace *address_space,
hwaddr addr, uint64_t size);
 (bit of a mouthful, but never mind)
 
  void memory_global_sync_dirty_bitmap(MemoryRegion *address_space);
 becomes
  void address_space_sync_dirty_bitmap(AddressSpace *address_space);

I think the latter makes definite sense, I am not quite as sure about the
former.

Looking at framebuffer.c's use of memory_region_find, here you really want
to go from the local view to a global one in order to look at global
data structures such as the dirty bitmap.  So it is right to have
memory_region_find as a MemoryRegion operation, even though right now
it is always passed an AddressSpace.

Communicating the absolute address to KVM is another example of
this local-global translation.  Hence, my suggestion is to remove
memory_region_find's limitation on the first argument, and make it work
on nested regions too.  With this change, memory_region_find() nicely
fits Igor's use case.

Not coincidentially, the additional code in memory_region_find() is
very similar to Igor's memory_region_get_address().

See the attached patch, which I tested on master.  Igor, can you try it
with iccbus?

Paolo

-- 8 
From 953460fa8ee9f9e7243ea34eb57a901102be9307 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini pbonz...@redhat.com
Date: Tue, 23 Apr 2013 10:29:51 +0200
Subject: [RFC PATCH 17/21] extend memory_region_find() and use it in kvm/ioapic

kvm/ioapic is relying on the fact that SysBus device
maps mmio regions with offset counted from start of system memory.
But if ioapic's region is moved to another sub-region which doesn't
start at the beginning of system memory then using offset isn't correct.

To fix kvm/ioapic, extend memory_region_find() so that it can help
retrieving the absolute region address and the respective address space.

The patch is a no-op in case mr is parentless, i.e. mr-addr == 0
and mr-parent == NULL.

Based on a patch by Igor Mammedov. imamm...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/i386/kvm/ioapic.c  |9 -
 include/exec/memory.h |   13 +++--
 memory.c  |   19 ++-
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c
index a3bd519..7564d07 100644
--- a/hw/i386/kvm/ioapic.c
+++ b/hw/i386/kvm/ioapic.c
@@ -89,14 +89,21 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
 {
 struct kvm_irqchip chip;
 struct kvm_ioapic_state *kioapic;
+MemoryRegionSection mrs;
 int ret, i;
 
+mrs = memory_region_find(s-io_memory, 0, 0x1000);
+if (mrs.mr != s-io_memory || mrs.offset_within_region != 0) {
+fprintf(stderr, cannot find IOAPIC base\n);
+abort();
+}
+
 chip.chip_id = KVM_IRQCHIP_IOAPIC;
 kioapic = chip.chip.ioapic;
 
 kioapic-id = s-id;
 kioapic-ioregsel = s-ioregsel;
-kioapic-base_address = s-busdev.mmio[0].addr;
+kioapic-base_address = mrs.offset_within_address_space;
 kioapic-irr = s-irr;
 for (i = 0; i  IOAPIC_NUM_PINS; i++) {
 kioapic-redirtbl[i].bits = s-ioredtbl[i];
diff --git a/include/exec/memory.h b/include/exec/memory.h
index eb9e659..5854d19 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -725,17 +725,18 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
  *
  * Returns a #MemoryRegionSection that describes a contiguous overlap.
  * It will have the following characteristics:
- *.@offset_within_address_space = @addr
- *.@offset_within_address_space + .@size = @addr + @size
  *.@size = 0 iff no overlap was found
  *.@mr is non-%NULL iff an overlap was found
  *
- * @address_space: a top-level (i.e. parentless) region that contains
- *   the region to be found
- * @addr: start of the area within @address_space to be searched
+ * If @mr is parent-less,
+ *.@offset_within_address_space = @addr
+ *.@offset_within_address_space + .@size = @addr + @size
+ *
+ * @mr: a (possibly indirect) parent that contains the region to be found
+ * @addr: start of the area within @as to be searched
  * @size: size of the area to be searched
  */
-MemoryRegionSection memory_region_find(MemoryRegion *address_space,
+MemoryRegionSection memory_region_find(MemoryRegion *mr,
hwaddr addr, uint64_t size);
 
 /**
diff --git a/memory.c b/memory.c
index c82bd12..dba0a4b 100644
--- a/memory.c
+++ b/memory.c
@@ -1451,15 +1451,24 @@ static FlatRange *address_space_lookup(AddressSpace 
*as, AddrRange addr)
sizeof(FlatRange), cmp_flatrange_addr);
 }
 
-MemoryRegionSection memory_region_find(MemoryRegion *address_space,
+MemoryRegionSection 

Re: [Qemu-devel] [PATCH 17/21] introduce memory_region_get_address() and use it in kvm/ioapic

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 12:22, Paolo Bonzini ha scritto:
 diff --git a/memory.c b/memory.c
 index c82bd12..dba0a4b 100644
 --- a/memory.c
 +++ b/memory.c
 @@ -1451,15 +1451,24 @@ static FlatRange *address_space_lookup(AddressSpace 
 *as, AddrRange addr)
 sizeof(FlatRange), cmp_flatrange_addr);
  }
  
 -MemoryRegionSection memory_region_find(MemoryRegion *address_space,
 +MemoryRegionSection memory_region_find(MemoryRegion *mr,
 hwaddr addr, uint64_t size)
  {
 -AddressSpace *as = memory_region_to_address_space(address_space);
 -AddrRange range = addrrange_make(int128_make64(addr),
 - int128_make64(size));
 -FlatRange *fr = address_space_lookup(as, range);
  MemoryRegionSection ret = { .mr = NULL, .size = 0 };
 +MemoryRegion *root;
 +AddressSpace *as;
 +AddrRange range;
 +FlatRange *fr;
 +
 +addr += mr-addr;
 +for (root = mr; root-parent; ) {
 +root = root-parent;
 +addr += root-addr;
 +}
  
 +as = memory_region_to_address_space(root);
 +range = addrrange_make(int128_make64(addr), int128_make64(size));
 +fr = address_space_lookup(as, range);
  if (!fr) {
  return ret;
  }
 

Looking at the code again, mrs.address_space is not filled in.  This should
be squashed in too for completeness.

diff --git a/memory.c b/memory.c
index dba0a4b..1916937 100644
--- a/memory.c
+++ b/memory.c
@@ -1479,6 +1479,7 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
 }
 
 ret.mr = fr-mr;
+ret.address_space = as;
 range = addrrange_intersection(range, fr-addr);
 ret.offset_within_region = fr-offset_in_region;
 ret.offset_within_region += int128_get64(int128_sub(range.start,

Paolo



[Qemu-devel] question about concurrent block job

2013-04-24 Thread Zhangleiqiang
Hi, Paolo:
I found qemu does not support concurrently running multiple block jobs 
of the same drive (limited by the bs-in_use field).  But there are indeed some 
type of block job can run concurrently, such as running block stream job while 
running drive mirror, etc.  Am I right ? Is it necessary to introduce the 
concurrency mechanism in qemu ?

Thanks.

--
Leiqzhang

Best Regards




[Qemu-devel] [PATCH] ich9: kill cmos_s3

2013-04-24 Thread Hu Tao

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 hw/acpi/ich9.c |  2 +-
 hw/i386/pc_q35.c   | 15 +--
 hw/isa/lpc_ich9.c  |  4 ++--
 include/hw/acpi/ich9.h |  2 +-
 include/hw/i386/ich9.h |  2 +-
 5 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index e663d29..4a17f32 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -203,7 +203,7 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 }
 
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
-  qemu_irq sci_irq, qemu_irq cmos_s3)
+  qemu_irq sci_irq)
 {
 memory_region_init(pm-io, ich9-pm, ICH9_PMIO_SIZE);
 memory_region_set_enabled(pm-io, false);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6ac1a89..e5f417e 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -45,17 +45,6 @@
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS 6
 
-/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
- *BIOS will read it and start S3 resume at POST Entry */
-static void pc_cmos_set_s3_resume(void *opaque, int irq, int level)
-{
-ISADevice *s = opaque;
-
-if (level) {
-rtc_set_memory(s, 0xF, 0xFE);
-}
-}
-
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
 {
@@ -84,7 +73,6 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 int i;
 ICH9LPCState *ich9_lpc;
 PCIDevice *ahci;
-qemu_irq *cmos_s3;
 
 pc_cpus_init(cpu_model);
 pc_acpi_init(q35-acpi-dsdt.aml);
@@ -175,8 +163,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 pc_basic_device_init(isa_bus, gsi, rtc_state, floppy, false);
 
 /* connect pm stuff to lpc */
-cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
-ich9_lpc_pm_init(lpc, *cmos_s3);
+ich9_lpc_pm_init(lpc);
 
 /* ahci and SATA device, for q35 1 ahci controller is built-in */
 ahci = pci_create_simple_multifunction(host_bus,
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index d116075..667e882 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -356,13 +356,13 @@ static void ich9_set_sci(void *opaque, int irq_num, int 
level)
 }
 }
 
-void ich9_lpc_pm_init(PCIDevice *lpc_pci, qemu_irq cmos_s3)
+void ich9_lpc_pm_init(PCIDevice *lpc_pci)
 {
 ICH9LPCState *lpc = ICH9_LPC_DEVICE(lpc_pci);
 qemu_irq *sci_irq;
 
 sci_irq = qemu_allocate_irqs(ich9_set_sci, lpc, 1);
-ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0], cmos_s3);
+ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0]);
 
 ich9_lpc_reset(lpc-d.qdev);
 }
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 85b82ee..b1fe71f 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -45,7 +45,7 @@ typedef struct ICH9LPCPMRegs {
 } ICH9LPCPMRegs;
 
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
-  qemu_irq sci_irq, qemu_irq cmos_s3_resume);
+  qemu_irq sci_irq);
 void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base);
 extern const VMStateDescription vmstate_ich9_pm;
 
diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h
index 51d5981..c5f637b 100644
--- a/include/hw/i386/ich9.h
+++ b/include/hw/i386/ich9.h
@@ -18,7 +18,7 @@
 void ich9_lpc_set_irq(void *opaque, int irq_num, int level);
 int ich9_lpc_map_irq(PCIDevice *pci_dev, int intx);
 PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin);
-void ich9_lpc_pm_init(PCIDevice *pci_lpc, qemu_irq cmos_s3);
+void ich9_lpc_pm_init(PCIDevice *pci_lpc);
 PCIBus *ich9_d2pbr_init(PCIBus *bus, int devfn, int sec_bus);
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base);
 
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH] ui/gtk: Add Turkish translations

2013-04-24 Thread Andreas Färber
Anthony,

Am 23.04.2013 12:04, schrieb Ozan Çağlayan:
 Signed-off-by: Ozan Çağlayan ozan...@gmail.com
 ---
  po/tr.po | 62 ++
  1 file changed, 62 insertions(+)
  create mode 100644 po/tr.po
 
 diff --git a/po/tr.po b/po/tr.po
 new file mode 100644
 index 000..4faefbd
 --- /dev/null
 +++ b/po/tr.po
 @@ -0,0 +1,62 @@
 +# Turkish translation for QEMU.
 +# This file is put in the public domain.

I see this got committed - didn't you say a while ago to malc that in
the public domain was not a legally valid license?

Andreas

 +# Ozan Çağlayan ozan...@gmail.com, 2013.
 +#
 +msgid 
 +msgstr 
 +Project-Id-Version: QEMU 1.4.50\n
 +Report-Msgid-Bugs-To: qemu-devel@nongnu.org\n
 +POT-Creation-Date: 2013-04-22 18:33+0300\n
 +PO-Revision-Date: 2013-04-22 18:35+0300\n
 +Last-Translator: Ozan Çağlayan ozan...@gmail.com\n
 +Language-Team: Türkçe \n
 +Language: \n
 +MIME-Version: 1.0\n
 +Content-Type: text/plain; charset=UTF-8\n
 +Content-Transfer-Encoding: 8bit\n
 +Plural-Forms: nplurals=1; plural=0;\n
 +X-Generator: Gtranslator 2.91.6\n
 +
 +#: ../ui/gtk.c:214
 +msgid  - Press Ctrl+Alt+G to release grab
 +msgstr  - Yakalamayı durdurmak için Ctrl+Alt+G tuşlarına basın
 +
 +#: ../ui/gtk.c:218
 +msgid  [Paused]
 +msgstr  [Duraklatıldı]
 +
 +#: ../ui/gtk.c:1282
 +msgid _Machine
 +msgstr _Makine
 +
 +#: ../ui/gtk.c:1284
 +msgid _Pause
 +msgstr _Duraklat
 +
 +#: ../ui/gtk.c:1290
 +msgid _Reset
 +msgstr _Sıfırla
 +
 +#: ../ui/gtk.c:1293
 +msgid Power _Down
 +msgstr _Kapat
 +
 +#: ../ui/gtk.c:1308
 +msgid _View
 +msgstr _Görüntüle
 +
 +#: ../ui/gtk.c:1338
 +msgid Zoom To _Fit
 +msgstr Yakınlaş ve Sığ_dır
 +
 +#: ../ui/gtk.c:1344
 +msgid Grab On _Hover
 +msgstr Ü_zerindeyken Yakala
 +
 +#: ../ui/gtk.c:1347
 +msgid _Grab Input
 +msgstr Girdiyi _Yakala
 +
 +#: ../ui/gtk.c:1373
 +msgid Show _Tabs
 +msgstr Se_kmeleri Göster
 


-- 
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] [RFC][PATCH v3 00/24] instrument: Let the user wrap/override specific event tracing routines

2013-04-24 Thread Stefan Hajnoczi
On Sun, Apr 21, 2013 at 09:11:30PM +0200, Lluís Vilanova wrote:
 TODO: Operations 'instr_load' and 'instr_unload' are not thread safe.
   (qemu_cpu_kick?)
 
 TODO: Do cmdline actions have to be implemented on top of QMP routines?
 
 TODO: HMP and QMP interfaces only accept one argument to instr-load.
 
 TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 
 'InstrLoadCode'?
   (harder to find using code navigation tools, as it's auto-generated; but
   provides a single point to manage the enumeration values, which is less
   error-prone)
 
 
 The whole set of patch series is available at:
   https://projects.gso.ac.upc.edu/projects/qemu-dbi
 
 Adds the instrument event property to declare which tracing events in QEMU
 must be instrumentable. Still, in case the user only wants to wrap around the
 tracing events, the original tracing implementation is accessible through the
 appropriate routines.
 
 The instrumentation can be performed either through a dynamically-loaded 
 library
 or through user-provided code that is compiled into QEMU itself (useful when
 instrumenting high-frequency events, as the fast-path of the instrumentation 
 can
 be inlined into QEMU).
 
 As a side-effect this series adds an API for the instrumentation code to have
 some basic interaction with QEMU.
 
 See the documentation added in the first patch for more information.
 
 Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
 ---

If I understand correctly this series allows trace events to be exported
as a shared library API.  It can be used with instrumentation libraries
(shared objects), which avoids rebuilding QEMU for each instrumentation
set.

I'm skeptical of the effort required to do this (and maintain it) when
it's easy to keep several git branches - one for each instrumentation
set - and rebuild.

Trace events are not an API.  They are not stable.  Therefore these
dynamic instrumentation libraries would be broken when QEMU changes.

Maybe I don't understand the application well enough to see the benefit?

Stefan



Re: [Qemu-devel] [PATCH] ich9: kill cmos_s3

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 12:37, Hu Tao ha scritto:
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com

I had exactly the same patch in my 1.6 queue. :)

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

 ---
  hw/acpi/ich9.c |  2 +-
  hw/i386/pc_q35.c   | 15 +--
  hw/isa/lpc_ich9.c  |  4 ++--
  include/hw/acpi/ich9.h |  2 +-
  include/hw/i386/ich9.h |  2 +-
  5 files changed, 6 insertions(+), 19 deletions(-)
 
 diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
 index e663d29..4a17f32 100644
 --- a/hw/acpi/ich9.c
 +++ b/hw/acpi/ich9.c
 @@ -203,7 +203,7 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
  }
  
  void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 -  qemu_irq sci_irq, qemu_irq cmos_s3)
 +  qemu_irq sci_irq)
  {
  memory_region_init(pm-io, ich9-pm, ICH9_PMIO_SIZE);
  memory_region_set_enabled(pm-io, false);
 diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
 index 6ac1a89..e5f417e 100644
 --- a/hw/i386/pc_q35.c
 +++ b/hw/i386/pc_q35.c
 @@ -45,17 +45,6 @@
  /* ICH9 AHCI has 6 ports */
  #define MAX_SATA_PORTS 6
  
 -/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
 - *BIOS will read it and start S3 resume at POST Entry */
 -static void pc_cmos_set_s3_resume(void *opaque, int irq, int level)
 -{
 -ISADevice *s = opaque;
 -
 -if (level) {
 -rtc_set_memory(s, 0xF, 0xFE);
 -}
 -}
 -
  /* PC hardware initialisation */
  static void pc_q35_init(QEMUMachineInitArgs *args)
  {
 @@ -84,7 +73,6 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
  int i;
  ICH9LPCState *ich9_lpc;
  PCIDevice *ahci;
 -qemu_irq *cmos_s3;
  
  pc_cpus_init(cpu_model);
  pc_acpi_init(q35-acpi-dsdt.aml);
 @@ -175,8 +163,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
  pc_basic_device_init(isa_bus, gsi, rtc_state, floppy, false);
  
  /* connect pm stuff to lpc */
 -cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
 -ich9_lpc_pm_init(lpc, *cmos_s3);
 +ich9_lpc_pm_init(lpc);
  
  /* ahci and SATA device, for q35 1 ahci controller is built-in */
  ahci = pci_create_simple_multifunction(host_bus,
 diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
 index d116075..667e882 100644
 --- a/hw/isa/lpc_ich9.c
 +++ b/hw/isa/lpc_ich9.c
 @@ -356,13 +356,13 @@ static void ich9_set_sci(void *opaque, int irq_num, int 
 level)
  }
  }
  
 -void ich9_lpc_pm_init(PCIDevice *lpc_pci, qemu_irq cmos_s3)
 +void ich9_lpc_pm_init(PCIDevice *lpc_pci)
  {
  ICH9LPCState *lpc = ICH9_LPC_DEVICE(lpc_pci);
  qemu_irq *sci_irq;
  
  sci_irq = qemu_allocate_irqs(ich9_set_sci, lpc, 1);
 -ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0], cmos_s3);
 +ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0]);
  
  ich9_lpc_reset(lpc-d.qdev);
  }
 diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
 index 85b82ee..b1fe71f 100644
 --- a/include/hw/acpi/ich9.h
 +++ b/include/hw/acpi/ich9.h
 @@ -45,7 +45,7 @@ typedef struct ICH9LPCPMRegs {
  } ICH9LPCPMRegs;
  
  void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 -  qemu_irq sci_irq, qemu_irq cmos_s3_resume);
 +  qemu_irq sci_irq);
  void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base);
  extern const VMStateDescription vmstate_ich9_pm;
  
 diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h
 index 51d5981..c5f637b 100644
 --- a/include/hw/i386/ich9.h
 +++ b/include/hw/i386/ich9.h
 @@ -18,7 +18,7 @@
  void ich9_lpc_set_irq(void *opaque, int irq_num, int level);
  int ich9_lpc_map_irq(PCIDevice *pci_dev, int intx);
  PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin);
 -void ich9_lpc_pm_init(PCIDevice *pci_lpc, qemu_irq cmos_s3);
 +void ich9_lpc_pm_init(PCIDevice *pci_lpc);
  PCIBus *ich9_d2pbr_init(PCIBus *bus, int devfn, int sec_bus);
  i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base);
  
 




[Qemu-devel] [PATCH v2] microblaze: Add internal base vectors reg

2013-04-24 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@gmail.com

Configurable at CPU synthesis/instantiation.

Signed-off-by: Edgar E. Iglesias edgar.igles...@gmail.com
---

Peter Crosthwaite commented off-list that it would be a good idea
to make this a device property. I agree but am a bit unsure of
how it should look. Any comments on this attempt?

v2:
Make base_vectors a CPU/device property.


 target-microblaze/cpu-qom.h |1 +
 target-microblaze/cpu.c |8 
 target-microblaze/helper.c  |8 
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/target-microblaze/cpu-qom.h b/target-microblaze/cpu-qom.h
index aa51cf6..ce92a4e 100644
--- a/target-microblaze/cpu-qom.h
+++ b/target-microblaze/cpu-qom.h
@@ -56,6 +56,7 @@ typedef struct MicroBlazeCPUClass {
 typedef struct MicroBlazeCPU {
 /* private */
 CPUState parent_obj;
+uint32_t base_vectors;
 /* public */
 
 CPUMBState env;
diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c
index 0f4293d..404f82c 100644
--- a/target-microblaze/cpu.c
+++ b/target-microblaze/cpu.c
@@ -22,6 +22,7 @@
 
 #include cpu.h
 #include qemu-common.h
+#include hw/qdev-properties.h
 #include migration/vmstate.h
 
 
@@ -119,6 +120,11 @@ static const VMStateDescription vmstate_mb_cpu = {
 .unmigratable = 1,
 };
 
+static Property mb_properties[] = {
+DEFINE_PROP_UINT32(xlnx.base-vectors, MicroBlazeCPU, base_vectors, 0),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static void mb_cpu_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
@@ -133,6 +139,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
 
 cc-do_interrupt = mb_cpu_do_interrupt;
 dc-vmsd = vmstate_mb_cpu;
+
+dc-props = mb_properties;
 }
 
 static const TypeInfo mb_cpu_type_info = {
diff --git a/target-microblaze/helper.c b/target-microblaze/helper.c
index a0416d0..0dd669d 100644
--- a/target-microblaze/helper.c
+++ b/target-microblaze/helper.c
@@ -152,7 +152,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
   env-sregs[SR_ESR], env-iflags);
 log_cpu_state_mask(CPU_LOG_INT, env, 0);
 env-iflags = ~(IMM_FLAG | D_FLAG);
-env-sregs[SR_PC] = 0x20;
+env-sregs[SR_PC] = cpu-base_vectors + 0x20;
 break;
 
 case EXCP_MMU:
@@ -192,7 +192,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
   env-sregs[SR_PC], env-sregs[SR_EAR], env-iflags);
 log_cpu_state_mask(CPU_LOG_INT, env, 0);
 env-iflags = ~(IMM_FLAG | D_FLAG);
-env-sregs[SR_PC] = 0x20;
+env-sregs[SR_PC] = cpu-base_vectors + 0x20;
 break;
 
 case EXCP_IRQ:
@@ -233,7 +233,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
 env-sregs[SR_MSR] |= t;
 
 env-regs[14] = env-sregs[SR_PC];
-env-sregs[SR_PC] = 0x10;
+env-sregs[SR_PC] = cpu-base_vectors + 0x10;
 //log_cpu_state_mask(CPU_LOG_INT, env, 0);
 break;
 
@@ -252,7 +252,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
 if (env-exception_index == EXCP_HW_BREAK) {
 env-regs[16] = env-sregs[SR_PC];
 env-sregs[SR_MSR] |= MSR_BIP;
-env-sregs[SR_PC] = 0x18;
+env-sregs[SR_PC] = cpu-base_vectors + 0x18;
 } else
 env-sregs[SR_PC] = env-btarget;
 break;
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 2/3] vnc: Support for LED state extension

2013-04-24 Thread Gerd Hoffmann
  Hi,

 +case VNC_ENCODING_LED_STATE:
 +vs-features |= VNC_FEATURE_LED_STATE_MASK;
 +break;

I think it with the client supporting the led state extension it is
probably a good idea to turn off the lock state sync logic in qemu's vnc
server, i.e. add a !(vs-features  VNC_FEATURE_LED_STATE_MASK) check
next to the lock_key_sync checks in do_key_event().

cheers,
  Gerd





[Qemu-devel] [PATCH 1/5] pci: Simpler implementation of PCI_COMMAND_MASTER bit

2013-04-24 Thread David Gibson
In commit 1c380f9460522f32c8dd2577b2a53d518ec91c6d pci: honor
PCI_COMMAND_MASTER the PCI_COMMAND_MASTER bit of the PCI command register
was implemented by toggling the enable bit on a memory region alias
interposed between the PCI device's dma address space and the main
system memory region.

Introducing an extra alias region for every PCI device just to implement
that bit seems like serious overkill.  Furthermore, it doesn't work when
there's a (guest side) iommu present, since that uses a different path for
constructing the PCI device's dma address space.

This patch removes the aliased window, instead implementing
PCI_COMMAND_MASTER with tests in the PCI DMA functions.

Signed-off-by: David Gibson da...@gibson.dropbear.id.au
---
 hw/pci/pci.c |   14 +-
 include/hw/pci/pci.h |   19 ++-
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 051da67..2fdd4b2 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -425,10 +425,6 @@ static int get_pci_config_device(QEMUFile *f, void *pv, 
size_t size)
 
 pci_update_mappings(s);
 
-memory_region_set_enabled(s-bus_master_enable_region,
-  pci_get_word(s-config + PCI_COMMAND)
-   PCI_COMMAND_MASTER);
-
 g_free(config);
 return 0;
 }
@@ -850,11 +846,7 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 /* FIXME: Make dma_context_fn use MemoryRegions instead, so this path 
is
  * taken unconditionally */
 /* FIXME: inherit memory region from bus creator */
-memory_region_init_alias(pci_dev-bus_master_enable_region, bus 
master,
- get_system_memory(), 0,
- memory_region_size(get_system_memory()));
-memory_region_set_enabled(pci_dev-bus_master_enable_region, false);
-address_space_init(pci_dev-bus_master_as, 
pci_dev-bus_master_enable_region);
+address_space_init(pci_dev-bus_master_as, get_system_memory());
 pci_dev-dma = g_new(DMAContext, 1);
 dma_context_init(pci_dev-dma, pci_dev-bus_master_as, NULL, NULL, 
NULL);
 }
@@ -913,7 +905,6 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
 
 if (!pci_dev-bus-dma_context_fn) {
 address_space_destroy(pci_dev-bus_master_as);
-memory_region_destroy(pci_dev-bus_master_enable_region);
 g_free(pci_dev-dma);
 pci_dev-dma = NULL;
 }
@@ -1201,9 +1192,6 @@ void pci_default_write_config(PCIDevice *d, uint32_t 
addr, uint32_t val, int l)
 
 if (range_covers_byte(addr, l, PCI_COMMAND)) {
 pci_update_irq_disabled(d, was_irq_disabled);
-memory_region_set_enabled(d-bus_master_enable_region,
-  pci_get_word(d-config + PCI_COMMAND)
- PCI_COMMAND_MASTER);
 }
 
 msi_write_config(d, addr, val, l);
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 7e5986a..8f682cc 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -241,7 +241,6 @@ struct PCIDevice {
 char name[64];
 PCIIORegion io_regions[PCI_NUM_REGIONS];
 AddressSpace bus_master_as;
-MemoryRegion bus_master_enable_region;
 DMAContext *dma;
 
 /* do not access the following fields */
@@ -648,8 +647,12 @@ static inline DMAContext *pci_dma_context(PCIDevice *dev)
 static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
  void *buf, dma_addr_t len, DMADirection dir)
 {
-dma_memory_rw(pci_dma_context(dev), addr, buf, len, dir);
-return 0;
+if (pci_get_word(dev-config + PCI_COMMAND)  PCI_COMMAND_MASTER) {
+dma_memory_rw(pci_dma_context(dev), addr, buf, len, dir);
+return 0;
+} else {
+return -EPERM;
+}
 }
 
 static inline int pci_dma_read(PCIDevice *dev, dma_addr_t addr,
@@ -668,12 +671,18 @@ static inline int pci_dma_write(PCIDevice *dev, 
dma_addr_t addr,
 static inline uint##_bits##_t ld##_l##_pci_dma(PCIDevice *dev,  \
dma_addr_t addr) \
 {   \
-return ld##_l##_dma(pci_dma_context(dev), addr);\
+if (pci_get_word(dev-config + PCI_COMMAND)  PCI_COMMAND_MASTER) { \
+return ld##_l##_dma(pci_dma_context(dev), addr);\
+} else {\
+return -1;  \
+}   \
 }   \
 static inline void st##_s##_pci_dma(PCIDevice *dev, \
 dma_addr_t addr, uint##_bits##_t val) \
 {   

[Qemu-devel] [PATCH 3/5] vfio: Associate VFIO groups with DMAContexts

2013-04-24 Thread David Gibson
The only model so far supported for VFIO passthrough devices is the model
usually used on x86, where all of the guest's RAM is mapped into the
(host) IOMMU and there is no IOMMU visible in the guest.  Later, however
we want to also support guest visible IOMMUs.

In order to do that the vfio subsystem needs to know which address space
its devices are supposed to be in.  In other words the PCI device's
DMAContext needs to be passed through to vfio.  This patch updates the
internal interfaces to do that.  So far it doesn't do much with it, except
to verify/enforce that a group is never added to multiple contexts.

Signed-off-by: David Gibson da...@gibson.dropbear.id.au
---
 hw/misc/vfio.c |   38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 693a9ff..f77a599 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -116,6 +116,7 @@ enum {
 struct VFIOGroup;
 
 typedef struct VFIOContainer {
+DMAContext *dma;
 int fd; /* /dev/vfio/vfio, empowered by the attached groups */
 struct {
 /* enable abstraction to support various iommu backends */
@@ -2612,13 +2613,19 @@ static int vfio_load_rom(VFIODevice *vdev)
 return 0;
 }
 
-static int vfio_connect_container(VFIOGroup *group)
+static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
 {
 VFIOContainer *container;
 int ret, fd;
 
 if (group-container) {
-return 0;
+if (group-container-dma == dma) {
+return 0;
+} else {
+error_report(vfio: group %d used in multiple DMA contexts,
+ group-groupid);
+return -EBUSY;
+}
 }
 
 QLIST_FOREACH(container, container_list, next) {
@@ -2644,6 +2651,7 @@ static int vfio_connect_container(VFIOGroup *group)
 }
 
 container = g_malloc0(sizeof(*container));
+container-dma = dma;
 container-fd = fd;
 
 if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
@@ -2683,12 +2691,12 @@ static int vfio_connect_container(VFIOGroup *group)
 return 0;
 }
 
-static void vfio_disconnect_container(VFIOGroup *group)
+static void vfio_disconnect_context(VFIOGroup *group)
 {
 VFIOContainer *container = group-container;
 
 if (ioctl(group-fd, VFIO_GROUP_UNSET_CONTAINER, container-fd)) {
-error_report(vfio: error disconnecting group %d from container,
+error_report(vfio: error disconnecting group %d from context,
  group-groupid);
 }
 
@@ -2700,13 +2708,13 @@ static void vfio_disconnect_container(VFIOGroup *group)
 container-iommu_data.release(container);
 }
 QLIST_REMOVE(container, next);
-DPRINTF(vfio_disconnect_container: close container-fd\n);
+DPRINTF(vfio_disconnect_context: close container-fd\n);
 close(container-fd);
 g_free(container);
 }
 }
 
-static VFIOGroup *vfio_get_group(int groupid)
+static VFIOGroup *vfio_get_group(int groupid, DMAContext *dma)
 {
 VFIOGroup *group;
 char path[32];
@@ -2714,7 +2722,15 @@ static VFIOGroup *vfio_get_group(int groupid)
 
 QLIST_FOREACH(group, group_list, next) {
 if (group-groupid == groupid) {
-return group;
+/* Found it.  Now is it already in the right context? */
+assert(group-container);
+if (group-container-dma == dma) {
+return group;
+} else {
+error_report(vfio: group %d used in multiple DMA contexts,
+ group-groupid);
+return NULL;
+}
 }
 }
 
@@ -2747,8 +2763,8 @@ static VFIOGroup *vfio_get_group(int groupid)
 group-groupid = groupid;
 QLIST_INIT(group-device_list);
 
-if (vfio_connect_container(group)) {
-error_report(vfio: failed to setup container for group %d, groupid);
+if (vfio_connect_context(group, dma)) {
+error_report(vfio: failed to setup context for group %d, groupid);
 close(group-fd);
 g_free(group);
 return NULL;
@@ -2765,7 +2781,7 @@ static void vfio_put_group(VFIOGroup *group)
 return;
 }
 
-vfio_disconnect_container(group);
+vfio_disconnect_context(group);
 QLIST_REMOVE(group, next);
 DPRINTF(vfio_put_group: close group-fd\n);
 close(group-fd);
@@ -2980,7 +2996,7 @@ static int vfio_initfn(PCIDevice *pdev)
 DPRINTF(%s(%04x:%02x:%02x.%x) group %d\n, __func__, vdev-host.domain,
 vdev-host.bus, vdev-host.slot, vdev-host.function, groupid);
 
-group = vfio_get_group(groupid);
+group = vfio_get_group(groupid, pdev-dma);
 if (!group) {
 error_report(vfio: failed to get group %d, groupid);
 return -ENOENT;
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 02/21] cpu: call cpu_synchronize_post_init() from CPUClass.realize() if hotplugged

2013-04-24 Thread Andreas Färber
Am 23.04.2013 17:59, schrieb Andreas Färber:
 Am 23.04.2013 10:29, schrieb Igor Mammedov:
 ... to synchronize CPU state to KVM

 Signed-off-by: Igor Mammedov imamm...@redhat.com
 Reviewed-by: Eduardo Habkost ehabk...@redhat.com
 ---
 v2:
   * linking kvm-stub.o to *-user target moved in separate patch
 
 Thanks, applied to qom-cpu:
 https://github.com/afaerber/qemu-cpu/commits/qom-cpu

To facilitate conflict resolution for future patches, I have modified
this to match other functions in there and to spare refactorings:

diff --git a/qom/cpu.c b/qom/cpu.c
index 0c76712..66f7c00 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -58,8 +58,10 @@ static ObjectClass *cpu_common_class_by_name(const
char *cpu_model)

 static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
+CPUState *cpu = CPU(dev);
+
 if (dev-hotplugged) {
-cpu_synchronize_post_init(CPU(dev));
+cpu_synchronize_post_init(cpu);
 }
 }


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 4/5] vfio: Move container list to DMAContext

2013-04-24 Thread David Gibson
At the moment, vfio maintains a global list of containers that are assumed
to be more or less interchangeable, since they are all set up with a
MemoryListener to have all of system memory mapped.  However, that only
makes sense if all the containers are used on devices which really do
expect a dma address space identical to system memory.

This patch moves towards that by making the list of containers per
DMAContext (which corresponds to a dma address space) instead of global.

Signed-off-by: David Gibson da...@gibson.dropbear.id.au
---
 dma-helpers.c  |2 ++
 hw/misc/vfio.c |   13 -
 include/hw/misc/vfio.h |   28 
 include/sysemu/dma.h   |2 ++
 stubs/Makefile.objs|1 +
 stubs/vfio.c   |6 ++
 6 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 include/hw/misc/vfio.h
 create mode 100644 stubs/vfio.c

diff --git a/dma-helpers.c b/dma-helpers.c
index 272632f..f0c7866 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -11,6 +11,7 @@
 #include trace.h
 #include qemu/range.h
 #include qemu/thread.h
+#include hw/misc/vfio.h
 
 /* #define DEBUG_IOMMU */
 
@@ -386,6 +387,7 @@ void dma_context_init(DMAContext *dma, AddressSpace *as, 
DMATranslateFunc transl
 dma-translate = translate;
 dma-map = map;
 dma-unmap = unmap;
+dma_context_init_vfio(dma);
 }
 
 void *iommu_dma_memory_map(DMAContext *dma, dma_addr_t addr, dma_addr_t *len,
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index f77a599..ab870a8 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -39,6 +39,7 @@
 #include qemu/range.h
 #include sysemu/kvm.h
 #include sysemu/sysemu.h
+#include hw/misc/vfio.h
 
 /* #define DEBUG_VFIO */
 #ifdef DEBUG_VFIO
@@ -179,9 +180,6 @@ typedef struct VFIOGroup {
 
 #define MSIX_CAP_LENGTH 12
 
-static QLIST_HEAD(, VFIOContainer)
-container_list = QLIST_HEAD_INITIALIZER(container_list);
-
 static QLIST_HEAD(, VFIOGroup)
 group_list = QLIST_HEAD_INITIALIZER(group_list);
 
@@ -2613,6 +2611,11 @@ static int vfio_load_rom(VFIODevice *vdev)
 return 0;
 }
 
+void dma_context_init_vfio(DMAContext *dma)
+{
+QLIST_INIT(dma-vfio.containers);
+}
+
 static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
 {
 VFIOContainer *container;
@@ -2628,7 +2631,7 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 }
 }
 
-QLIST_FOREACH(container, container_list, next) {
+QLIST_FOREACH(container, dma-vfio.containers, next) {
 if (!ioctl(group-fd, VFIO_GROUP_SET_CONTAINER, container-fd)) {
 group-container = container;
 QLIST_INSERT_HEAD(container-group_list, group, container_next);
@@ -2683,7 +2686,7 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 }
 
 QLIST_INIT(container-group_list);
-QLIST_INSERT_HEAD(container_list, container, next);
+QLIST_INSERT_HEAD(dma-vfio.containers, container, next);
 
 group-container = container;
 QLIST_INSERT_HEAD(container-group_list, group, container_next);
diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
new file mode 100644
index 000..18fe144
--- /dev/null
+++ b/include/hw/misc/vfio.h
@@ -0,0 +1,28 @@
+/*
+ * vfio based device assignment
+ *
+ * Copyright 2013 David Gibson, IBM Corporation.
+ * Copyright Red Hat, Inc. 2012
+ *
+ * This work is licensed under the terms of the GNU GPL, version
+ * 2. See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_VFIO_H
+#define QEMU_VFIO_H
+
+#include qemu/queue.h
+
+typedef struct DMAContext DMAContext;
+struct DMAContext;
+
+typedef struct VFIOContainer VFIOContainer;
+struct VFIOContainer;
+
+typedef struct DMAContextVFIO DMAContextVFIO;
+struct DMAContextVFIO {
+QLIST_HEAD(, VFIOContainer) containers;
+};
+
+void dma_context_init_vfio(DMAContext *dma);
+
+#endif /* QEMU_VFIO_H */
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index a52c93a..8692d0a 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -15,6 +15,7 @@
 #include hw/hw.h
 #include block/block.h
 #include sysemu/kvm.h
+#include hw/misc/vfio.h
 
 typedef struct DMAContext DMAContext;
 typedef struct ScatterGatherEntry ScatterGatherEntry;
@@ -66,6 +67,7 @@ struct DMAContext {
 DMATranslateFunc *translate;
 DMAMapFunc *map;
 DMAUnmapFunc *unmap;
+DMAContextVFIO vfio;
 };
 
 /* A global DMA context corresponding to the address_space_memory
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 9c55b34..858ca6b 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -20,6 +20,7 @@ stub-obj-y += reset.o
 stub-obj-y += set-fd-handler.o
 stub-obj-y += slirp.o
 stub-obj-y += sysbus.o
+stub-obj-y += vfio.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
diff --git a/stubs/vfio.c b/stubs/vfio.c
new file mode 100644
index 000..6fe4a84
--- /dev/null
+++ b/stubs/vfio.c
@@ -0,0 +1,6 @@
+#include hw/misc/vfio.h
+#include sysemu/dma.h

[Qemu-devel] [0/5] RFC: Preparations for supporting VFIO with guest IOMMUs

2013-04-24 Thread David Gibson
This patch series represents my attempt at better integration of the
vfio code with qemu's DMAContext and other guest IOMMU handling code,
as discussed by Alex Williamson and myself on IRC.  It opens the way
for using VFIO with a guest system containing an IOMMU by passing
guest IOMMU operations through to the host IOMMU via VFIO.  That's
opposed to the present model of having no IOMMU in the guest, and
simply mapping all guest RAM into the host IOMMU.

I hit some complications with some changes in the guest iommu
infrastructure since it went in.  Patches 1  2 clean that up, patches
3-5 do the necessary VFIO infrastructure changes.



[Qemu-devel] [PATCH 2/5] pci: Don't create an address space object for every PCI device

2013-04-24 Thread David Gibson
Commit 817dcc5368988b023c5e1d3f1444fd370c77c6a9 pci: give each device its
own address space did exactly what the comment suggests, it creates an
AddressSpace object for every PCI device to represent the address space
it uses for DMA.  All the objects so constructed are basically identical
to address_space_memory.

While its true that PCI devices can have different effective DMA address
spaces, they usually don't.  Further, the PCI structure already had a way
to represent its DMA address space, through its DMAContext pointer.  The
way those are assigned through an optional callback in the bus also
addresses the FIXME: inherit memory region from bus creator.

So while its true that the DMAContext handling needs to be better
integrated with the MemoryRegion and AddressSpace handling, that commit
wasn't actually a step in the right direction for it.  Since then, the
DMAContext has been extended so it can backend onto an AddressSpace, and
thereby, a MemoryRegion.  Effectively a DMAContext is now an AddressSpace
with iommu translation handling on top.

Therefore, this patch essentially reverts the earlier commit, making all
PCI devices by default shared the global dma_context_memory which backs
onto main system memory.  Those cases which need to set up different DMA
address spaces for each PCI device should supply a suitable dma_context_fn
in the bus to correctly assign / create suitable DMAContext structures.

Signed-off-by: David Gibson da...@gibson.dropbear.id.au
---
 hw/pci/pci.c |   14 ++
 include/hw/pci/pci.h |1 -
 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2fdd4b2..038be92 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -843,12 +843,7 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 if (bus-dma_context_fn) {
 pci_dev-dma = bus-dma_context_fn(bus, bus-dma_context_opaque, 
devfn);
 } else {
-/* FIXME: Make dma_context_fn use MemoryRegions instead, so this path 
is
- * taken unconditionally */
-/* FIXME: inherit memory region from bus creator */
-address_space_init(pci_dev-bus_master_as, get_system_memory());
-pci_dev-dma = g_new(DMAContext, 1);
-dma_context_init(pci_dev-dma, pci_dev-bus_master_as, NULL, NULL, 
NULL);
+pci_dev-dma = dma_context_memory;
 }
 pci_dev-devfn = devfn;
 pstrcpy(pci_dev-name, sizeof(pci_dev-name), name);
@@ -902,12 +897,7 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
 qemu_free_irqs(pci_dev-irq);
 pci_dev-bus-devices[pci_dev-devfn] = NULL;
 pci_config_free(pci_dev);
-
-if (!pci_dev-bus-dma_context_fn) {
-address_space_destroy(pci_dev-bus_master_as);
-g_free(pci_dev-dma);
-pci_dev-dma = NULL;
-}
+pci_dev-dma = NULL;
 }
 
 static void pci_unregister_io_regions(PCIDevice *pci_dev)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 8f682cc..206da1f 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -240,7 +240,6 @@ struct PCIDevice {
 int32_t devfn;
 char name[64];
 PCIIORegion io_regions[PCI_NUM_REGIONS];
-AddressSpace bus_master_as;
 DMAContext *dma;
 
 /* do not access the following fields */
-- 
1.7.10.4




[Qemu-devel] [PATCH 5/5] vfio: Only use memory listeners when appropriate

2013-04-24 Thread David Gibson
Currently, vfio registers a MemoryListener for every vfio container we
create, to keep the container's mappings in sync with main system memory.
That's only correct though, if the context the container is attached to
represents a dma address space which actually matches main system memory -
roughly speaking that means that there is no guest side IOMMU above the
vfio device in question.

This patch corrects the code, by only registering the MemoryListener when
the container belongs to a DMAContext which does not include an IOMMU (i.e.
which has no -translate function).  In other cases we given an error; that
will change when vfio support for guest side IOMMUs is added.

In addition, this generalizes the code slightly, by attaching the
MemoryListener to the DMAContext's underlying AddressSpace, rather than
just assuming that it is main system memory.

Signed-off-by: David Gibson da...@gibson.dropbear.id.au
---
 hw/misc/vfio.c |   79 +---
 1 file changed, 46 insertions(+), 33 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index ab870a8..dce6189 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -2616,28 +2616,11 @@ void dma_context_init_vfio(DMAContext *dma)
 QLIST_INIT(dma-vfio.containers);
 }
 
-static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
+static int vfio_connect_container_address_space(VFIOGroup *group,
+DMAContext *dma)
 {
 VFIOContainer *container;
-int ret, fd;
-
-if (group-container) {
-if (group-container-dma == dma) {
-return 0;
-} else {
-error_report(vfio: group %d used in multiple DMA contexts,
- group-groupid);
-return -EBUSY;
-}
-}
-
-QLIST_FOREACH(container, dma-vfio.containers, next) {
-if (!ioctl(group-fd, VFIO_GROUP_SET_CONTAINER, container-fd)) {
-group-container = container;
-QLIST_INSERT_HEAD(container-group_list, group, container_next);
-return 0;
-}
-}
+int fd, ret;
 
 fd = qemu_open(/dev/vfio/vfio, O_RDWR);
 if (fd  0) {
@@ -2657,15 +2640,15 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 container-dma = dma;
 container-fd = fd;
 
-if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
-ret = ioctl(group-fd, VFIO_GROUP_SET_CONTAINER, fd);
-if (ret) {
-error_report(vfio: failed to set group container: %m);
-g_free(container);
-close(fd);
-return -errno;
-}
+ret = ioctl(group-fd, VFIO_GROUP_SET_CONTAINER, fd);
+if (ret) {
+error_report(vfio: failed to set group container: %m);
+g_free(container);
+close(fd);
+return -errno;
+}
 
+if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
 ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU);
 if (ret) {
 error_report(vfio: failed to set iommu for container: %m);
@@ -2673,11 +2656,6 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 close(fd);
 return -errno;
 }
-
-container-iommu_data.listener = vfio_memory_listener;
-container-iommu_data.release = vfio_listener_release;
-
-memory_listener_register(container-iommu_data.listener, 
address_space_memory);
 } else {
 error_report(vfio: No available IOMMU models);
 g_free(container);
@@ -2685,6 +2663,11 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 return -EINVAL;
 }
 
+container-iommu_data.listener = vfio_memory_listener;
+container-iommu_data.release = vfio_listener_release;
+
+memory_listener_register(container-iommu_data.listener, dma-as);
+
 QLIST_INIT(container-group_list);
 QLIST_INSERT_HEAD(dma-vfio.containers, container, next);
 
@@ -2694,6 +2677,36 @@ static int vfio_connect_context(VFIOGroup *group, 
DMAContext *dma)
 return 0;
 }
 
+static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
+{
+VFIOContainer *container;
+
+if (group-container) {
+if (group-container-dma == dma) {
+return 0;
+} else {
+error_report(vfio: group %d used in multiple DMA contexts,
+ group-groupid);
+return -EBUSY;
+}
+}
+
+QLIST_FOREACH(container, dma-vfio.containers, next) {
+if (!ioctl(group-fd, VFIO_GROUP_SET_CONTAINER, container-fd)) {
+group-container = container;
+QLIST_INSERT_HEAD(container-group_list, group, container_next);
+return 0;
+}
+}
+
+if (!dma-translate) {
+return vfio_connect_container_address_space(group, dma);
+}
+
+error_report(vfio: no support for guest side IOMMU);
+return -ENODEV;
+}
+
 static void vfio_disconnect_context(VFIOGroup *group)
 {
 

Re: [Qemu-devel] [RFC][PATCH v3 00/24] instrument: Let the user wrap/override specific event tracing routines

2013-04-24 Thread Lluís Vilanova
Stefan Hajnoczi writes:

 On Sun, Apr 21, 2013 at 09:11:30PM +0200, Lluís Vilanova wrote:
 TODO: Operations 'instr_load' and 'instr_unload' are not thread safe.
 (qemu_cpu_kick?)
 
 TODO: Do cmdline actions have to be implemented on top of QMP routines?
 
 TODO: HMP and QMP interfaces only accept one argument to instr-load.
 
 TODO: Replace programmatic 'InstrLoadError' in favour of QAPI's 
 'InstrLoadCode'?
 (harder to find using code navigation tools, as it's auto-generated; but
 provides a single point to manage the enumeration values, which is less
 error-prone)
 
 
 The whole set of patch series is available at:
 https://projects.gso.ac.upc.edu/projects/qemu-dbi
 
 Adds the instrument event property to declare which tracing events in QEMU
 must be instrumentable. Still, in case the user only wants to wrap around the
 tracing events, the original tracing implementation is accessible through the
 appropriate routines.
 
 The instrumentation can be performed either through a dynamically-loaded 
 library
 or through user-provided code that is compiled into QEMU itself (useful when
 instrumenting high-frequency events, as the fast-path of the instrumentation 
 can
 be inlined into QEMU).
 
 As a side-effect this series adds an API for the instrumentation code to have
 some basic interaction with QEMU.
 
 See the documentation added in the first patch for more information.
 
 Signed-off-by: Lluís Vilanova vilan...@ac.upc.edu
 ---

 If I understand correctly this series allows trace events to be exported
 as a shared library API.  It can be used with instrumentation libraries
 (shared objects), which avoids rebuilding QEMU for each instrumentation
 set.

 I'm skeptical of the effort required to do this (and maintain it) when
 it's easy to keep several git branches - one for each instrumentation
 set - and rebuild.

 Trace events are not an API.  They are not stable.  Therefore these
 dynamic instrumentation libraries would be broken when QEMU changes.

 Maybe I don't understand the application well enough to see the benefit?

True, changing QEMU's tracing events will break the instrumentation libraries,
and the user should be completely aware of that, given that the library is
actually instrumenting specific tracing events (not just some well-established
API). You can think of this as yet another tracing backend, with the ability to
interact with QEMU.

The actually interesting part is in the following series (which are also
publicly available on the url of the cover), which adds some generic tracing
events that should not change between versions, and can thus be safely assumed.
Such events are related to the guest code, including (but not limited to) guest
memory accesses or instruction execution. As we discussed in some very old try
at this, what all of this provides is the ability to instrument guest code for
all architectures supported by QEMU.

In fact, the ability to instrument all tracing events could be seen as just a
side-effect of the implementation; but one that can come in handy in certain
cases when developing ad-hoc trace analyses.

Does this make more sense now?


Lluis



Re: [Qemu-devel] [PATCH v2 2/5] block: vhdx header for the QEMU support of VHDX images

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 10:24:21AM -0400, Jeff Cody wrote:
 +/*  HEADER SECTION STRUCTURES  */
 +
 +/* Important note: these structures are as defined in the VHDX specification,
 + * including byte order and size.  However, without being packed structures,
 + * they will not match 1:1 data read from disk.  Rather than use potentially
 + * non-portable packed structures, data is copied from read buffers into
 + * the structures below.  However, for reference, please refrain from
 + * modifying these structures to something that does not represent the spec 
 */

Outdated comment?  The patch uses QEMU_PACKED.

 +/* Header for the region table block */
 +#define VHDX_RT_MAGIC 0x69676572  /* 'regi ' */

Not worth respinnning, but should be 'regi' (4 bytes).



Re: [Qemu-devel] [PATCH v2 2/5] block: vhdx header for the QEMU support of VHDX images

2013-04-24 Thread Jeff Cody
On Wed, Apr 24, 2013 at 02:31:27PM +0200, Stefan Hajnoczi wrote:
 On Tue, Apr 23, 2013 at 10:24:21AM -0400, Jeff Cody wrote:
  +/*  HEADER SECTION STRUCTURES  */
  +
  +/* Important note: these structures are as defined in the VHDX 
  specification,
  + * including byte order and size.  However, without being packed 
  structures,
  + * they will not match 1:1 data read from disk.  Rather than use 
  potentially
  + * non-portable packed structures, data is copied from read buffers into
  + * the structures below.  However, for reference, please refrain from
  + * modifying these structures to something that does not represent the 
  spec */
 
 Outdated comment?  The patch uses QEMU_PACKED.
 

Yes, outdated comment, thanks.

  +/* Header for the region table block */
  +#define VHDX_RT_MAGIC 0x69676572  /* 'regi ' */
 
 Not worth respinnning, but should be 'regi' (4 bytes).

Per Kevin's comments, I am removing all the _MAGIC's from the
headers anyway, and using memcmp against the strings in the source
file.  So I'll take care of the outdated comment as well then.



Re: [Qemu-devel] [PATCH 2/5] pci: Don't create an address space object for every PCI device

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 14:01, David Gibson ha scritto:
 So while its true that the DMAContext handling needs to be better
 integrated with the MemoryRegion and AddressSpace handling, that commit
 wasn't actually a step in the right direction for it.  Since then, the
 DMAContext has been extended so it can backend onto an AddressSpace, and
 thereby, a MemoryRegion.  Effectively a DMAContext is now an AddressSpace
 with iommu translation handling on top.
 
 Therefore, this patch essentially reverts the earlier commit, making all
 PCI devices by default shared the global dma_context_memory which backs
 onto main system memory.  Those cases which need to set up different DMA
 address spaces for each PCI device should supply a suitable dma_context_fn
 in the bus to correctly assign / create suitable DMAContext structures.

I think this will be handled correctly when I submit IOMMU AddressSpace
patches (next week or so).  The structure will be

PCI device 1   PCI device 2
---
   AddressSpace 1  AddressSpace 2
   |   |
   | (enable/disable)  | (enable/disable)
   '---.  .'
   v  v
 IOMMU AddressSpace
|
| (translation)
v
   system memory

VFIO will be able to access the IOMMU AddressSpace simply via
pci_dev-iommu, and that field will be ==-identical  for different PCI
devices.

Paolo




Re: [Qemu-devel] [PATCH] ui/gtk: Add Turkish translations

2013-04-24 Thread Anthony Liguori
Andreas Färber afaer...@suse.de writes:

 Anthony,

 Am 23.04.2013 12:04, schrieb Ozan Çağlayan:
 Signed-off-by: Ozan Çağlayan ozan...@gmail.com
 ---
  po/tr.po | 62 ++
  1 file changed, 62 insertions(+)
  create mode 100644 po/tr.po
 
 diff --git a/po/tr.po b/po/tr.po
 new file mode 100644
 index 000..4faefbd
 --- /dev/null
 +++ b/po/tr.po
 @@ -0,0 +1,62 @@
 +# Turkish translation for QEMU.
 +# This file is put in the public domain.

 I see this got committed - didn't you say a while ago to malc that in
 the public domain was not a legally valid license?

Yup, this is my fault.  xgettext generates this by default in
messages.po.  Translators copy that and get the boiler plate
silliness.  I should have noticed when I first added it.

I'll send a series this afternoon and ask for all contributors to Ack.
Thanks for spotting this.

Regards,

Anthony Liguori


 Andreas

 +# Ozan Çağlayan ozan...@gmail.com, 2013.
 +#
 +msgid 
 +msgstr 
 +Project-Id-Version: QEMU 1.4.50\n
 +Report-Msgid-Bugs-To: qemu-devel@nongnu.org\n
 +POT-Creation-Date: 2013-04-22 18:33+0300\n
 +PO-Revision-Date: 2013-04-22 18:35+0300\n
 +Last-Translator: Ozan Çağlayan ozan...@gmail.com\n
 +Language-Team: Türkçe \n
 +Language: \n
 +MIME-Version: 1.0\n
 +Content-Type: text/plain; charset=UTF-8\n
 +Content-Transfer-Encoding: 8bit\n
 +Plural-Forms: nplurals=1; plural=0;\n
 +X-Generator: Gtranslator 2.91.6\n
 +
 +#: ../ui/gtk.c:214
 +msgid  - Press Ctrl+Alt+G to release grab
 +msgstr  - Yakalamayı durdurmak için Ctrl+Alt+G tuşlarına basın
 +
 +#: ../ui/gtk.c:218
 +msgid  [Paused]
 +msgstr  [Duraklatıldı]
 +
 +#: ../ui/gtk.c:1282
 +msgid _Machine
 +msgstr _Makine
 +
 +#: ../ui/gtk.c:1284
 +msgid _Pause
 +msgstr _Duraklat
 +
 +#: ../ui/gtk.c:1290
 +msgid _Reset
 +msgstr _Sıfırla
 +
 +#: ../ui/gtk.c:1293
 +msgid Power _Down
 +msgstr _Kapat
 +
 +#: ../ui/gtk.c:1308
 +msgid _View
 +msgstr _Görüntüle
 +
 +#: ../ui/gtk.c:1338
 +msgid Zoom To _Fit
 +msgstr Yakınlaş ve Sığ_dır
 +
 +#: ../ui/gtk.c:1344
 +msgid Grab On _Hover
 +msgstr Ü_zerindeyken Yakala
 +
 +#: ../ui/gtk.c:1347
 +msgid _Grab Input
 +msgstr Girdiyi _Yakala
 +
 +#: ../ui/gtk.c:1373
 +msgid Show _Tabs
 +msgstr Se_kmeleri Göster
 


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




Re: [Qemu-devel] [PATCH 1/5] pci: Simpler implementation of PCI_COMMAND_MASTER bit

2013-04-24 Thread Paolo Bonzini
Il 24/04/2013 14:01, David Gibson ha scritto:
 In commit 1c380f9460522f32c8dd2577b2a53d518ec91c6d pci: honor
 PCI_COMMAND_MASTER the PCI_COMMAND_MASTER bit of the PCI command register
 was implemented by toggling the enable bit on a memory region alias
 interposed between the PCI device's dma address space and the main
 system memory region.
 
 Introducing an extra alias region for every PCI device just to implement
 that bit seems like serious overkill.  Furthermore, it doesn't work when
 there's a (guest side) iommu present, since that uses a different path for
 constructing the PCI device's dma address space.
 
 This patch removes the aliased window, instead implementing
 PCI_COMMAND_MASTER with tests in the PCI DMA functions.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au

This doesn't work.

You have no guarantee that PCI devices use the PCI DMA functions.  The
device could just pass the DMAContext to another function, and indeed
the OHCI controller does exactly that.

This will be even simpler after IOMMU/DMAContext are also unified in the
AddressSpace framework.

Paolo



[Qemu-devel] [PATCH v3 1/6] vmdk: named return code.

2013-04-24 Thread Fam Zheng
Internal routines in vmdk.c previously return -1 on error and 0 on
success. More return values are useful for future changes such as
zeroed-grain GTE. Change all the magic `return 0` and `return -1` to
macro names:

 * VMDK_OK  0
 * VMDK_ERROR   (-1)
 * VMDK_UNALLOC (-2)
 * VMDK_ZEROED  (-3)

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 60 ++--
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 7bad757..16aa29c 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -37,6 +37,14 @@
 #define VMDK4_FLAG_MARKER (1  17)
 #define VMDK4_GD_AT_END 0xULL
 
+
+/* VMDK internal error codes */
+#define VMDK_OK  0
+#define VMDK_ERROR   (-1)
+/* Cluster not allocated */
+#define VMDK_UNALLOC (-2)
+#define VMDK_ZEROED  (-3)
+
 typedef struct {
 uint32_t version;
 uint32_t flags;
@@ -578,22 +586,22 @@ static int vmdk_parse_description(const char *desc, const 
char *opt_name,
 
 opt_pos = strstr(desc, opt_name);
 if (!opt_pos) {
-return -1;
+return VMDK_ERROR;
 }
 /* Skip =\ following opt_name */
 opt_pos += strlen(opt_name) + 2;
 if (opt_pos = end) {
-return -1;
+return VMDK_ERROR;
 }
 opt_end = opt_pos;
 while (opt_end  end  *opt_end != '') {
 opt_end++;
 }
 if (opt_end == end || buf_size  opt_end - opt_pos + 1) {
-return -1;
+return VMDK_ERROR;
 }
 pstrcpy(buf, opt_end - opt_pos + 1, opt_pos);
-return 0;
+return VMDK_OK;
 }
 
 /* Open an extent file and append to bs array */
@@ -772,7 +780,7 @@ static int get_whole_cluster(BlockDriverState *bs,
 int ret;
 
 if (!vmdk_is_cid_valid(bs)) {
-return -1;
+return VMDK_ERROR;
 }
 
 /* floor offset to cluster */
@@ -780,17 +788,17 @@ static int get_whole_cluster(BlockDriverState *bs,
 ret = bdrv_read(bs-backing_hd, offset  9, whole_grain,
 extent-cluster_sectors);
 if (ret  0) {
-return -1;
+return VMDK_ERROR;
 }
 
 /* Write grain only into the active image */
 ret = bdrv_write(extent-file, cluster_offset, whole_grain,
 extent-cluster_sectors);
 if (ret  0) {
-return -1;
+return VMDK_ERROR;
 }
 }
-return 0;
+return VMDK_OK;
 }
 
 static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data)
@@ -803,7 +811,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData 
*m_data)
 (m_data-offset),
 sizeof(m_data-offset)
 )  0) {
-return -1;
+return VMDK_ERROR;
 }
 /* update backup L2 table */
 if (extent-l1_backup_table_offset != 0) {
@@ -814,11 +822,11 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData 
*m_data)
 + (m_data-l2_index * sizeof(m_data-offset)),
 (m_data-offset), sizeof(m_data-offset)
 )  0) {
-return -1;
+return VMDK_ERROR;
 }
 }
 
-return 0;
+return VMDK_OK;
 }
 
 static int get_cluster_offset(BlockDriverState *bs,
@@ -837,17 +845,17 @@ static int get_cluster_offset(BlockDriverState *bs,
 }
 if (extent-flat) {
 *cluster_offset = extent-flat_start_offset;
-return 0;
+return VMDK_OK;
 }
 
 offset -= (extent-end_sector - extent-sectors) * SECTOR_SIZE;
 l1_index = (offset  9) / extent-l1_entry_sectors;
 if (l1_index = extent-l1_size) {
-return -1;
+return VMDK_ERROR;
 }
 l2_offset = extent-l1_table[l1_index];
 if (!l2_offset) {
-return -1;
+return VMDK_UNALLOC;
 }
 for (i = 0; i  L2_CACHE_SIZE; i++) {
 if (l2_offset == extent-l2_cache_offsets[i]) {
@@ -877,7 +885,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 l2_table,
 extent-l2_size * sizeof(uint32_t)
 ) != extent-l2_size * sizeof(uint32_t)) {
-return -1;
+return VMDK_ERROR;
 }
 
 extent-l2_cache_offsets[min_index] = l2_offset;
@@ -888,7 +896,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 
 if (!*cluster_offset) {
 if (!allocate) {
-return -1;
+return VMDK_UNALLOC;
 }
 
 /* Avoid the L2 tables update for the images that have snapshots. */
@@ -911,7 +919,7 @@ static int get_cluster_offset(BlockDriverState *bs,
  */
 if (get_whole_cluster(
 bs, extent, *cluster_offset, offset, allocate) == -1) {
-return -1;
+return VMDK_ERROR;
 }
 
 if (m_data) {
@@ -923,7 +931,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 }
 }
 *cluster_offset = 9;
-return 0;
+return VMDK_OK;
 }
 
 static VmdkExtent *find_extent(BDRVVmdkState *s,
@@ -1173,7 

[Qemu-devel] [PATCH v3 0/6] vmdk: zeroed-grain GTE support

2013-04-24 Thread Fam Zheng
Added support for zeroed-grain GTE to VMDK according to VMDK Spec 5.0[1].

[1] Virtual Disk Format 5.0 - VMware,
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?src=vmdk

Changes since v2:
 - all: Added 5/6 (vmdk: store fields of VmdkMetaData in cpu endian)
 - 6/6: Avoid side-effect of vmdk_L2update.
Change function comment to gtkdoc stype.
Fix VMDK4_FLAG_ZG.

Changes since v1:
 - all: fix From: field
 - 1/5: squash one line of ret code macro change from 2/5
 - 2/5: change VMDK4_FLAG_ZG to VMDK4_FLAG_ZERO_GRAIN
 - 3/5: move BLOCK_OPT_ZEROED_GRAIN defination from block_int.h to vmdk.c
 - 5/5: fix metadata update issue, unit test with cases 033 034

Fam Zheng (6):
  vmdk: named return code.
  vmdk: add support for “zeroed‐grain” GTE
  vmdk: Add option to create zeroed-grain image
  vmdk: change magic number to macro
  vmdk: store fields of VmdkMetaData in cpu endian
  vmdk: add bdrv_co_write_zeroes

 block/vmdk.c | 194 ++-
 1 file changed, 138 insertions(+), 56 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v3 6/6] vmdk: add bdrv_co_write_zeroes

2013-04-24 Thread Fam Zheng
Use special offset to write zeroes efficiently, when zeroed-grain GTE is
available. If zero-write an allocated cluster, cluster is leaked because
its offset pointer is overwritten by 0x1.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 77 +---
 1 file changed, 63 insertions(+), 14 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 16e1417..90cb071 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -905,6 +905,13 @@ static int get_cluster_offset(BlockDriverState *bs,
 l2_index = ((offset  9) / extent-cluster_sectors) % extent-l2_size;
 *cluster_offset = le32_to_cpu(l2_table[l2_index]);
 
+if (m_data) {
+m_data-valid = 1;
+m_data-l1_index = l1_index;
+m_data-l2_index = l2_index;
+m_data-offset = *cluster_offset;
+m_data-l2_offset = extent-l1_table[m_data-l1_index];
+}
 if (extent-has_zero_grain  *cluster_offset == VMDK_GTE_ZEROED) {
 zeroed = true;
 }
@@ -1165,8 +1172,17 @@ static coroutine_fn int vmdk_co_read(BlockDriverState 
*bs, int64_t sector_num,
 return ret;
 }
 
+/**
+ * vmdk_write:
+ * @zeroed:   buf is ignored (data is zero), use zeroed_grain GTE feature
+ * if possible, otherwise return -ENOTSUP.
+ * @zero_dry_run: used for zeroed == true only, don't update L2 table, just
+ *
+ * Returns: error code with 0 for success.
+ */
 static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
- const uint8_t *buf, int nb_sectors)
+  const uint8_t *buf, int nb_sectors,
+  bool zeroed, bool zero_dry_run)
 {
 BDRVVmdkState *s = bs-opaque;
 VmdkExtent *extent = NULL;
@@ -1212,7 +1228,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t 
sector_num,
 cluster_offset);
 }
 }
-if (ret) {
+if (ret == VMDK_ERROR) {
 return -EINVAL;
 }
 extent_begin_sector = extent-end_sector - extent-sectors;
@@ -1222,17 +1238,34 @@ static int vmdk_write(BlockDriverState *bs, int64_t 
sector_num,
 if (n  nb_sectors) {
 n = nb_sectors;
 }
-
-ret = vmdk_write_extent(extent,
-cluster_offset, index_in_cluster * 512,
-buf, n, sector_num);
-if (ret) {
-return ret;
-}
-if (m_data.valid) {
-/* update L2 tables */
-if (vmdk_L2update(extent, m_data) == -1) {
-return -EIO;
+if (zeroed) {
+/* Do zeroed write, buf is ignored */
+if (extent-has_zero_grain 
+index_in_cluster == 0 
+n = extent-cluster_sectors) {
+n = extent-cluster_sectors;
+if (!zero_dry_run) {
+m_data.offset = cpu_to_le32(VMDK_GTE_ZEROED);
+/* update L2 tables */
+if (vmdk_L2update(extent, m_data) != VMDK_OK) {
+return -EIO;
+}
+}
+} else {
+return -ENOTSUP;
+}
+} else {
+ret = vmdk_write_extent(extent,
+cluster_offset, index_in_cluster * 512,
+buf, n, sector_num);
+if (ret) {
+return ret;
+}
+if (m_data.valid) {
+/* update L2 tables */
+if (vmdk_L2update(extent, m_data) != VMDK_OK) {
+return -EIO;
+}
 }
 }
 nb_sectors -= n;
@@ -1258,7 +1291,22 @@ static coroutine_fn int vmdk_co_write(BlockDriverState 
*bs, int64_t sector_num,
 int ret;
 BDRVVmdkState *s = bs-opaque;
 qemu_co_mutex_lock(s-lock);
-ret = vmdk_write(bs, sector_num, buf, nb_sectors);
+ret = vmdk_write(bs, sector_num, buf, nb_sectors, false, false);
+qemu_co_mutex_unlock(s-lock);
+return ret;
+}
+
+static int coroutine_fn vmdk_co_write_zeroes(BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors)
+{
+int ret;
+BDRVVmdkState *s = bs-opaque;
+qemu_co_mutex_lock(s-lock);
+ret = vmdk_write(bs, sector_num, NULL, nb_sectors, true, true);
+if (!ret) {
+ret = vmdk_write(bs, sector_num, NULL, nb_sectors, true, false);
+}
 qemu_co_mutex_unlock(s-lock);
 return ret;
 }
@@ -1738,6 +1786,7 @@ static BlockDriver bdrv_vmdk = {
 .bdrv_reopen_prepare = vmdk_reopen_prepare,
 .bdrv_read  = vmdk_co_read,
 .bdrv_write = vmdk_co_write,
+.bdrv_co_write_zeroes = vmdk_co_write_zeroes,
 .bdrv_close = vmdk_close,
 .bdrv_create= vmdk_create,
 .bdrv_co_flush_to_disk  = vmdk_co_flush,
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 3/6] vmdk: Add option to create zeroed-grain image

2013-04-24 Thread Fam Zheng
Add image create option zeroed-grain to enable zeroed-grain GTE
feature of vmdk sparse extents. When this option is on, header version
of newly created extent will be 2 and VMDK4_FLAG_ZERO_GRAIN flag bit
will be set.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 7e07c0f..cc19e20 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -48,6 +48,8 @@
 #define VMDK_UNALLOC (-2)
 #define VMDK_ZEROED  (-3)
 
+#define BLOCK_OPT_ZEROED_GRAIN zeroed_grain
+
 typedef struct {
 uint32_t version;
 uint32_t flags;
@@ -1262,7 +1264,7 @@ static coroutine_fn int vmdk_co_write(BlockDriverState 
*bs, int64_t sector_num,
 
 
 static int vmdk_create_extent(const char *filename, int64_t filesize,
-  bool flat, bool compress)
+  bool flat, bool compress, bool zeroed_grain)
 {
 int ret, i;
 int fd = 0;
@@ -1284,9 +1286,10 @@ static int vmdk_create_extent(const char *filename, 
int64_t filesize,
 }
 magic = cpu_to_be32(VMDK4_MAGIC);
 memset(header, 0, sizeof(header));
-header.version = 1;
-header.flags =
-3 | (compress ? VMDK4_FLAG_COMPRESS | VMDK4_FLAG_MARKER : 0);
+header.version = zeroed_grain ? 2 : 1;
+header.flags = 3
+   | (compress ? VMDK4_FLAG_COMPRESS | VMDK4_FLAG_MARKER : 0)
+   | (zeroed_grain ? VMDK4_FLAG_ZERO_GRAIN : 0);
 header.compressAlgorithm = compress ? VMDK4_COMPRESSION_DEFLATE : 0;
 header.capacity = filesize / 512;
 header.granularity = 128;
@@ -1467,6 +1470,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 char parent_desc_line[BUF_SIZE] = ;
 uint32_t parent_cid = 0x;
 uint32_t number_heads = 16;
+bool zeroed_grain = false;
 const char desc_template[] =
 # Disk DescriptorFile\n
 version=1\n
@@ -1502,6 +1506,8 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 flags |= options-value.n ? BLOCK_FLAG_COMPAT6 : 0;
 } else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) {
 fmt = options-value.s;
+} else if (!strcmp(options-name, BLOCK_OPT_ZEROED_GRAIN)) {
+zeroed_grain |= options-value.n;
 }
 options++;
 }
@@ -1588,7 +1594,8 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 snprintf(ext_filename, sizeof(ext_filename), %s%s,
 path, desc_filename);
 
-if (vmdk_create_extent(ext_filename, size, flat, compress)) {
+if (vmdk_create_extent(ext_filename, size,
+   flat, compress, zeroed_grain)) {
 return -EINVAL;
 }
 filesize -= size;
@@ -1714,6 +1721,11 @@ static QEMUOptionParameter vmdk_create_options[] = {
 VMDK flat extent format, can be one of 
 {monolithicSparse (default) | monolithicFlat | 
twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} 
 },
+{
+.name = BLOCK_OPT_ZEROED_GRAIN,
+.type = OPT_FLAG,
+.help = Enable efficient zero writes using the zeroed-grain GTE 
feature
+},
 { NULL }
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 4/6] vmdk: change magic number to macro

2013-04-24 Thread Fam Zheng
Two hard coded flag bits are changed to macros.
Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index cc19e20..0463d3b 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -32,6 +32,7 @@
 #define VMDK3_MAGIC (('C'  24) | ('O'  16) | ('W'  8) | 'D')
 #define VMDK4_MAGIC (('K'  24) | ('D'  16) | ('M'  8) | 'V')
 #define VMDK4_COMPRESSION_DEFLATE 1
+#define VMDK4_FLAG_NL_DETECT (1  0)
 #define VMDK4_FLAG_RGD (1  1)
 /* Zeroed-grain enable bit */
 #define VMDK4_FLAG_ZERO_GRAIN   (1  2)
@@ -1287,7 +1288,7 @@ static int vmdk_create_extent(const char *filename, 
int64_t filesize,
 magic = cpu_to_be32(VMDK4_MAGIC);
 memset(header, 0, sizeof(header));
 header.version = zeroed_grain ? 2 : 1;
-header.flags = 3
+header.flags = VMDK4_FLAG_RGD | VMDK4_FLAG_NL_DETECT
| (compress ? VMDK4_FLAG_COMPRESS | VMDK4_FLAG_MARKER : 0)
| (zeroed_grain ? VMDK4_FLAG_ZERO_GRAIN : 0);
 header.compressAlgorithm = compress ? VMDK4_COMPRESSION_DEFLATE : 0;
-- 
1.8.1.4




[Qemu-devel] [RESEND PATCH 1/2] qapi: introduce strList and visit_type_strList()

2013-04-24 Thread Amos Kong
Currently we can only use ['String'] to add string to a list,
it contains some additional JSON structure.
multicast: [
{
str: 01:80:c2:00:00:21
},
{
str: 00:00:00:00:00:00
}
]

This patch introdued strList, we can use ['str']

multicast: [
01:00:5e:00:00:01,
33:33:ff:12:34:57
]

Signed-off-by: Amos Kong ak...@redhat.com
---
I used an _ugly_ #ifndef to limit it only be defined in qapi-types.h.
do you have some suggestion to fix it?
---
 include/qapi/visitor.h |2 ++
 qapi/qapi-visit-core.c |   23 +++
 scripts/qapi-types.py  |8 
 3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 1fef18c..a79ce79 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -50,6 +50,8 @@ 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);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
+void visit_type_strList(Visitor *m, strList ** obj, const char *name,
+Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error 
**errp);
 
 #endif
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 401ee6e..dc54cc8 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -257,6 +257,29 @@ void visit_type_str(Visitor *v, char **obj, const char 
*name, Error **errp)
 }
 }
 
+void visit_type_strList(Visitor *m, strList ** obj, const char *name,
+Error **errp)
+{
+GenericList *i, **prev = (GenericList **)obj;
+Error *err = NULL;
+
+if (!error_is_set(errp)) {
+visit_start_list(m, name, err);
+if (!err) {
+for (; (i = visit_next_list(m, prev, err)) != NULL; prev = i) {
+strList *native_i = (strList *)i;
+visit_type_str(m, native_i-value, NULL, err);
+}
+error_propagate(errp, err);
+err = NULL;
+
+/* Always call end_list if start_list succeeded.  */
+visit_end_list(m, err);
+}
+error_propagate(errp, err);
+}
+}
+
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
 {
 if (!error_is_set(errp)) {
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9e19920..f2ca373 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -276,6 +276,14 @@ fdecl.write(mcgen('''
 #include stdbool.h
 #include stdint.h
 
+#ifndef QGA_QAPI_TYPES_H
+typedef struct strList
+{
+  char *value;
+  struct strList *next;
+} strList;
+#endif
+
 ''',
   guard=guardname(h_file)))
 
-- 
1.7.1




[Qemu-devel] [PATCH v3 5/6] vmdk: store fields of VmdkMetaData in cpu endian

2013-04-24 Thread Fam Zheng
Previously VmdkMetaData.offset is stored little endian while other
fields are cpu endian. This changes offset to cpu endian and convert
before writing to image.
Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 0463d3b..16e1417 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -813,14 +813,15 @@ static int get_whole_cluster(BlockDriverState *bs,
 
 static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data)
 {
+uint32_t offset;
+QEMU_BUILD_BUG_ON(sizeof(offset) != sizeof(m_data-offset));
+offset = cpu_to_le32(m_data-offset);
 /* update L2 table */
 if (bdrv_pwrite_sync(
 extent-file,
 ((int64_t)m_data-l2_offset * 512)
 + (m_data-l2_index * sizeof(m_data-offset)),
-(m_data-offset),
-sizeof(m_data-offset)
-)  0) {
+offset, sizeof(offset))  0) {
 return VMDK_ERROR;
 }
 /* update backup L2 table */
@@ -830,8 +831,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData 
*m_data)
 extent-file,
 ((int64_t)m_data-l2_offset * 512)
 + (m_data-l2_index * sizeof(m_data-offset)),
-(m_data-offset), sizeof(m_data-offset)
-)  0) {
+offset, sizeof(offset))  0) {
 return VMDK_ERROR;
 }
 }
@@ -938,7 +938,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 }
 
 if (m_data) {
-m_data-offset = tmp;
+m_data-offset = *cluster_offset;
 m_data-l1_index = l1_index;
 m_data-l2_index = l2_index;
 m_data-l2_offset = l2_offset;
-- 
1.8.1.4




[Qemu-devel] [PATCH 2/2] monitor: introduce query-config-schema command

2013-04-24 Thread Amos Kong
Libvirt has no way to probe if an option or property is supported,
This patch introdues a new qmp command to query configuration schema
information. hmp command isn't added because it's not needed.

Signed-off-by: Amos Kong ak...@redhat.com
CC: Osier Yang jy...@redhat.com
CC: Anthony Liguori aligu...@us.ibm.com
---
 qapi-schema.json   |   29 +
 qmp-commands.hx|   40 
 util/qemu-config.c |   40 
 3 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 751d3c2..aeab057 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3505,3 +3505,32 @@
 '*asl_compiler_rev':  'uint32',
 '*file':  'str',
 '*data':  'str' }}
+
+##
+# @ConfigSchemaInfo:
+#
+# Configration schema information.
+#
+# @option: option name
+#
+# @params: parameters strList of one option
+#
+# Since 1.5
+##
+{ 'type': 'ConfigSchemaInfo', 'data': {'option': 'str', 'params': ['str']} }
+
+##
+# @query-config-schema
+#
+# Query configuration schema information of options
+#
+# @option: #optional option name
+#
+# Returns: returns @ConfigSchemaInfo if option is assigned, returns
+#  @ConfigSchemaInfo list if no option is assigned, returns an error
+#  QERR_INVALID_OPTION_GROUP if assigned option doesn't exist.
+#
+# Since 1.5
+##
+{'command': 'query-config-schema', 'data': {'*option': 'str'},
+ 'returns': ['ConfigSchemaInfo']}
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 4d65422..c6399be 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2414,6 +2414,46 @@ EQMP
 .args_type  = ,
 .mhandler.cmd_new = qmp_marshal_input_query_uuid,
 },
+SQMP
+query-config-schema
+
+
+Show configuration schema.
+
+Return configuration schema of one option if option is assigned, return
+configuration schema list of all options if no option is assigned. return
+an error QERR_INVALID_OPTION_GROUP if assigned option doesn't exist.
+
+- option: option name
+- params: parameters string list of one option
+
+Example:
+
+- {execute: query-config-schema, arguments : {option: boot-opts}}
+- {
+return: [
+{
+params: [
+strict,
+reboot-timeout,
+splash-time,
+splash,
+menu,
+once,
+order
+],
+option: boot-opts
+}
+]
+  }
+
+EQMP
+
+{
+.name   = query-config-schema,
+.args_type  = option:s?,
+.mhandler.cmd_new = qmp_marshal_input_query_config_schema,
+},
 
 SQMP
 query-migrate
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 01ca890..e8b4466 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -5,6 +5,7 @@
 #include qapi/qmp/qerror.h
 #include hw/qdev.h
 #include qapi/error.h
+#include qmp-commands.h
 
 static QemuOptsList *vm_config_groups[32];
 
@@ -37,6 +38,45 @@ QemuOptsList *qemu_find_opts(const char *group)
 return ret;
 }
 
+ConfigSchemaInfoList *qmp_query_config_schema(bool has_option,
+  const char *option, Error **errp)
+{
+ConfigSchemaInfoList *conf_list = NULL, *entry;
+ConfigSchemaInfo *info;
+strList *str_list = NULL, *str_entry;
+int entries, i, j;
+
+entries = ARRAY_SIZE(vm_config_groups);
+
+for (i = 0; i  entries; i++) {
+if (vm_config_groups[i] != NULL 
+(!has_option || !strcmp(option, vm_config_groups[i]-name))) {
+info = g_malloc0(sizeof(*info));
+info-option = g_strdup(vm_config_groups[i]-name);
+str_list = NULL;
+
+for (j = 0; vm_config_groups[i]-desc[j].name != NULL; j++) {
+str_entry = g_malloc0(sizeof(*str_entry));
+str_entry-value = g_strdup(vm_config_groups[i]-desc[j].name);
+str_entry-next = str_list;
+str_list = str_entry;
+}
+
+info-params = str_list;
+entry = g_malloc0(sizeof(*entry));
+entry-value = info;
+entry-next = conf_list;
+conf_list = entry;
+}
+}
+
+if (conf_list == NULL) {
+error_set(errp, QERR_INVALID_OPTION_GROUP, option);
+}
+
+return conf_list;
+}
+
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
 {
 return find_list(vm_config_groups, group, errp);
-- 
1.7.1




Re: [Qemu-devel] [PATCH 0/3] block: block-backup live backup command

2013-04-24 Thread Eric Blake
On 04/24/2013 01:41 AM, Stefan Hajnoczi wrote:


 2. Sync modes like drive-mirror (top, full, none).  This makes it possible 
 to
preserve the backing file chain.

 Based on today's phone call, it sounds like this would mean adding
 optional parameters to the QMP command.

 
 It's not a problem in this case because block-backup and the sync mode
 optional parameter will be added in the 1.6 release cycle.

Ah, I misunderstood - I thought you were shooting for 1.5 for the
initial release.  But it definitely makes more sense if the entire
command is waiting for 1.6, since we've already entered soft freeze for 1.5.

-- 
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] ui/gtk: Add Turkish translations

2013-04-24 Thread Daniel P. Berrange
On Wed, Apr 24, 2013 at 07:36:25AM -0500, Anthony Liguori wrote:
 Andreas Färber afaer...@suse.de writes:
 
  Anthony,
 
  Am 23.04.2013 12:04, schrieb Ozan Çağlayan:
  Signed-off-by: Ozan Çağlayan ozan...@gmail.com
  ---
   po/tr.po | 62 
  ++
   1 file changed, 62 insertions(+)
   create mode 100644 po/tr.po
  
  diff --git a/po/tr.po b/po/tr.po
  new file mode 100644
  index 000..4faefbd
  --- /dev/null
  +++ b/po/tr.po
  @@ -0,0 +1,62 @@
  +# Turkish translation for QEMU.
  +# This file is put in the public domain.
 
  I see this got committed - didn't you say a while ago to malc that in
  the public domain was not a legally valid license?
 
 Yup, this is my fault.  xgettext generates this by default in
 messages.po.  Translators copy that and get the boiler plate
 silliness.  I should have noticed when I first added it.
 
 I'll send a series this afternoon and ask for all contributors to Ack.
 Thanks for spotting this.

Sounds like 'checkpatch.pl' could also do a quick grep for the phrase
'public domain' and complain if found to prevent this happening again
in the future.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] [PATCH 1/5] pci: Simpler implementation of PCI_COMMAND_MASTER bit

2013-04-24 Thread David Gibson
On Wed, Apr 24, 2013 at 02:36:46PM +0200, Paolo Bonzini wrote:
 Il 24/04/2013 14:01, David Gibson ha scritto:
  In commit 1c380f9460522f32c8dd2577b2a53d518ec91c6d pci: honor
  PCI_COMMAND_MASTER the PCI_COMMAND_MASTER bit of the PCI command register
  was implemented by toggling the enable bit on a memory region alias
  interposed between the PCI device's dma address space and the main
  system memory region.
  
  Introducing an extra alias region for every PCI device just to implement
  that bit seems like serious overkill.  Furthermore, it doesn't work when
  there's a (guest side) iommu present, since that uses a different path for
  constructing the PCI device's dma address space.
  
  This patch removes the aliased window, instead implementing
  PCI_COMMAND_MASTER with tests in the PCI DMA functions.
  
  Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 
 This doesn't work.

Well.. say rather that it fails to work in a different set of
circumstances from those in which the current scheme fails to work.

 You have no guarantee that PCI devices use the PCI DMA functions.  The
 device could just pass the DMAContext to another function, and indeed
 the OHCI controller does exactly that.

Ah, good point.  Drat.

 This will be even simpler after IOMMU/DMAContext are also unified in the
 AddressSpace framework.
 
 Paolo
 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: Digital signature


Re: [Qemu-devel] [PATCH 2/5] pci: Don't create an address space object for every PCI device

2013-04-24 Thread David Gibson
On Wed, Apr 24, 2013 at 02:34:21PM +0200, Paolo Bonzini wrote:
 Il 24/04/2013 14:01, David Gibson ha scritto:
  So while its true that the DMAContext handling needs to be better
  integrated with the MemoryRegion and AddressSpace handling, that commit
  wasn't actually a step in the right direction for it.  Since then, the
  DMAContext has been extended so it can backend onto an AddressSpace, and
  thereby, a MemoryRegion.  Effectively a DMAContext is now an AddressSpace
  with iommu translation handling on top.
  
  Therefore, this patch essentially reverts the earlier commit, making all
  PCI devices by default shared the global dma_context_memory which backs
  onto main system memory.  Those cases which need to set up different DMA
  address spaces for each PCI device should supply a suitable dma_context_fn
  in the bus to correctly assign / create suitable DMAContext structures.
 
 I think this will be handled correctly when I submit IOMMU AddressSpace
 patches (next week or so).  The structure will be
 
 PCI device 1   PCI device 2
 ---
AddressSpace 1  AddressSpace 2
|   |
| (enable/disable)  | (enable/disable)
'---.  .'
v  v
  IOMMU AddressSpace
 |
 | (translation)
 v
system memory
 
 VFIO will be able to access the IOMMU AddressSpace simply via
 pci_dev-iommu, and that field will be ==-identical  for different PCI
 devices.

Hrm, ok.  Still seems excessively complicated, but as long as there's
a way to get from the pci device to the common address space, I can
work with that.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: Digital signature


[Qemu-devel] [PATCH v3 2/6] vmdk: add support for “zeroed‐grain” GTE

2013-04-24 Thread Fam Zheng
Introduced support for zeroed-grain GTE, as specified in Virtual Disk
Format 5.0[1].

Recent VMware hosted platform products support a new “zeroed‐grain”
grain table entry (GTE). The zeroed‐grain GTE returns all zeros on
read.  In other words, the zeroed‐grain GTE indicates that a grain
in the child disk is zero‐filled but does not actually occupy space
in storage.  A sparse extent with zeroed‐grain GTE has the following
in its header:

 * SparseExtentHeader.version = 2
 * SparseExtentHeader.flags has bit 2 set

Other than the new flag and the possibly zeroed‐grain GTE, version 2
sparse extents are identical to version 1.  Also, a zeroed‐grain GTE
has value 0x1 in the GT table.

[1] Virtual Disk Format 5.0, 
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?src=vmdk
Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c | 24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 16aa29c..7e07c0f 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -33,10 +33,13 @@
 #define VMDK4_MAGIC (('K'  24) | ('D'  16) | ('M'  8) | 'V')
 #define VMDK4_COMPRESSION_DEFLATE 1
 #define VMDK4_FLAG_RGD (1  1)
+/* Zeroed-grain enable bit */
+#define VMDK4_FLAG_ZERO_GRAIN   (1  2)
 #define VMDK4_FLAG_COMPRESS (1  16)
 #define VMDK4_FLAG_MARKER (1  17)
 #define VMDK4_GD_AT_END 0xULL
 
+#define VMDK_GTE_ZEROED 0x1
 
 /* VMDK internal error codes */
 #define VMDK_OK  0
@@ -81,6 +84,8 @@ typedef struct VmdkExtent {
 bool flat;
 bool compressed;
 bool has_marker;
+bool has_zero_grain;
+int version;
 int64_t sectors;
 int64_t end_sector;
 int64_t flat_start_offset;
@@ -569,6 +574,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
 extent-compressed =
 le16_to_cpu(header.compressAlgorithm) == VMDK4_COMPRESSION_DEFLATE;
 extent-has_marker = le32_to_cpu(header.flags)  VMDK4_FLAG_MARKER;
+extent-version = le32_to_cpu(header.version);
+extent-has_zero_grain = le32_to_cpu(header.flags)  VMDK4_FLAG_ZERO_GRAIN;
 ret = vmdk_init_tables(bs, extent);
 if (ret) {
 /* free extent allocated by vmdk_add_extent */
@@ -839,6 +846,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 unsigned int l1_index, l2_offset, l2_index;
 int min_index, i, j;
 uint32_t min_count, *l2_table, tmp = 0;
+bool zeroed = false;
 
 if (m_data) {
 m_data-valid = 0;
@@ -894,9 +902,13 @@ static int get_cluster_offset(BlockDriverState *bs,
 l2_index = ((offset  9) / extent-cluster_sectors) % extent-l2_size;
 *cluster_offset = le32_to_cpu(l2_table[l2_index]);
 
-if (!*cluster_offset) {
+if (extent-has_zero_grain  *cluster_offset == VMDK_GTE_ZEROED) {
+zeroed = true;
+}
+
+if (!*cluster_offset || zeroed) {
 if (!allocate) {
-return VMDK_UNALLOC;
+return zeroed ? VMDK_ZEROED : VMDK_UNALLOC;
 }
 
 /* Avoid the L2 tables update for the images that have snapshots. */
@@ -967,8 +979,8 @@ static int coroutine_fn 
vmdk_co_is_allocated(BlockDriverState *bs,
 ret = get_cluster_offset(bs, extent, NULL,
 sector_num * 512, 0, offset);
 qemu_co_mutex_unlock(s-lock);
-/* get_cluster_offset returning 0 means success */
-ret = !ret;
+
+ret = (ret == VMDK_OK || ret == VMDK_ZEROED);
 
 index_in_cluster = sector_num % extent-cluster_sectors;
 n = extent-cluster_sectors - index_in_cluster;
@@ -,9 +1123,9 @@ static int vmdk_read(BlockDriverState *bs, int64_t 
sector_num,
 if (n  nb_sectors) {
 n = nb_sectors;
 }
-if (ret) {
+if (ret != VMDK_OK) {
 /* if not allocated, try to read from parent image, if exist */
-if (bs-backing_hd) {
+if (bs-backing_hd  ret != VMDK_ZEROED) {
 if (!vmdk_is_cid_valid(bs)) {
 return -EINVAL;
 }
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH v2 3/5] block: initial VHDX driver support framework - supports open and probe

2013-04-24 Thread Stefan Hajnoczi
On Tue, Apr 23, 2013 at 10:24:22AM -0400, Jeff Cody wrote:
 +if (!vhdx_checksum_is_valid(buffer, VHDX_HEADER_BLOCK_SIZE, 4) ||
 +s-rt.signature != VHDX_RT_MAGIC) {
 +ret = -EINVAL;
 +goto fail;
 +}
 +
 +for (i = 0; i  s-rt.entry_count; i++) {

It's nice to avoid signed/unsigned comparisons.  i should be uint32_t
just like entry_count.

 +memcpy(rt_entry, buffer+offset, sizeof(rt_entry));
 +offset += sizeof(rt_entry);

Looks like we're trusting rt.entry_count to be a sane value?  Need to
prevent offset from exceeding buffer size.

 +while (logical_sector_size = 1) {
 +s-logical_sector_size_bits++;
 +}
 +while (sectors_per_block = 1) {
 +s-sectors_per_block_bits++;
 +}
 +while (chunk_ratio = 1) {
 +s-chunk_ratio_bits++;
 +}
 +while (block_size = 1) {
 +s-block_size_bits++;
 +}

ctz()/clo() do this.

 +static int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s)
 +{
 +int ret = 0;
 +int i;
 +vhdx_header *hdr;
 +
 +hdr = s-headers[s-curr_header];
 +
 +/* either either the log guid, or log length is zero,

either either

 +s-bat_offset = s-bat_rt.file_offset;
 +s-bat_entries = s-bat_rt.length / sizeof(vhdx_bat_entry);
 +s-bat = qemu_blockalign(bs, s-bat_rt.length);

No sanity check was done on bat_rt.length.  If this allocation fails
QEMU will exit.  Could be used as a DoS if you can get someone to attach
a malicious VHDX to their VM?



  1   2   3   >