Re: [Qemu-devel] [PATCH v2 1/2] net: introduce MAC_TABLE_CHANGED event

2013-05-23 Thread Amos Kong
On Tue, May 21, 2013 at 11:51:17AM +0300, Michael S. Tsirkin wrote:
 On Tue, May 21, 2013 at 01:04:55PM +0800, Amos Kong wrote:
 

snip
+event_data = qobject_from_jsonf({ 'name': %s }, 
n-netclient_name);
+monitor_protocol_event(QEVENT_MAC_TABLE_CHANGED, event_data);
+qobject_decref(event_data);
+
 return VIRTIO_NET_OK;
 }

   
   This makes it easy for guest to flood management with
   spurious events.
  
   How about we set a flag after this, and avoid sending any more
   events until management queries the filter status?
  
  As you discussed in this thread, we need a flag to turn on/off
  the event notification to avoid the flooding.
  
  But we could not set the flag in first mac-table change to turn off
  the notification.

I'm wrong. Management's query for first event will enable
notification. If management don't query, no problem here,
because we only need to know the latest rx-filter state.

  Becase one action(execute one cmd in guest) might
  cause multiple events.

|| To clarify what I am proposing:
|| - on info mac-table - clear flag
|| - on mac-table change - test and set flag
||   if was not set - send event to management
||   if was set - do not send event
 
 I still think it will work.

Yes, it works, effectively avoid the event flooding.

 since the event does not have any
 information, what does it matter that we send one and not many events?
 
  It would be flexible to add a parameter for query-mac-table to change
  the flag. Or add a new command to change the flag.
   
  -- 
  Amos.
 
 Looks a bit too complex, to me.

-- 
Amos.



Re: [Qemu-devel] [PATCH v3 1/3] debugcon: fix always print addr=0x0, val=0x0 bug

2013-05-23 Thread Markus Armbruster
Cc'ing qemu-trivial.

liguang lig.f...@cn.fujitsu.com writes:

 when use DEBUG_DEBUGCON, screen spits:
 debugcon: write addr=0x val=0x00
 Rdebugcon: write addr=0x val=0x00
 udebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 idebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 gdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 pdebugcon: write addr=0x val=0x00
 tdebugcon: write addr=0x val=0x00
 idebugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 rdebugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 mdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 adebugcon: write addr=0x val=0x00
 tdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00

 Oh, that's wrong, val is not always be 0.
 this bug caused by lack of length modifier
 for specifier 'x'.

Subject is misleading, it doesn't always print, only when
DEBUG_DEBUGCON is enabled.

Recommend to abridge the commit message radically.

 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  hw/char/debugcon.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
 index 0588eeb..44c93e1 100644
 --- a/hw/char/debugcon.c
 +++ b/hw/char/debugcon.c
 @@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr 
 addr, uint64_t val,
  unsigned char ch = val;
  
  #ifdef DEBUG_DEBUGCON
 -printf(debugcon: write addr=0x%04x val=0x%02x\n, addr, val);
 +printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
 val);
  #endif
  
  qemu_chr_fe_write(s-chr, ch, 1);



Re: [Qemu-devel] [PATCH v3 1/3] debugcon: fix always print addr=0x0, val=0x0 bug

2013-05-23 Thread li guang
在 2013-05-23四的 08:25 +0200,Markus Armbruster写道:
 Cc'ing qemu-trivial.
 
 liguang lig.f...@cn.fujitsu.com writes:
 
  when use DEBUG_DEBUGCON, screen spits:
  debugcon: write addr=0x val=0x00
  Rdebugcon: write addr=0x val=0x00
  udebugcon: write addr=0x val=0x00
  ndebugcon: write addr=0x val=0x00
  ndebugcon: write addr=0x val=0x00
  idebugcon: write addr=0x val=0x00
  ndebugcon: write addr=0x val=0x00
  gdebugcon: write addr=0x val=0x00
   debugcon: write addr=0x val=0x00
  odebugcon: write addr=0x val=0x00
  pdebugcon: write addr=0x val=0x00
  tdebugcon: write addr=0x val=0x00
  idebugcon: write addr=0x val=0x00
  odebugcon: write addr=0x val=0x00
  ndebugcon: write addr=0x val=0x00
   debugcon: write addr=0x val=0x00
  rdebugcon: write addr=0x val=0x00
  odebugcon: write addr=0x val=0x00
  mdebugcon: write addr=0x val=0x00
   debugcon: write addr=0x val=0x00
  adebugcon: write addr=0x val=0x00
  tdebugcon: write addr=0x val=0x00
   debugcon: write addr=0x val=0x00
 
  Oh, that's wrong, val is not always be 0.
  this bug caused by lack of length modifier
  for specifier 'x'.
 
 Subject is misleading, it doesn't always print, only when
 DEBUG_DEBUGCON is enabled.
 
 Recommend to abridge the commit message radically.

OK, thanks!

 
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
  ---
   hw/char/debugcon.c |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
  diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
  index 0588eeb..44c93e1 100644
  --- a/hw/char/debugcon.c
  +++ b/hw/char/debugcon.c
  @@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr 
  addr, uint64_t val,
   unsigned char ch = val;
   
   #ifdef DEBUG_DEBUGCON
  -printf(debugcon: write addr=0x%04x val=0x%02x\n, addr, val);
  +printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
  val);
   #endif
   
   qemu_chr_fe_write(s-chr, ch, 1);





[Qemu-devel] [PATCH][v4 1/3] debugcon: fix always print addr=0x0, val=0x0 bug

2013-05-23 Thread liguang
when use DEBUG_DEBUGCON, screen spits:
debugcon: write addr=0x val=0x00
Rdebugcon: write addr=0x val=0x00
udebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
idebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
gdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
pdebugcon: write addr=0x val=0x00
tdebugcon: write addr=0x val=0x00
idebugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
rdebugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
mdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
adebugcon: write addr=0x val=0x00
tdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00

Oh, that's wrong, val is not always be 0.
this bug caused by lack of length modifier
for specifier 'x'.

Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
v4: fix misleading subject
---
 hw/char/debugcon.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
index 02c9577..7e41c90 100644
--- a/hw/char/debugcon.c
+++ b/hw/char/debugcon.c
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, 
uint64_t val,
 unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-printf(debugcon: write addr=0x%04x val=0x%02x\n, addr, val);
+printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
val);
 #endif
 
 qemu_chr_fe_write(s-chr, ch, 1);
-- 
1.7.2.5




[Qemu-devel] [PATCH][v4 1/3] debugcon: fix always print addr=0x0, val=0x0 bug when use DEBUG_DEBUGCON

2013-05-23 Thread liguang
when use DEBUG_DEBUGCON, screen spits:
debugcon: write addr=0x val=0x00
Rdebugcon: write addr=0x val=0x00
udebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
idebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
gdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
pdebugcon: write addr=0x val=0x00
tdebugcon: write addr=0x val=0x00
idebugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
ndebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
rdebugcon: write addr=0x val=0x00
odebugcon: write addr=0x val=0x00
mdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00
adebugcon: write addr=0x val=0x00
tdebugcon: write addr=0x val=0x00
 debugcon: write addr=0x val=0x00

Oh, that's wrong, val is not always be 0.
this bug caused by lack of length modifier
for specifier 'x'.

Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
v4: fix misleading subject
---
 hw/char/debugcon.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
index 02c9577..7e41c90 100644
--- a/hw/char/debugcon.c
+++ b/hw/char/debugcon.c
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, 
uint64_t val,
 unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-printf(debugcon: write addr=0x%04x val=0x%02x\n, addr, val);
+printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
val);
 #endif
 
 qemu_chr_fe_write(s-chr, ch, 1);
-- 
1.7.2.5




[Qemu-devel] [PATCH][v4 2/3] debugcon: make debug message more readable

2013-05-23 Thread liguang
before change:
Bdebugcon: write addr=0x val=0x6f
odebugcon: write addr=0x val=0x6f
odebugcon: write addr=0x val=0x74
tdebugcon: write addr=0x val=0x69
idebugcon: write addr=0x val=0x6e
ndebugcon: write addr=0x val=0x67
gdebugcon: write addr=0x val=0x20
 debugcon: write addr=0x val=0x66

after change:
B [debugcon: write addr=0x val=0x6f]
o [debugcon: write addr=0x val=0x6f]
o [debugcon: write addr=0x val=0x74]
t [debugcon: write addr=0x val=0x69]
i [debugcon: write addr=0x val=0x6e]
n [debugcon: write addr=0x val=0x67]
g [debugcon: write addr=0x val=0x20]
  [debugcon: write addr=0x val=0x66]

Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 hw/char/debugcon.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
index 7e41c90..52fa0ab 100644
--- a/hw/char/debugcon.c
+++ b/hw/char/debugcon.c
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, 
uint64_t val,
 unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
val);
+printf( [debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x]\n, addr, 
val);
 #endif
 
 qemu_chr_fe_write(s-chr, ch, 1);
-- 
1.7.2.5




[Qemu-devel] [PATCH][v4 3/3] debugcon: fix compiler warning when open DEBUG_DEBUGCON

2013-05-23 Thread liguang
compiler warnings:
  CChw/char/debugcon.o
hw/char/debugcon.c: In function ‘debugcon_ioport_write’:
hw/char/debugcon.c:58: warning: format ‘%02x’ expects type ‘unsigned int’, but 
argument 3 has type ‘uint64_t’
hw/char/debugcon.c: In function ‘debugcon_ioport_read’:
hw/char/debugcon.c:70: warning: format ‘%04x’ expects type ‘unsigned int’, but 
argument 2 has type ‘hwaddr’

Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 hw/char/debugcon.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
index 52fa0ab..3b0637d 100644
--- a/hw/char/debugcon.c
+++ b/hw/char/debugcon.c
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, 
uint64_t val,
 unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-printf( [debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x]\n, addr, 
val);
+printf( [debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02 PRIx64 
]\n, addr, val);
 #endif
 
 qemu_chr_fe_write(s-chr, ch, 1);
@@ -67,7 +67,7 @@ static uint64_t debugcon_ioport_read(void *opaque, hwaddr 
addr, unsigned width)
 DebugconState *s = opaque;
 
 #ifdef DEBUG_DEBUGCON
-printf(debugcon: read addr=0x%04x\n, addr);
+printf(debugcon: read addr=0x%04 HWADDR_PRIx \n, addr);
 #endif
 
 return s-readback;
-- 
1.7.2.5




Re: [Qemu-devel] [PATCH 17/30] memory: add address_space_translate

2013-05-23 Thread liu ping fan
On Tue, May 21, 2013 at 6:57 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Using phys_page_find to translate an AddressSpace to a MemoryRegionSection
 is unwieldy.  It requires to pass the page index rather than the address,
 and later memory_region_section_addr has to be called.  Replace
 memory_region_section_addr with a function that does all of it: call
 phys_page_find, compute the offset within the region, and check how
 big the current mapping is.  This way, a large flat region can be written
 with a single lookup rather than a page at a time.

 address_space_translate will also provide a single point where IOMMU
 forwarding is implemented.

 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  cputlb.c  |  20 ++---
  exec.c| 201 
 +++---
  include/exec/cputlb.h |  12 ++-
  include/exec/memory.h |  31 
  translate-all.c   |   6 +-
  5 files changed, 143 insertions(+), 127 deletions(-)

 diff --git a/cputlb.c b/cputlb.c
 index aba7e44..1f85da0 100644
 --- a/cputlb.c
 +++ b/cputlb.c
 @@ -248,13 +248,18 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
  target_ulong code_address;
  uintptr_t addend;
  CPUTLBEntry *te;
 -hwaddr iotlb;
 +hwaddr iotlb, xlat, sz;

  assert(size = TARGET_PAGE_SIZE);
  if (size != TARGET_PAGE_SIZE) {
  tlb_add_large_page(env, vaddr, size);
  }
 -section = phys_page_find(address_space_memory.dispatch, paddr  
 TARGET_PAGE_BITS);
 +
 +sz = size;
 +section = address_space_translate(address_space_memory, paddr, xlat, 
 sz,
 +  false);
 +assert(sz = TARGET_PAGE_SIZE);
 +
  #if defined(DEBUG_TLB)
  printf(tlb_set_page: vaddr= TARGET_FMT_lx  paddr=0x TARGET_FMT_plx
  prot=%x idx=%d pd=0x%08lx\n,
 @@ -269,15 +274,14 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
  }
  if (memory_region_is_ram(section-mr) ||
  memory_region_is_romd(section-mr)) {
 -addend = (uintptr_t)memory_region_get_ram_ptr(section-mr)
 -+ memory_region_section_addr(section, paddr);
 +addend = (uintptr_t)memory_region_get_ram_ptr(section-mr) + xlat;
  } else {
  addend = 0;
  }

  code_address = address;
 -iotlb = memory_region_section_get_iotlb(env, section, vaddr, paddr, prot,
 -address);
 +iotlb = memory_region_section_get_iotlb(env, section, vaddr, paddr, xlat,
 +prot, address);

  index = (vaddr  TARGET_PAGE_BITS)  (CPU_TLB_SIZE - 1);
  env-iotlb[mmu_idx][index] = iotlb - vaddr;
 @@ -300,9 +304,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
  /* Write access calls the I/O callback.  */
  te-addr_write = address | TLB_MMIO;
  } else if (memory_region_is_ram(section-mr)
 -!cpu_physical_memory_is_dirty(
 -   section-mr-ram_addr
 -   + memory_region_section_addr(section, paddr))) {
 +!cpu_physical_memory_is_dirty(section-mr-ram_addr + 
 xlat)) {
  te-addr_write = address | TLB_NOTDIRTY;
  } else {
  te-addr_write = address;
 diff --git a/exec.c b/exec.c
 index 82da067..e5ee8ff 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -182,7 +182,7 @@ static void phys_page_set(AddressSpaceDispatch *d,
  phys_page_set_level(d-phys_map, index, nb, leaf, P_L2_LEVELS - 1);
  }

 -MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index)
 +static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr 
 index)
  {
  PhysPageEntry lp = d-phys_map;
  PhysPageEntry *p;
 @@ -198,6 +198,22 @@ MemoryRegionSection *phys_page_find(AddressSpaceDispatch 
 *d, hwaddr index)
  return phys_sections[lp.ptr];
  }

 +MemoryRegionSection *address_space_translate(AddressSpace *as, hwaddr addr,
 + hwaddr *xlat, hwaddr *plen,
 + bool is_write)
 +{
 +MemoryRegionSection *section;
 +
 +section = phys_page_find(as-dispatch, addr  TARGET_PAGE_BITS);
 +/* Compute offset within MemoryRegionSection */
 +addr -= section-offset_within_address_space;
 +*plen = MIN(section-size - addr, *plen);
 +
 +/* Compute offset within MemoryRegion */
 +*xlat = addr + section-offset_within_region;
 +return section;
 +}
 +
  bool memory_region_is_unassigned(MemoryRegion *mr)
  {
  return mr != io_mem_ram  mr != io_mem_rom
 @@ -616,11 +632,11 @@ static int cpu_physical_memory_set_dirty_tracking(int 
 enable)
  }

  hwaddr memory_region_section_get_iotlb(CPUArchState *env,
 -   MemoryRegionSection 
 *section,
 -   target_ulong vaddr,
 -  

Re: [Qemu-devel] [PATCH] kvm: add detail error message when fail to add ioeventfd

2013-05-23 Thread Stefan Hajnoczi
On Wed, May 22, 2013 at 09:48:21PM +0800, Amos Kong wrote:
 On Wed, May 22, 2013 at 11:32:27AM +0200, Stefan Hajnoczi wrote:
  On Wed, May 22, 2013 at 12:57:35PM +0800, Amos Kong wrote:
   I try to hotplug 28 * 8 multiple-function devices to guest with
   old host kernel, ioeventfds in host kernel will be exhausted, then
   qemu fails to allocate ioeventfds for blk/nic devices.
   
   It's better to add detail error here.
   
   Signed-off-by: Amos Kong ak...@redhat.com
   ---
kvm-all.c |4 
1 files changed, 4 insertions(+), 0 deletions(-)
  
  It would be nice to make kvm bus scalable so that the hardcoded
  in-kernel I/O device limit can be lifted.
 
 I had increased kernel NR_IOBUS_DEVS to 1000 (a limitation is needed for
 security) in last Mar, and make resizing kvm_io_range array dynamical.

The maximum should not be hardcoded.  File descriptor, maximum memory,
etc are all controlled by rlimits.  And since ioeventfds are file
descriptors they are already limited by the maximum number of file
descriptors.

Why is there a need to impose a hardcoded limit?

Stefan



Re: [Qemu-devel] [RFC] block-trace Low Level Command Supporting Disk Introspection

2013-05-23 Thread Stefan Hajnoczi
On Wed, May 22, 2013 at 11:46:15PM +0200, Paolo Bonzini wrote:
 Il 22/05/2013 22:47, Richard W.M. Jones ha scritto:
   
   I meant if there was interest in reading from a disk that isn't fully
   synchronized
   (yet) to the original disk (it might have old blocks).  Or would you only
   want to
   connect once a (complete) snapshot is available (synchronized completely 
   to
   some point-in.
  IIUC a disk which wasn't fully synchronized wouldn't necessarily be
  interpretable by libguestfs, so I guess we would need the complete
  snapshot.
 
 In the case of point-in-time backups (Stefan's block-backup) the plan is
 to have the snapshot complete from the beginning.

The way it will work is that the drive-backup target is a qcow2 image
with the guest's disk as its backing file.  When the guest writes to the
disk, drive-backup copies the original data to the qcow2 image.

The qcow2 image is exported over NBD so a client can connect to access
the read-only point-in-time snapshot.  It is not necessary to populate
the qcow2 file since it uses the guest disk as its backing file - all
reads to unpopulated clusters go to the backing file.

Stefan



Re: [Qemu-devel] [PATCH v3 0/8] block: drive-backup live backup command

2013-05-23 Thread Stefan Hajnoczi
On Wed, May 22, 2013 at 03:34:18PM +, Dietmar Maurer wrote:
  That sounds like more work than a persistent dirty bitmap.  The advantage 
  is that
  while dirty bitmaps are consumed by a single user, the Merkle tree can be 
  used
  to sync up any number of replicas.
 
 I also consider it safer, because you make sure the data exists (using hash 
 keys like SHA1).
 
 I am unsure how you can check if a dirty bitmap contains errors, or is out of 
 date?
 
 Also, you can compare arbitrary Merkle trees, whereas a dirty bitmap is 
 always related to a single image.
 (consider the user remove the latest backup from the backup target). 

One disadvantage of Merkle trees is that the client becomes stateful -
the client needs to store its own Merkle tree and this requires fancier
client-side code.

It is also more expensive to update hashes than a dirty bitmap.  Not
because you need to hash data but because a small write (e.g. 1 sector)
requires that you read the surrounding sectors to recompute a hash for
the cluster.  Therefore you can expect worse guest I/O performance than
with a dirty bitmap.

I still think it's a cool idea.  Making it work well will require a lot
more effort than a dirty bitmap.

Stefan



[Qemu-devel] [PATCH 0/4] ARM aarch64 TCG target VERSION 2

2013-05-23 Thread Claudio Fontana

This series implements preliminary support for the ARM aarch64 TCG target.

Limitations of this initial implementation (TODOs) include:

 * missing TLB lookup in qemu_ld/st [C helpers always called].
   An incremental patch, which requires this series, is coming up
   from teammate Jani Kokkonen to implement this.
 * most optional opcodes are not implemented yet (only rotation done).
 * CONFIG_SOFTMMU only
 * only little endian qemu targets supported

Tested running on a x86-64 physical machine running Foundation v8,
running a linux 3.8.0-rc6+ minimal host system based on linaro v8
image 201301271620 for user space.

Tested guests: arm v5 test image, i386 FreeDOS test image,
i386 linux test image, all from qemu-devel testing page.
Also tested on x86-64/linux built with buildroot,
and on arm v7/linux built with buildroot as well.

checkpatch emits a false positive for the last patch regarding
missing braces which are actually there. I suspect it is
because of a comment.

checkpatch also complains about the labeled statements in
the switch, which I think are in fact good for readability.

Claudio Fontana (4):
  include/elf.h: add aarch64 ELF machine and relocs
  tcg/aarch64: implement new TCG target for aarch64
  configure: permit compilation on arm aarch64
  tcg/aarch64: implement more low level ops in preparation of tlb lookup

 configure|8 +
 include/elf.h|  129 +
 include/exec/exec-all.h  |5 +-
 tcg/aarch64/tcg-target.c | 1203 ++
 tcg/aarch64/tcg-target.h |   99 
 translate-all.c  |2 +
 6 files changed, 1445 insertions(+), 1 deletion(-)
 create mode 100644 tcg/aarch64/tcg-target.c
 create mode 100644 tcg/aarch64/tcg-target.h

-- 
1.8.1





Re: [Qemu-devel] [PATCH v3 0/8] block: drive-backup live backup command

2013-05-23 Thread Dietmar Maurer
  I also consider it safer, because you make sure the data exists (using hash 
  keys
 like SHA1).
 
  I am unsure how you can check if a dirty bitmap contains errors, or is out 
  of
 date?
 
  Also, you can compare arbitrary Merkle trees, whereas a dirty bitmap is 
  always
 related to a single image.
  (consider the user remove the latest backup from the backup target).
 
 One disadvantage of Merkle trees is that the client becomes stateful - the 
 client
 needs to store its own Merkle tree and this requires fancier client-side code.

What 'client' do you talk about here?

But sure, the code gets more complex, and needs considerable amount of RAM
to store the hash keys .
 
 It is also more expensive to update hashes than a dirty bitmap.  Not because 
 you
 need to hash data but because a small write (e.g. 1 sector) requires that you
 read the surrounding sectors to recompute a hash for the cluster.  Therefore 
 you
 can expect worse guest I/O performance than with a dirty bitmap.

There is no need to update any hash - You only need to do that on backup - in 
fact, all
those things can be done by the backup driver.
 
 I still think it's a cool idea.  Making it work well will require a lot more 
 effort than
 a dirty bitmap.

How do you re-generate a dirty bitmap after a server crash?




[Qemu-devel] [PATCH 1/4] include/elf.h: add aarch64 ELF machine and relocs

2013-05-23 Thread Claudio Fontana

we will use the 26bit relative relocs in the aarch64 tcg target.

Signed-off-by: Claudio Fontana claudio.font...@huawei.com
---
 include/elf.h | 129 ++
 1 file changed, 129 insertions(+)

diff --git a/include/elf.h b/include/elf.h
index a21ea53..cf0d3e2 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -129,6 +129,8 @@ typedef int64_t  Elf64_Sxword;
 
 #define EM_XTENSA   94  /* Tensilica Xtensa */
 
+#define EM_AARCH64  183
+
 /* This is the info that is needed to parse the dynamic section of the file */
 #define DT_NULL0
 #define DT_NEEDED  1
@@ -616,6 +618,133 @@ typedef struct {
 /* Keep this the last entry.  */
 #define R_ARM_NUM  256
 
+/* ARM Aarch64 relocation types */
+#define R_AARCH64_NONE256 /* also accepts R_ARM_NONE (0) */
+/* static data relocations */
+#define R_AARCH64_ABS64   257
+#define R_AARCH64_ABS32   258
+#define R_AARCH64_ABS16   259
+#define R_AARCH64_PREL64  260
+#define R_AARCH64_PREL32  261
+#define R_AARCH64_PREL16  262
+/* static aarch64 group relocations */
+/* group relocs to create unsigned data value or address inline */
+#define R_AARCH64_MOVW_UABS_G0263
+#define R_AARCH64_MOVW_UABS_G0_NC 264
+#define R_AARCH64_MOVW_UABS_G1265
+#define R_AARCH64_MOVW_UABS_G1_NC 266
+#define R_AARCH64_MOVW_UABS_G2267
+#define R_AARCH64_MOVW_UABS_G2_NC 268
+#define R_AARCH64_MOVW_UABS_G3269
+/* group relocs to create signed data or offset value inline */
+#define R_AARCH64_MOVW_SABS_G0270
+#define R_AARCH64_MOVW_SABS_G1271
+#define R_AARCH64_MOVW_SABS_G2272
+/* relocs to generate 19, 21, and 33 bit PC-relative addresses */
+#define R_AARCH64_LD_PREL_LO19273
+#define R_AARCH64_ADR_PREL_LO21   274
+#define R_AARCH64_ADR_PREL_PG_HI21275
+#define R_AARCH64_ADR_PREL_PG_HI21_NC 276
+#define R_AARCH64_ADD_ABS_LO12_NC 277
+#define R_AARCH64_LDST8_ABS_LO12_NC   278
+#define R_AARCH64_LDST16_ABS_LO12_NC  284
+#define R_AARCH64_LDST32_ABS_LO12_NC  285
+#define R_AARCH64_LDST64_ABS_LO12_NC  286
+#define R_AARCH64_LDST128_ABS_LO12_NC 299
+/* relocs for control-flow - all offsets as multiple of 4 */
+#define R_AARCH64_TSTBR14 279
+#define R_AARCH64_CONDBR19280
+#define R_AARCH64_JUMP26  282
+#define R_AARCH64_CALL26  283
+/* group relocs to create pc-relative offset inline */
+#define R_AARCH64_MOVW_PREL_G0287
+#define R_AARCH64_MOVW_PREL_G0_NC 288
+#define R_AARCH64_MOVW_PREL_G1289
+#define R_AARCH64_MOVW_PREL_G1_NC 290
+#define R_AARCH64_MOVW_PREL_G2291
+#define R_AARCH64_MOVW_PREL_G2_NC 292
+#define R_AARCH64_MOVW_PREL_G3293
+/* group relocs to create a GOT-relative offset inline */
+#define R_AARCH64_MOVW_GOTOFF_G0  300
+#define R_AARCH64_MOVW_GOTOFF_G0_NC   301
+#define R_AARCH64_MOVW_GOTOFF_G1  302
+#define R_AARCH64_MOVW_GOTOFF_G1_NC   303
+#define R_AARCH64_MOVW_GOTOFF_G2  304
+#define R_AARCH64_MOVW_GOTOFF_G2_NC   305
+#define R_AARCH64_MOVW_GOTOFF_G3  306
+/* GOT-relative data relocs */
+#define R_AARCH64_GOTREL64307
+#define R_AARCH64_GOTREL32308
+/* GOT-relative instr relocs */
+#define R_AARCH64_GOT_LD_PREL19   309
+#define R_AARCH64_LD64_GOTOFF_LO15310
+#define R_AARCH64_ADR_GOT_PAGE311
+#define R_AARCH64_LD64_GOT_LO12_NC312
+#define R_AARCH64_LD64_GOTPAGE_LO15   313
+/* General Dynamic TLS relocations */
+#define R_AARCH64_TLSGD_ADR_PREL21512
+#define R_AARCH64_TLSGD_ADR_PAGE21513
+#define R_AARCH64_TLSGD_ADD_LO12_NC   514
+#define R_AARCH64_TLSGD_MOVW_G1   515
+#define R_AARCH64_TLSGD_MOVW_G0_NC516
+/* Local Dynamic TLS relocations */
+#define R_AARCH64_TLSLD_ADR_PREL21517
+#define R_AARCH64_TLSLD_ADR_PAGE21518
+#define R_AARCH64_TLSLD_ADD_LO12_NC   519
+#define R_AARCH64_TLSLD_MOVW_G1   520
+#define R_AARCH64_TLSLD_MOVW_G0_NC521
+#define R_AARCH64_TLSLD_LD_PREL19 522
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G2523
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1524
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0526
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527
+#define R_AARCH64_TLSLD_ADD_DTPREL_HI12   528
+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12   529
+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC530
+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531
+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC  532
+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12533
+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534
+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12535
+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536
+#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12537
+#define 

Re: [Qemu-devel] [PATCH v5 00/11] curl: fix curl read

2013-05-23 Thread Richard W.M. Jones

v5 tested and works for me.

Attached is the test script I'm using.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v


test.sh
Description: Bourne shell script


Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Kevin Wolf
Am 22.05.2013 um 18:14 hat Anthony Liguori geschrieben:
 Kevin Wolf kw...@redhat.com writes:
 
  Am 22.05.2013 um 15:40 hat Amos Kong geschrieben:
  Hi all,
  
  We already have query-command-line-options to query details of command-line
  options. As we discussed in the list, we also need full introspection of 
  QMP
  (command). The qmp-events also need to be dumped, we can define events in
  qai-schema.json. We can also dump QMP errors in future if it's needed.
  
  Command name: query-qmp-schema
  Return: returns the contents of qapi-schema.json in json format.
  
  Solution to query json content from C code:
qapi-schema.json is processed by qapi python scripts to generate C
files, I found the content is good enough for Libvirt to know the
QMP command schema. We can change qapi scripts to generate a talbe/list
to record the raw string, then we can return the raw string in
qmp_query_qmp_schema().
 
  Yes, the schema as defined in qapi-schema.json should be good to be sent
  over the wire.
 
  Maybe we should already now consider that we'll want to have a dynamic
  schema eventually: Depending on which modules are compiled in (or even
  which modules are loaded when we go forward with shared libraries), some
  types, commands or enum values may be available or not.
 
  For example, libvirt wants to query which block drivers it can use. It
  doesn't really matter for which drivers we had the source initially, but
  only which drivers are compiled in (possibly loaded) and can actually be
  used.
 
 The schema is the wrong place to discover this.
 
 Loading a module wouldn't add an enumeration value.  The enumeration
 values are fixed.
 
 We should introduce commands to query this kind of information.
 
 Schema introspection is primarily useful for dynamic languages to
 autogenerate bindings.  It's not terribly useful for query
 capabilities/features.

Then you won't get real modularity. It means that all modules must
already be known during the build time, and if they aren't available
(because they weren't built or aren't loaded) you include them anyway,
some parts of them are a static part of the core. You don't get fully
rid of modules by not linking their object file in, but you always have
the QAPI part left over.

It also makes the schema totally useless. If you can't use it to tell
which commands this qemu can execute and which it can't, then we don't
need introspection at all. There's no user for it then.

We can have hundreds of individual query commands like you suggest
(query-qcow2-creation-option-values, yay!) or we do the modularity
thing and the schema introspection properly and make it dynamic. I
prefer the latter.

Kevin



[Qemu-devel] [PATCH 3/4] configure: permit compilation on arm aarch64

2013-05-23 Thread Claudio Fontana

support compiling on aarch64.

Signed-off-by: Claudio Fontana claudio.font...@huawei.com
---
 configure | 8 
 1 file changed, 8 insertions(+)

diff --git a/configure b/configure
index 9439f1c..9cc398c 100755
--- a/configure
+++ b/configure
@@ -384,6 +384,8 @@ elif check_define __s390__ ; then
   fi
 elif check_define __arm__ ; then
   cpu=arm
+elif check_define __aarch64__ ; then
+  cpu=aarch64
 elif check_define __hppa__ ; then
   cpu=hppa
 else
@@ -406,6 +408,9 @@ case $cpu in
   armv*b|armv*l|arm)
 cpu=arm
   ;;
+  aarch64)
+cpu=aarch64
+  ;;
   hppa|parisc|parisc64)
 cpu=hppa
   ;;
@@ -4114,6 +4119,9 @@ if test $linux = yes ; then
   s390x)
 linux_arch=s390
 ;;
+  aarch64)
+linux_arch=arm64
+;;
   *)
 # For most CPUs the kernel architecture name and QEMU CPU name match.
 linux_arch=$cpu
-- 
1.8.1





[Qemu-devel] [PATCH 4/4] tcg/aarch64: more ops in preparation of tlb lookup

2013-05-23 Thread Claudio Fontana

add SUBS to the arithmetic instructions and add a shift parameter to
all arithmetic instructions, so we can make use of shifted registers.

Signed-off-by: Claudio Fontana claudio.font...@huawei.com
---
 tcg/aarch64/tcg-target.c | 36 +++-
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c
index da859c7..5440659 100644
--- a/tcg/aarch64/tcg-target.c
+++ b/tcg/aarch64/tcg-target.c
@@ -190,6 +190,7 @@ enum aarch64_ldst_op_type { /* type of operation */
 enum aarch64_arith_opc {
 ARITH_ADD = 0x0b,
 ARITH_SUB = 0x4b,
+ARITH_SUBS = 0x6b,
 ARITH_AND = 0x0a,
 ARITH_OR = 0x2a,
 ARITH_XOR = 0x4a
@@ -410,12 +411,20 @@ static inline void tcg_out_st(TCGContext *s, TCGType 
type, TCGReg arg,
 }
 
 static inline void tcg_out_arith(TCGContext *s, enum aarch64_arith_opc opc,
- int ext, int rd, int rn, int rm)
+ int ext, int rd, int rn, int rm, int 
shift_imm)
 {
 /* Using shifted register arithmetic operations */
 /* if extended registry operation (64bit) just or with 0x80  24 */
-unsigned int base = ext ? (0x80 | opc)  24 : opc  24;
-tcg_out32(s, base | rm  16 | rn  5 | rd);
+unsigned int shift, base = ext ? (0x80 | opc)  24 : opc  24;
+if (shift_imm == 0) {
+shift = 0;
+} else if (shift_imm  0) {
+shift = shift_imm  10 | 1  22;
+} else /* (shift_imm  0) */ {
+shift = (-shift_imm)  10;
+}
+
+tcg_out32(s, base | rm  16 | shift | rn  5 | rd);
 }
 
 static inline void tcg_out_mul(TCGContext *s, int ext, int rd, int rn, int rm)
@@ -597,6 +606,15 @@ static inline void tcg_out_tst(TCGContext *s, int ext, int 
rn,
 tcg_out32(s, base | (pattern_n - 1)  10 | rn  5);
 }
 
+/* and a register with a bit pattern, similarly to TST, no flags change */
+static inline void tcg_out_andi(TCGContext *s, int ext, int rd,
+int rn, tcg_target_ulong pattern_n)
+{
+/* using AND 0x1200. Ext requires 4. */
+unsigned int base = ext ? 0x9240 : 0x1200;
+tcg_out32(s, base | (pattern_n - 1)  10 | rn  5);
+}
+
 static inline void tcg_out_ret(TCGContext *s)
 {
 /* emit RET { LR } */
@@ -870,27 +888,27 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
 
 case INDEX_op_add_i64: ext = 1;
 case INDEX_op_add_i32:
-tcg_out_arith(s, ARITH_ADD, ext, args[0], args[1], args[2]);
+tcg_out_arith(s, ARITH_ADD, ext, args[0], args[1], args[2], 0);
 break;
 
 case INDEX_op_sub_i64: ext = 1;
 case INDEX_op_sub_i32:
-tcg_out_arith(s, ARITH_SUB, ext, args[0], args[1], args[2]);
+tcg_out_arith(s, ARITH_SUB, ext, args[0], args[1], args[2], 0);
 break;
 
 case INDEX_op_and_i64: ext = 1;
 case INDEX_op_and_i32:
-tcg_out_arith(s, ARITH_AND, ext, args[0], args[1], args[2]);
+tcg_out_arith(s, ARITH_AND, ext, args[0], args[1], args[2], 0);
 break;
 
 case INDEX_op_or_i64: ext = 1;
 case INDEX_op_or_i32:
-tcg_out_arith(s, ARITH_OR, ext, args[0], args[1], args[2]);
+tcg_out_arith(s, ARITH_OR, ext, args[0], args[1], args[2], 0);
 break;
 
 case INDEX_op_xor_i64: ext = 1;
 case INDEX_op_xor_i32:
-tcg_out_arith(s, ARITH_XOR, ext, args[0], args[1], args[2]);
+tcg_out_arith(s, ARITH_XOR, ext, args[0], args[1], args[2], 0);
 break;
 
 case INDEX_op_mul_i64: ext = 1;
@@ -939,7 +957,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
 if (const_args[2]) {/* ROR / EXTR Wd, Wm, Wm, 32 - m */
 tcg_out_rotl(s, ext, args[0], args[1], args[2]);
 } else {
-tcg_out_arith(s, ARITH_SUB, ext, args[2], TCG_REG_XZR, args[2]);
+tcg_out_arith(s, ARITH_SUB, ext, args[2], TCG_REG_XZR, args[2], 0);
 tcg_out_shiftrot_reg(s, SRR_ROR, ext, args[0], args[1], args[2]);
 }
 break;
-- 
1.8.1





[Qemu-devel] [PATCH 2/4] tcg/aarch64: implement new TCG target for aarch64

2013-05-23 Thread Claudio Fontana

add preliminary support for TCG target aarch64.

Signed-off-by: Claudio Fontana claudio.font...@huawei.com
---
 include/exec/exec-all.h  |5 +-
 tcg/aarch64/tcg-target.c | 1185 ++
 tcg/aarch64/tcg-target.h |   99 
 translate-all.c  |2 +
 4 files changed, 1290 insertions(+), 1 deletion(-)
 create mode 100644 tcg/aarch64/tcg-target.c
 create mode 100644 tcg/aarch64/tcg-target.h

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 6362074..5c31863 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -128,7 +128,7 @@ static inline void tlb_flush(CPUArchState *env, int 
flush_global)
 
 #if defined(__arm__) || defined(_ARCH_PPC) \
 || defined(__x86_64__) || defined(__i386__) \
-|| defined(__sparc__) \
+|| defined(__sparc__) || defined(__aarch64__) \
 || defined(CONFIG_TCG_INTERPRETER)
 #define USE_DIRECT_JUMP
 #endif
@@ -230,6 +230,9 @@ static inline void tb_set_jmp_target1(uintptr_t jmp_addr, 
uintptr_t addr)
 *(uint32_t *)jmp_addr = addr - (jmp_addr + 4);
 /* no need to flush icache explicitly */
 }
+#elif defined(__aarch64__)
+void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr);
+#define tb_set_jmp_target1 aarch64_tb_set_jmp_target
 #elif defined(__arm__)
 static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr)
 {
diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c
new file mode 100644
index 000..da859c7
--- /dev/null
+++ b/tcg/aarch64/tcg-target.c
@@ -0,0 +1,1185 @@
+/*
+ * Initial TCG Implementation for aarch64
+ *
+ * Copyright (c) 2013 Huawei Technologies Duesseldorf GmbH
+ * Written by Claudio Fontana
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.
+ *
+ * See the COPYING file in the top-level directory for details.
+ */
+
+#ifdef TARGET_WORDS_BIGENDIAN
+#error Sorry, bigendian target not supported yet.
+#endif /* TARGET_WORDS_BIGENDIAN */
+
+#ifndef NDEBUG
+static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
+%x0, %x1, %x2, %x3, %x4, %x5, %x6, %x7,
+%x8, %x9, %x10, %x11, %x12, %x13, %x14, %x15,
+%x16, %x17, %x18, %x19, %x20, %x21, %x22, %x23,
+%x24, %x25, %x26, %x27, %x28,
+%fp, /* frame pointer */
+%lr, /* link register */
+%sp,  /* stack pointer */
+};
+#endif /* NDEBUG */
+
+static const int tcg_target_reg_alloc_order[] = {
+TCG_REG_X20, TCG_REG_X21, TCG_REG_X22, TCG_REG_X23,
+TCG_REG_X24, TCG_REG_X25, TCG_REG_X26, TCG_REG_X27,
+TCG_REG_X28,
+
+TCG_REG_X9, TCG_REG_X10, TCG_REG_X11, TCG_REG_X12,
+TCG_REG_X13, TCG_REG_X14, TCG_REG_X15,
+TCG_REG_X16, TCG_REG_X17,
+
+TCG_REG_X18, TCG_REG_X19, /* will not use these, see tcg_target_init */
+
+TCG_REG_X0, TCG_REG_X1, TCG_REG_X2, TCG_REG_X3,
+TCG_REG_X4, TCG_REG_X5, TCG_REG_X6, TCG_REG_X7,
+
+TCG_REG_X8, /* will not use, see tcg_target_init */
+};
+
+static const int tcg_target_call_iarg_regs[8] = {
+TCG_REG_X0, TCG_REG_X1, TCG_REG_X2, TCG_REG_X3,
+TCG_REG_X4, TCG_REG_X5, TCG_REG_X6, TCG_REG_X7
+};
+static const int tcg_target_call_oarg_regs[1] = {
+TCG_REG_X0
+};
+
+#define TCG_REG_TMP TCG_REG_X8
+
+static inline void reloc_pc26(void *code_ptr, tcg_target_long target)
+{
+tcg_target_long offset; uint32_t insn;
+offset = (target - (tcg_target_long)code_ptr) / 4;
+offset = 0x03ff;
+/* read instruction, mask away previous PC_REL26 parameter contents,
+   set the proper offset, then write back the instruction. */
+insn = *(uint32_t *)code_ptr;
+insn = (insn  0xfc00) | offset;
+*(uint32_t *)code_ptr = insn;
+}
+
+static inline void reloc_pc19(void *code_ptr, tcg_target_long target)
+{
+tcg_target_long offset; uint32_t insn;
+offset = (target - (tcg_target_long)code_ptr) / 4;
+offset = 0x07;
+/* read instruction, mask away previous PC_REL19 parameter contents,
+   set the proper offset, then write back the instruction. */
+insn = *(uint32_t *)code_ptr;
+insn = (insn  0xff1f) | offset  5; /* lower 5 bits = condition */
+*(uint32_t *)code_ptr = insn;
+}
+
+static inline void patch_reloc(uint8_t *code_ptr, int type,
+   tcg_target_long value, tcg_target_long addend)
+{
+switch (type) {
+case R_AARCH64_JUMP26:
+case R_AARCH64_CALL26:
+reloc_pc26(code_ptr, value);
+break;
+case R_AARCH64_CONDBR19:
+reloc_pc19(code_ptr, value);
+break;
+
+default:
+tcg_abort();
+}
+}
+
+/* parse target specific constraints */
+static int target_parse_constraint(TCGArgConstraint *ct,
+   const char **pct_str)
+{
+const char *ct_str = *pct_str;
+
+switch (ct_str[0]) {
+case 'r':
+ct-ct |= TCG_CT_REG;
+tcg_regset_set32(ct-u.regs, 0, (1ULL  TCG_TARGET_NB_REGS) - 1);
+break;
+case 'l': /* qemu_ld / qemu_st address, 

Re: [Qemu-devel] [PATCH] hw/9pfs: Use O_NOFOLLOW when opening files on server

2013-05-23 Thread Aneesh Kumar K.V
Stefan Hajnoczi stefa...@gmail.com writes:

 On Wed, May 22, 2013 at 04:52:54PM +0530, Aneesh Kumar K.V wrote:
 diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
 index fe8e0ed..e2a89e3 100644
 --- a/hw/9pfs/virtio-9p-handle.c
 +++ b/hw/9pfs/virtio-9p-handle.c
 @@ -608,7 +608,7 @@ static int handle_init(FsContext *ctx)
  struct file_handle fh;
  struct handle_data *data = g_malloc(sizeof(struct handle_data));
  
 -data-mountfd = open(ctx-fs_root, O_DIRECTORY);
 +data-mountfd = open(ctx-fs_root, O_DIRECTORY | O_NOFOLLOW);

 Why is the root path not allowed to be a symlink?

No specific reason. 


 And if so, it would be more user-friendly to resolve the path before
 open.  That way we don't need to bug the user with an error here.

I will drop that hunk.

-aneesh




[Qemu-devel] [PATCH 3/5] memory: do not assign node_mem[] to 0 twice

2013-05-23 Thread Wanlong Gao
We already assigned node_mem[] to 0 before add numa,
so it's unnecessary to assign twice.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 vl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/vl.c b/vl.c
index ce24bcd..b1d 100644
--- a/vl.c
+++ b/vl.c
@@ -1381,9 +1381,7 @@ static void numa_add(const char *optarg)
 exit(1);
 }
 
-if (get_param_value(option, 128, mem, optarg) == 0) {
-node_mem[nodenr] = 0;
-} else {
+if (get_param_value(option, 128, mem, optarg) != 0) {
 int64_t sval;
 sval = strtosz(option, endptr);
 if (sval  0 || *endptr) {
-- 
1.8.3.rc2.10.g0c2b1cf




[Qemu-devel] [PATCH 4/5] Add qemu_mbind interface for pinning memory to host node

2013-05-23 Thread Wanlong Gao
Add qemu_mbind() interface for pinning memory to host node
manually. Use the mbind() syscall wrapper which defined
in libnuma.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 configure| 18 ++
 include/qemu/osdep.h | 26 ++
 util/osdep.c | 15 +++
 3 files changed, 59 insertions(+)

diff --git a/configure b/configure
index 5ae7e4a..5364d01 100755
--- a/configure
+++ b/configure
@@ -3141,6 +3141,20 @@ if compile_prog   ; then
 fi
 
 ##
+# check if we have mbind
+
+mbind=no
+cat  $TMPC  EOF
+#include numaif.h
+int main(void) { return mbind(0, 0, MPOL_BIND, 0, 0, 0); }
+EOF
+if compile_prog  -lnuma; then
+mbind=yes
+LIBS=-lnuma $LIBS
+libs_qga=-lnuma $libs_qga
+fi
+
+##
 # check if we have usable SIGEV_THREAD_ID
 
 sigev_thread_id=no
@@ -3560,6 +3574,7 @@ echo preadv support$preadv
 echo fdatasync $fdatasync
 echo madvise   $madvise
 echo posix_madvise $posix_madvise
+echo mbind $mbind
 echo sigev_thread_id   $sigev_thread_id
 echo uuid support  $uuid
 echo libcap-ng support $cap_ng
@@ -3875,6 +3890,9 @@ fi
 if test $posix_madvise = yes ; then
   echo CONFIG_POSIX_MADVISE=y  $config_host_mak
 fi
+if test $mbind = yes; then
+  echo CONFIG_MBIND=y  $config_host_mak
+fi
 if test $sigev_thread_id = yes ; then
   echo CONFIG_SIGEV_THREAD_ID=y  $config_host_mak
 fi
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 57d7b1f..82a790e 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -152,6 +152,32 @@ int qemu_madvise(void *addr, size_t len, int advice);
 int qemu_open(const char *name, int flags, ...);
 int qemu_close(int fd);
 
+#define QEMU_MPOL_INVALID -1
+
+#if defined(CONFIG_MBIND)
+#include numaif.h
+/* Policies */
+#define QEMU_MPOL_DEFAULT MPOL_DEFAULT
+#define QEMU_MPOL_PREFERRED MPOL_PREFERRED
+#define QEMU_MPOL_BIND MPOL_BIND
+#define QEMU_MPOL_INTERLEAVE MPOL_INTERLEAVE
+/* Flags for qemu_mbind */
+#define QEMU_MPOL_MF_STRICT MPOL_MF_STRICT
+#define QEMU_MPOL_MF_MOVE MPOL_MF_MOVE
+#define QEMU_MPOL_MF_MOVE_ALL MPOL_MF_MOVE_ALL
+#else
+#define QEMU_MPOL_DEFAULT QEMU_MPOL_INVALID
+#define QEMU_MPOL_PREFERRED QEMU_MPOL_INVALID
+#define QEMU_MPOL_BIND QEMU_MPOL_INVALID
+#define QEMU_MPOL_INTERLEAVE QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_STRICT QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_MOVE QEMU_MPOL_INVALID
+#define QEMU_MPOL_MF_MOVE_ALL QEMU_MPOL_INVALID
+#endif
+int qemu_mbind(void *addr, unsigned long len, int mode,
+   unsigned long *nodemask, unsigned long maxnode,
+   unsigned flags);
+
 #if defined(__HAIKU__)  defined(__i386__)
 #define FMT_pid %ld
 #elif defined(WIN64)
diff --git a/util/osdep.c b/util/osdep.c
index 685c8ae..70f33c7 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -37,6 +37,10 @@
 #include sys/mman.h
 #endif
 
+#if defined(CONFIG_MBIND)
+#include numaif.h
+#endif
+
 #ifdef CONFIG_SOLARIS
 #include sys/types.h
 #include sys/statvfs.h
@@ -472,3 +476,14 @@ writev(int fd, const struct iovec *iov, int iov_cnt)
 return readv_writev(fd, iov, iov_cnt, true);
 }
 #endif
+
+int qemu_mbind(void *addr, unsigned long len, int mode,
+   unsigned long *nodemask, unsigned long maxnode,
+   unsigned flags)
+{
+#if defined(CONFIG_MBIND)
+return mbind(addr, len, mode, nodemask, maxnode, flags);
+#else
+return 0;
+#endif
+}
-- 
1.8.3.rc2.10.g0c2b1cf




[Qemu-devel] [PATCH 2/5] memory: check if the total numa memory size is equal to ram_size

2013-05-23 Thread Wanlong Gao
If the total number of the assigned numa nodes memory is not
equal to the assigned total ram size, the guest will recognize
all memory to one node.

eg:
-m 1024 -smp sockets=2,cores=1,threads=1 -numa node,cpus=0,nodeid=0,mem=512 \
-numa node,nodeid=1,cpus=1,mem=256

(qemu) info numa
2 nodes
node 0 cpus: 0
node 0 size: 512 MB
node 1 cpus: 1
node 1 size: 256 MB

$ numactl -H
avaliable: 1 nodes (0)
node 0 cpus: 0 1
node 0 size: 1023 MB
node 0 free: 821 MB
node distances:
node0
0: 10

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 vl.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/vl.c b/vl.c
index 59dc0b4..ce24bcd 100644
--- a/vl.c
+++ b/vl.c
@@ -4238,6 +4238,15 @@ int main(int argc, char **argv, char **envp)
 node_mem[i] = ram_size - usedmem;
 }
 
+uint64_t numa_total = 0;
+for (i = 0; i  nb_numa_nodes; i++)
+numa_total += node_mem[i];
+if (numa_total != ram_size) {
+fprintf(stderr, qemu: numa nodes total memory size 
+should equal ram size\n);
+exit(1);
+}
+
 for (i = 0; i  nb_numa_nodes; i++) {
 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
 break;
-- 
1.8.3.rc2.10.g0c2b1cf




[Qemu-devel] [PATCH V2 0/5] qapi and snapshot code clean up in block layer

2013-05-23 Thread Wenchao Xia
These patches are the common part of my hmp/qmp block query series and Pavel's
qmp snapshot command converion series. It mainly does following things:
1 move snapshot related code to block/snapshot.c, qmp and info dumping code to
block/qapi.c.
2 better info dumping function to get rid of buffer, avoid string truncation.

Stefan Hajnoczi (1):
  1 block: drop bs_snapshots global variable

v2:
  Squash code moving patches since they are reviewed in v1.
  Drop bdrv_snapshot_find() function change patch, since it related to snapshot
logic which should be changed together with Pavel's serial.
  Use a parameter in message_printf() to tell where to print, instead of use
global variable cur_mon inside.

Wenchao Xia (4):
  2 block: move snapshot code in block.c to block/snapshot.c
  3 block: move qmp and info dump related code to block/qapi.c
  4 util: add new function message_printf()
  5 block: dump to specified output for bdrv_snapshot_dump() and 
bdrv_image_info_dump()

 block.c |  318 -
 block/Makefile.objs |1 +
 block/qapi.c|  365 +++
 block/snapshot.c|  162 +++
 include/block/block.h   |   29 +
 include/block/block_int.h   |1 +
 include/block/qapi.h|   42 +
 include/block/snapshot.h|   54 +++
 include/qemu/error-report.h |   13 ++
 qemu-img.c  |  169 ++---
 savevm.c|   44 +++---
 util/qemu-error.c   |   28 +++-
 12 files changed, 697 insertions(+), 529 deletions(-)
 create mode 100644 block/qapi.c
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/qapi.h
 create mode 100644 include/block/snapshot.h





[Qemu-devel] [PATCH V2 3/5] block: move qmp and info dump related code to block/qapi.c

2013-05-23 Thread Wenchao Xia
This patch is a pure code move patch, except following modification:
1 get_human_readable_size() is changed to static function.
2 dump_human_image_info() is renamed to bdrv_image_info_dump().
3 in qmp_query_block() and qmp_query_blockstats, use bdrv_next(bs)
instead of direct traverse of global array 'bdrv_states'.
4 code style fix.

To avoid conflict and tip better, macro in header file is BLOCK_QAPI_H
instead of QAPI_H. Now block.h and snapshot.h are at the same level in
include path, block_int.h and qapi.h will both include them.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 block.c   |  185 ---
 block/Makefile.objs   |2 +-
 block/qapi.c  |  360 +
 include/block/block.h |   10 --
 include/block/block_int.h |1 +
 include/block/qapi.h  |   41 +
 qemu-img.c|  156 +---
 savevm.c  |1 +
 8 files changed, 408 insertions(+), 348 deletions(-)
 create mode 100644 block/qapi.c
 create mode 100644 include/block/qapi.h

diff --git a/block.c b/block.c
index 2561800..ca28c0d 100644
--- a/block.c
+++ b/block.c
@@ -3089,128 +3089,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, 
BlockDriverState *base,
 return data.ret;
 }
 
-BlockInfo *bdrv_query_info(BlockDriverState *bs)
-{
-BlockInfo *info = g_malloc0(sizeof(*info));
-info-device = g_strdup(bs-device_name);
-info-type = g_strdup(unknown);
-info-locked = bdrv_dev_is_medium_locked(bs);
-info-removable = bdrv_dev_has_removable_media(bs);
-
-if (bdrv_dev_has_removable_media(bs)) {
-info-has_tray_open = true;
-info-tray_open = bdrv_dev_is_tray_open(bs);
-}
-
-if (bdrv_iostatus_is_enabled(bs)) {
-info-has_io_status = true;
-info-io_status = bs-iostatus;
-}
-
-if (bs-dirty_bitmap) {
-info-has_dirty = true;
-info-dirty = g_malloc0(sizeof(*info-dirty));
-info-dirty-count = bdrv_get_dirty_count(bs) * BDRV_SECTOR_SIZE;
-info-dirty-granularity =
-((int64_t) BDRV_SECTOR_SIZE  
hbitmap_granularity(bs-dirty_bitmap));
-}
-
-if (bs-drv) {
-info-has_inserted = true;
-info-inserted = g_malloc0(sizeof(*info-inserted));
-info-inserted-file = g_strdup(bs-filename);
-info-inserted-ro = bs-read_only;
-info-inserted-drv = g_strdup(bs-drv-format_name);
-info-inserted-encrypted = bs-encrypted;
-info-inserted-encryption_key_missing = bdrv_key_required(bs);
-
-if (bs-backing_file[0]) {
-info-inserted-has_backing_file = true;
-info-inserted-backing_file = g_strdup(bs-backing_file);
-}
-
-info-inserted-backing_file_depth = bdrv_get_backing_file_depth(bs);
-
-if (bs-io_limits_enabled) {
-info-inserted-bps =
-   bs-io_limits.bps[BLOCK_IO_LIMIT_TOTAL];
-info-inserted-bps_rd =
-   bs-io_limits.bps[BLOCK_IO_LIMIT_READ];
-info-inserted-bps_wr =
-   bs-io_limits.bps[BLOCK_IO_LIMIT_WRITE];
-info-inserted-iops =
-   bs-io_limits.iops[BLOCK_IO_LIMIT_TOTAL];
-info-inserted-iops_rd =
-   bs-io_limits.iops[BLOCK_IO_LIMIT_READ];
-info-inserted-iops_wr =
-   bs-io_limits.iops[BLOCK_IO_LIMIT_WRITE];
-}
-}
-return info;
-}
-
-BlockInfoList *qmp_query_block(Error **errp)
-{
-BlockInfoList *head = NULL, **p_next = head;
-BlockDriverState *bs;
-
-QTAILQ_FOREACH(bs, bdrv_states, list) {
-BlockInfoList *info = g_malloc0(sizeof(*info));
-info-value = bdrv_query_info(bs);
-
-*p_next = info;
-p_next = info-next;
-}
-
-return head;
-}
-
-BlockStats *bdrv_query_stats(const BlockDriverState *bs)
-{
-BlockStats *s;
-
-s = g_malloc0(sizeof(*s));
-
-if (bs-device_name[0]) {
-s-has_device = true;
-s-device = g_strdup(bs-device_name);
-}
-
-s-stats = g_malloc0(sizeof(*s-stats));
-s-stats-rd_bytes = bs-nr_bytes[BDRV_ACCT_READ];
-s-stats-wr_bytes = bs-nr_bytes[BDRV_ACCT_WRITE];
-s-stats-rd_operations = bs-nr_ops[BDRV_ACCT_READ];
-s-stats-wr_operations = bs-nr_ops[BDRV_ACCT_WRITE];
-s-stats-wr_highest_offset = bs-wr_highest_sector * BDRV_SECTOR_SIZE;
-s-stats-flush_operations = bs-nr_ops[BDRV_ACCT_FLUSH];
-s-stats-wr_total_time_ns = bs-total_time_ns[BDRV_ACCT_WRITE];
-s-stats-rd_total_time_ns = bs-total_time_ns[BDRV_ACCT_READ];
-s-stats-flush_total_time_ns = bs-total_time_ns[BDRV_ACCT_FLUSH];
-
-if (bs-file) {
-s-has_parent = true;
-s-parent = bdrv_query_stats(bs-file);
-}
-
-return s;
-}
-
-BlockStatsList *qmp_query_blockstats(Error **errp)
-{
-BlockStatsList *head = NULL, **p_next = 

[Qemu-devel] [PATCH V2 4/5] util: add new function message_printf()

2013-05-23 Thread Wenchao Xia
This function takes an input parameter *output, which can be specified by
caller as stderr, stdout or a monitor. error_vprintf() now calls 
message_vprintf(),
which is a static function added in this patch.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 include/qemu/error-report.h |   13 +
 util/qemu-error.c   |   28 ++--
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index c902cc1..cdde78b 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -14,6 +14,8 @@
 #define QEMU_ERROR_H
 
 #include stdarg.h
+#include stdio.h
+#include qemu/typedefs.h
 
 typedef struct Location {
 /* all members are private to qemu-error.c */
@@ -32,6 +34,17 @@ void loc_set_none(void);
 void loc_set_cmdline(char **argv, int idx, int cnt);
 void loc_set_file(const char *fname, int lno);
 
+typedef struct QemuOutput {
+enum { OUTPUT_STREAM, OUTPUT_MONITOR } kind;
+union {
+FILE *stream;
+Monitor *monitor;
+};
+} QemuOutput;
+
+void message_printf(const QemuOutput *output, const char *fmt, ...)
+GCC_FMT_ATTR(2, 3);
+
 void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 08a36f4..c7ff0a8 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -13,6 +13,25 @@
 #include stdio.h
 #include monitor/monitor.h
 
+static GCC_FMT_ATTR(2, 0)
+void message_vprintf(const QemuOutput *output, const char *fmt, va_list ap)
+{
+if (output-kind == OUTPUT_STREAM) {
+vfprintf(output-stream, fmt, ap);
+} else if (output-kind == OUTPUT_MONITOR) {
+monitor_vprintf(output-monitor, fmt, ap);
+}
+}
+
+void message_printf(const QemuOutput *output, const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+message_vprintf(output, fmt, ap);
+va_end(ap);
+}
+
 /*
  * Print to current monitor if we have one, else to stderr.
  * TODO should return int, so callers can calculate width, but that
@@ -20,11 +39,16 @@
  */
 void error_vprintf(const char *fmt, va_list ap)
 {
+QemuOutput output;
+
 if (cur_mon) {
-monitor_vprintf(cur_mon, fmt, ap);
+output.kind = OUTPUT_MONITOR;
+output.monitor = cur_mon;
 } else {
-vfprintf(stderr, fmt, ap);
+output.kind = OUTPUT_STREAM;
+output.stream = stderr;
 }
+message_vprintf(output, fmt, ap);
 }
 
 /*
-- 
1.7.1





[Qemu-devel] [PATCH 5/5] memory: able to pin guest node memory to host node manually

2013-05-23 Thread Wanlong Gao
Use mbind to pin guest numa node memory to host nodes manually.

If we are not able to pin memory to host node, we may meet the
cross node memory access performance regression.

With this patch, we can add manual pinning host node like this:
-m 1024 -numa node,cpus=0,nodeid=0,mem=512,pin=0 -numa 
node,nodeid=1,cpus=1,mem=512,pin=1

And, if PCI-passthrough is used, direct-attached-device uses DMA transfer
between device and qemu process. All pages of the guest will be pinned by 
get_user_pages().

KVM_ASSIGN_PCI_DEVICE ioctl
  kvm_vm_ioctl_assign_device()
=kvm_assign_device()
  = kvm_iommu_map_memslots()
= kvm_iommu_map_pages()
   = kvm_pin_pages()

So, with direct-attached-device, all guest page's page count will be +1 and
any page migration will not work. AutoNUMA won't too. And direction by libvirt 
is *ignored*.

Above all, we need manual pinning memory to host node to avoid
such cross nodes memmory access performance regression.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 exec.c  | 21 +
 include/sysemu/sysemu.h |  1 +
 vl.c| 13 +
 3 files changed, 35 insertions(+)

diff --git a/exec.c b/exec.c
index aec65c5..fe929ef 100644
--- a/exec.c
+++ b/exec.c
@@ -36,6 +36,8 @@
 #include qemu/config-file.h
 #include exec/memory.h
 #include sysemu/dma.h
+#include sysemu/sysemu.h
+#include qemu/bitops.h
 #include exec/address-spaces.h
 #if defined(CONFIG_USER_ONLY)
 #include qemu.h
@@ -1081,6 +1083,25 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
 memory_try_enable_merging(new_block-host, size);
 }
 }
+
+if (nb_numa_nodes  0  !strcmp(mr-name, pc.ram)) {
+int i;
+uint64_t nodes_mem = 0;
+unsigned long *maskp = g_malloc0(sizeof(*maskp));
+for (i = 0; i  nb_numa_nodes; i++) {
+*maskp = 0;
+if (node_pin[i] != -1) {
+set_bit(node_pin[i], maskp);
+if (qemu_mbind(new_block-host + nodes_mem, node_mem[i],
+   QEMU_MPOL_BIND, maskp, MAX_NODES, 0)) {
+perror(qemu_mbind);
+exit(1);
+}
+}
+nodes_mem += node_mem[i];
+}
+}
+
 new_block-length = size;
 
 /* Keep the list sorted from biggest to smallest block.  */
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 2fb71af..ebf6580 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -131,6 +131,7 @@ extern QEMUClock *rtc_clock;
 #define MAX_CPUMASK_BITS 255
 extern int nb_numa_nodes;
 extern uint64_t node_mem[MAX_NODES];
+extern int node_pin[MAX_NODES];
 extern unsigned long *node_cpumask[MAX_NODES];
 
 #define MAX_OPTION_ROMS 16
diff --git a/vl.c b/vl.c
index b1d..3768002 100644
--- a/vl.c
+++ b/vl.c
@@ -253,6 +253,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
 
 int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
+int node_pin[MAX_NODES];
 unsigned long *node_cpumask[MAX_NODES];
 
 uint8_t qemu_uuid[16];
@@ -1390,6 +1391,17 @@ static void numa_add(const char *optarg)
 }
 node_mem[nodenr] = sval;
 }
+
+if (get_param_value(option, 128, pin, optarg) != 0) {
+int unsigned long long pin_node;
+if (parse_uint_full(option, pin_node, 10)  0) {
+fprintf(stderr, qemu: Invalid pinning nodeid: %s\n, optarg);
+exit(1);
+} else {
+node_pin[nodenr] = pin_node;
+}
+}
+
 if (get_param_value(option, 128, cpus, optarg) != 0) {
 numa_node_parse_cpus(nodenr, option);
 }
@@ -2921,6 +2933,7 @@ int main(int argc, char **argv, char **envp)
 
 for (i = 0; i  MAX_NODES; i++) {
 node_mem[i] = 0;
+node_pin[i] = -1;
 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
 }
 
-- 
1.8.3.rc2.10.g0c2b1cf




[Qemu-devel] [PATCH V2 5/5] block: dump to specified output for bdrv_snapshot_dump() and bdrv_image_info_dump()

2013-05-23 Thread Wenchao Xia
Buffer is not used now so the string would not be truncated any more. They can 
be used
by both qemu and qemu-img with correct parameter specified.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block/qapi.c |   65 +++---
 include/block/qapi.h |5 ++-
 qemu-img.c   |   15 +++
 savevm.c |   11 ++--
 4 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/block/qapi.c b/block/qapi.c
index 155e77e..2e083f8 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -259,7 +259,7 @@ static char *get_human_readable_size(char *buf, int 
buf_size, int64_t size)
 return buf;
 }
 
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
+void bdrv_snapshot_dump(const QemuOutput *output, QEMUSnapshotInfo *sn)
 {
 char buf1[128], date_buf[128], clock_buf[128];
 struct tm tm;
@@ -267,9 +267,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, 
QEMUSnapshotInfo *sn)
 int64_t secs;
 
 if (!sn) {
-snprintf(buf, buf_size,
- %-10s%-20s%7s%20s%15s,
- ID, TAG, VM SIZE, DATE, VM CLOCK);
+message_printf(output,
+   %-10s%-20s%7s%20s%15s,
+   ID, TAG, VM SIZE, DATE, VM CLOCK);
 } else {
 ti = sn-date_sec;
 localtime_r(ti, tm);
@@ -282,17 +282,17 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, 
QEMUSnapshotInfo *sn)
  (int)((secs / 60) % 60),
  (int)(secs % 60),
  (int)((sn-vm_clock_nsec / 100) % 1000));
-snprintf(buf, buf_size,
- %-10s%-20s%7s%20s%15s,
- sn-id_str, sn-name,
- get_human_readable_size(buf1, sizeof(buf1), 
sn-vm_state_size),
- date_buf,
- clock_buf);
+message_printf(output,
+   %-10s%-20s%7s%20s%15s,
+   sn-id_str, sn-name,
+   get_human_readable_size(buf1, sizeof(buf1),
+   sn-vm_state_size),
+   date_buf,
+   clock_buf);
 }
-return buf;
 }
 
-void bdrv_image_info_dump(ImageInfo *info)
+void bdrv_image_info_dump(const QemuOutput *output, ImageInfo *info)
 {
 char size_buf[128], dsize_buf[128];
 if (!info-has_actual_size) {
@@ -302,43 +302,47 @@ void bdrv_image_info_dump(ImageInfo *info)
 info-actual_size);
 }
 get_human_readable_size(size_buf, sizeof(size_buf), info-virtual_size);
-printf(image: %s\n
-   file format: %s\n
-   virtual size: %s (% PRId64  bytes)\n
-   disk size: %s\n,
-   info-filename, info-format, size_buf,
-   info-virtual_size,
-   dsize_buf);
+message_printf(output,
+   image: %s\n
+   file format: %s\n
+   virtual size: %s (% PRId64  bytes)\n
+   disk size: %s\n,
+   info-filename, info-format, size_buf,
+   info-virtual_size,
+   dsize_buf);
 
 if (info-has_encrypted  info-encrypted) {
-printf(encrypted: yes\n);
+message_printf(output, encrypted: yes\n);
 }
 
 if (info-has_cluster_size) {
-printf(cluster_size: % PRId64 \n, info-cluster_size);
+message_printf(output, cluster_size: % PRId64 \n,
+   info-cluster_size);
 }
 
 if (info-has_dirty_flag  info-dirty_flag) {
-printf(cleanly shut down: no\n);
+message_printf(output, cleanly shut down: no\n);
 }
 
 if (info-has_backing_filename) {
-printf(backing file: %s, info-backing_filename);
+message_printf(output, backing file: %s, info-backing_filename);
 if (info-has_full_backing_filename) {
-printf( (actual path: %s), info-full_backing_filename);
+message_printf(output,  (actual path: %s),
+   info-full_backing_filename);
 }
-putchar('\n');
+message_printf(output, \n);
 if (info-has_backing_filename_format) {
-printf(backing file format: %s\n, info-backing_filename_format);
+message_printf(output, backing file format: %s\n,
+   info-backing_filename_format);
 }
 }
 
 if (info-has_snapshots) {
 SnapshotInfoList *elem;
-char buf[256];
 
-printf(Snapshot list:\n);
-printf(%s\n, bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+message_printf(output, Snapshot list:\n);
+bdrv_snapshot_dump(output, NULL);
+message_printf(output, \n);
 
 /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
  * we convert to the block layer's native QEMUSnapshotInfo for now.
@@ -354,7 +358,8 @@ void bdrv_image_info_dump(ImageInfo *info)
 
 pstrcpy(sn.id_str, 

[Qemu-devel] updated: kvm networking todo wiki

2013-05-23 Thread Michael S. Tsirkin
Hey guys,
I've updated the kvm networking todo wiki with current projects.
Will try to keep it up to date more often.
Original announcement below.



I've put up a wiki page with a kvm networking todo list,
mainly to avoid effort duplication, but also in the hope
to draw attention to what I think we should try addressing
in KVM:

http://www.linux-kvm.org/page/NetworkingTodo

This page could cover all networking related activity in KVM,
currently most info is related to virtio-net.

Note: if there's no developer listed for an item,
this just means I don't know of anyone actively working
on an issue at the moment, not that no one intends to.

I would appreciate it if others working on one of the items on this list
would add their names so we can communicate better.  If others like this
wiki page, please go ahead and add stuff you are working on if any.

It would be especially nice to add autotest projects:
there is just a short test matrix and a catch-all
'Cover test matrix with autotest', currently.

Currently there are some links to Red Hat bugzilla entries,
feel free to add links to other bugzillas.

Thanks!

-- 
MST



[Qemu-devel] [PATCH V2 1/5] block: drop bs_snapshots global variable

2013-05-23 Thread Wenchao Xia
From: Stefan Hajnoczi stefa...@redhat.com

The bs_snapshots global variable points to the BlockDriverState which
will be used to save vmstate.  This is really a savevm.c concept but was
moved into block.c:bdrv_snapshots() when it became clear that hotplug
could result in a dangling pointer.

While auditing the block layer's global state I came upon bs_snapshots
and realized that a variable is not necessary here.  Simply find the
first BlockDriverState capable of internal snapshots each time this is
needed.

The behavior of bdrv_snapshots() is preserved across hotplug because new
drives are always appended to the bdrv_states list.  This means that
calling the new find_vmstate_bs() function is idempotent - it returns
the same BlockDriverState unless it was hot-unplugged.

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
Reviewed-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c   |   28 
 include/block/block.h |1 -
 savevm.c  |   19 +++
 3 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/block.c b/block.c
index 3f87489..478a3b2 100644
--- a/block.c
+++ b/block.c
@@ -99,9 +99,6 @@ static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
 static QLIST_HEAD(, BlockDriver) bdrv_drivers =
 QLIST_HEAD_INITIALIZER(bdrv_drivers);
 
-/* The device to use for VM snapshots */
-static BlockDriverState *bs_snapshots;
-
 /* If non-zero, use only whitelisted block drivers */
 static int use_bdrv_whitelist;
 
@@ -1357,9 +1354,6 @@ void bdrv_close(BlockDriverState *bs)
 notifier_list_notify(bs-close_notifiers, bs);
 
 if (bs-drv) {
-if (bs == bs_snapshots) {
-bs_snapshots = NULL;
-}
 if (bs-backing_hd) {
 bdrv_delete(bs-backing_hd);
 bs-backing_hd = NULL;
@@ -1591,7 +1585,6 @@ void bdrv_delete(BlockDriverState *bs)
 
 bdrv_close(bs);
 
-assert(bs != bs_snapshots);
 g_free(bs);
 }
 
@@ -1635,9 +1628,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const 
BlockDevOps *ops,
 {
 bs-dev_ops = ops;
 bs-dev_opaque = opaque;
-if (bdrv_dev_has_removable_media(bs)  bs == bs_snapshots) {
-bs_snapshots = NULL;
-}
 }
 
 void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
@@ -3381,24 +3371,6 @@ int bdrv_is_snapshot(BlockDriverState *bs)
 return !!(bs-open_flags  BDRV_O_SNAPSHOT);
 }
 
-BlockDriverState *bdrv_snapshots(void)
-{
-BlockDriverState *bs;
-
-if (bs_snapshots) {
-return bs_snapshots;
-}
-
-bs = NULL;
-while ((bs = bdrv_next(bs))) {
-if (bdrv_can_snapshot(bs)) {
-bs_snapshots = bs;
-return bs;
-}
-}
-return NULL;
-}
-
 int bdrv_snapshot_create(BlockDriverState *bs,
  QEMUSnapshotInfo *sn_info)
 {
diff --git a/include/block/block.h b/include/block/block.h
index 1251c5c..38263b9 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -332,7 +332,6 @@ BlockInfo *bdrv_query_info(BlockDriverState *s);
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
 int bdrv_can_snapshot(BlockDriverState *bs);
 int bdrv_is_snapshot(BlockDriverState *bs);
-BlockDriverState *bdrv_snapshots(void);
 int bdrv_snapshot_create(BlockDriverState *bs,
  QEMUSnapshotInfo *sn_info);
 int bdrv_snapshot_goto(BlockDriverState *bs,
diff --git a/savevm.c b/savevm.c
index 31dcce9..baa1a09 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2262,6 +2262,17 @@ out:
 return ret;
 }
 
+static BlockDriverState *find_vmstate_bs(void)
+{
+BlockDriverState *bs = NULL;
+while ((bs = bdrv_next(bs))) {
+if (bdrv_can_snapshot(bs)) {
+return bs;
+}
+}
+return NULL;
+}
+
 static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
   const char *name)
 {
@@ -2338,7 +2349,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
 }
 }
 
-bs = bdrv_snapshots();
+bs = find_vmstate_bs();
 if (!bs) {
 monitor_printf(mon, No block device can accept snapshots\n);
 return;
@@ -2440,7 +2451,7 @@ int load_vmstate(const char *name)
 QEMUFile *f;
 int ret;
 
-bs_vm_state = bdrv_snapshots();
+bs_vm_state = find_vmstate_bs();
 if (!bs_vm_state) {
 error_report(No block device supports snapshots);
 return -ENOTSUP;
@@ -2519,7 +2530,7 @@ void do_delvm(Monitor *mon, const QDict *qdict)
 int ret;
 const char *name = qdict_get_str(qdict, name);
 
-bs = bdrv_snapshots();
+bs = find_vmstate_bs();
 if (!bs) {
 monitor_printf(mon, No block device supports snapshots\n);
 return;
@@ -2551,7 +2562,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
 int *available_snapshots;
 char buf[256];
 
-bs = bdrv_snapshots();
+bs = find_vmstate_bs();
 if 

Re: [Qemu-devel] [PATCH 1/2] target-i386/seg_helper: refactor 4 helper functions

2013-05-23 Thread li guang
ping ... again.

在 2013-04-22一的 11:44 +0800,liguang写道:
 for helper_{lsl, lar, verr, verw}, there are
 common parts, so move them outside, and then
 call this new helper-helper function.
 
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  target-i386/seg_helper.c |  179 ++---
  1 files changed, 56 insertions(+), 123 deletions(-)
 
 diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
 index 906e4f3..419efd8 100644
 --- a/target-i386/seg_helper.c
 +++ b/target-i386/seg_helper.c
 @@ -2292,9 +2292,10 @@ void helper_sysexit(CPUX86State *env, int dflag)
  EIP = EDX;
  }
  
 -target_ulong helper_lsl(CPUX86State *env, target_ulong selector1)
 +
 +static target_ulong misc_check_helper(CPUX86State *env, target_ulong 
 selector1,
 +  int inst)
  {
 -unsigned int limit;
  uint32_t e1, e2, eflags, selector;
  int rpl, dpl, cpl, type;
  
 @@ -2306,14 +2307,30 @@ target_ulong helper_lsl(CPUX86State *env, 
 target_ulong selector1)
  if (load_segment(env, e1, e2, selector) != 0) {
  goto fail;
  }
 +
 +CC_SRC = eflags  ~CC_Z;
 +
  rpl = selector  3;
  dpl = (e2  DESC_DPL_SHIFT)  3;
  cpl = env-hflags  HF_CPL_MASK;
 +
  if (e2  DESC_S_MASK) {
 -if ((e2  DESC_CS_MASK)  (e2  DESC_C_MASK)) {
 -/* conforming */
 -} else {
 -if (dpl  cpl || dpl  rpl) {
 +if (e2  DESC_CS_MASK) {
 +switch (inst) {
 +case 1:
 +goto fail;
 +case 2:
 +if (!(e2  (DESC_R_MASK | DESC_C_MASK))) {
 +goto fail;
 +}
 +break;
 +case 3:
 +case 4:
 +if (!(e2  DESC_C_MASK)) {
 +goto check_pl;
 +}
 +break;
 +default:
  goto fail;
  }
  }
 @@ -2325,140 +2342,56 @@ target_ulong helper_lsl(CPUX86State *env, 
 target_ulong selector1)
  case 3:
  case 9:
  case 11:
 -break;
 +if (inst == 3) {
 +break;
 +}
 +case 5:
 +case 12:
 +if (inst == 4) {
 +break;
 +}
  default:
  goto fail;
  }
 -if (dpl  cpl || dpl  rpl) {
 -fail:
 -CC_SRC = eflags  ~CC_Z;
 -return 0;
 -}
 +goto check_pl;
 +}
 +
 +if (inst == 3) {
 +e2 = 0x00f0ff00;
  }
 -limit = get_seg_limit(e1, e2);
 +if (inst == 4) {
 +e2 = get_seg_limit(e1, e2);
 +}
 +
  CC_SRC = eflags | CC_Z;
 -return limit;
 +
 +check_pl:
 +if (dpl  cpl || dpl  rpl) {
 +goto fail;
 +}
 +
 +fail:
 +return e2;
  }
  
 -target_ulong helper_lar(CPUX86State *env, target_ulong selector1)
 +target_ulong helper_lsl(CPUX86State *env, target_ulong selector1)
  {
 -uint32_t e1, e2, eflags, selector;
 -int rpl, dpl, cpl, type;
 +return misc_check_helper(env, selector1, 4);
 +}
  
 -selector = selector1  0x;
 -eflags = cpu_cc_compute_all(env, CC_OP);
 -if ((selector  0xfffc) == 0) {
 -goto fail;
 -}
 -if (load_segment(env, e1, e2, selector) != 0) {
 -goto fail;
 -}
 -rpl = selector  3;
 -dpl = (e2  DESC_DPL_SHIFT)  3;
 -cpl = env-hflags  HF_CPL_MASK;
 -if (e2  DESC_S_MASK) {
 -if ((e2  DESC_CS_MASK)  (e2  DESC_C_MASK)) {
 -/* conforming */
 -} else {
 -if (dpl  cpl || dpl  rpl) {
 -goto fail;
 -}
 -}
 -} else {
 -type = (e2  DESC_TYPE_SHIFT)  0xf;
 -switch (type) {
 -case 1:
 -case 2:
 -case 3:
 -case 4:
 -case 5:
 -case 9:
 -case 11:
 -case 12:
 -break;
 -default:
 -goto fail;
 -}
 -if (dpl  cpl || dpl  rpl) {
 -fail:
 -CC_SRC = eflags  ~CC_Z;
 -return 0;
 -}
 -}
 -CC_SRC = eflags | CC_Z;
 -return e2  0x00f0ff00;
 +target_ulong helper_lar(CPUX86State *env, target_ulong selector1)
 +{
 +return misc_check_helper(env, selector1, 3);
  }
  
  void helper_verr(CPUX86State *env, target_ulong selector1)
  {
 -uint32_t e1, e2, eflags, selector;
 -int rpl, dpl, cpl;
 -
 -selector = selector1  0x;
 -eflags = cpu_cc_compute_all(env, CC_OP);
 -if ((selector  0xfffc) == 0) {
 -goto fail;
 -}
 -if (load_segment(env, e1, e2, selector) != 0) {
 -goto fail;
 -}
 -if (!(e2  DESC_S_MASK)) {
 -goto fail;
 -}
 -rpl = selector  3;
 -dpl = (e2  DESC_DPL_SHIFT)  3;
 -cpl = env-hflags  HF_CPL_MASK;
 -if (e2  DESC_CS_MASK) {
 -if (!(e2  DESC_R_MASK)) {
 -goto fail;
 -}
 -if (!(e2  DESC_C_MASK)) {
 -   

[Qemu-devel] [PATCH v3 0/2] mac programming over macvtap

2013-05-23 Thread Amos Kong
This patchset introduces a QMP event and a monitor command.
The event is used to notify management when rx-filter
configuration is changed by guest. Management can use the
new monitor command to query rx-filter information, and
sync the changes to macvtap devices.

There maybe exist an uncontrollable delay, guests normally expect
rx-mode updates immediately, but it's another separate issue, we
can investigate it after Libvirt work is done.

Patches are based on Michael's patchset [1], you can also find patches
in my github [2].

[1] [PATCH v3 00/11] qapi: add support for lists of native types
[2] https://github.com/kongove/qemu/tree/01-query-rxfilter

v2: add argument to filter mac-table info of single nic (Stefan)
update the document
add event notification
V3: rename to rx-filter, add main mac, avoid event flooding (MST)
fix error process (Stefan)
fix qmp interface (Eric)

Amos Kong (2):
  net: introduce RX_FILTER_CHANGED event
  net: introduce command to query rx-filter information

 QMP/qmp-events.txt| 14 +++
 hmp-commands.hx   |  2 +
 hmp.c | 49 +
 hmp.h |  1 +
 hw/net/virtio-net.c   | 93 +++
 include/monitor/monitor.h |  1 +
 include/net/net.h |  2 +
 monitor.c |  9 +
 net/net.c | 47 
 qapi-schema.json  | 73 +
 qmp-commands.hx   | 55 
 11 files changed, 346 insertions(+)

-- 
1.8.1.4




[Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event

2013-05-23 Thread Amos Kong
Introduce this new QMP event to notify management after guest changes
rx-filter configuration.

Signed-off-by: Amos Kong ak...@redhat.com
---
 QMP/qmp-events.txt| 14 ++
 include/monitor/monitor.h |  1 +
 monitor.c |  1 +
 3 files changed, 16 insertions(+)

diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 92fe5fb..ad6612b 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -154,6 +154,20 @@ Data:
 path: /machine/peripheral/virtio-net-pci-0 },
   timestamp: { seconds: 1265044230, microseconds: 450486 } }
 
+RX_FILTER_CHANGED
+-
+
+Emitted when rx-filter configuration is changed by the guest.
+
+Data:
+
+- name: net client name (json-string)
+
+{ event: RX_FILTER_CHANGED,
+  data: { name: vnet0 },
+  timestamp: { seconds: 1368697518, microseconds: 326866 }}
+}
+
 DEVICE_TRAY_MOVED
 -
 
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1a6cfcf..c495a67 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -40,6 +40,7 @@ typedef enum MonitorEvent {
 QEVENT_BLOCK_JOB_ERROR,
 QEVENT_BLOCK_JOB_READY,
 QEVENT_DEVICE_DELETED,
+QEVENT_RX_FILTER_CHANGED,
 QEVENT_DEVICE_TRAY_MOVED,
 QEVENT_SUSPEND,
 QEVENT_SUSPEND_DISK,
diff --git a/monitor.c b/monitor.c
index 6ce2a4e..4f7bd48 100644
--- a/monitor.c
+++ b/monitor.c
@@ -489,6 +489,7 @@ static const char *monitor_event_names[] = {
 [QEVENT_BLOCK_JOB_ERROR] = BLOCK_JOB_ERROR,
 [QEVENT_BLOCK_JOB_READY] = BLOCK_JOB_READY,
 [QEVENT_DEVICE_DELETED] = DEVICE_DELETED,
+[QEVENT_RX_FILTER_CHANGED] = RX_FILTER_CHANGED,
 [QEVENT_DEVICE_TRAY_MOVED] = DEVICE_TRAY_MOVED,
 [QEVENT_SUSPEND] = SUSPEND,
 [QEVENT_SUSPEND_DISK] = SUSPEND_DISK,
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information

2013-05-23 Thread Amos Kong
We want to implement mac programming over macvtap through Libvirt,
related rx-filter configuration contains main mac, some of rx-mode
and mac-table.

The previous patch adds QMP event to notify management of rx-filter
change. This patch adds a monitor command to query rx-filter
information.

A flag is used to avoid events flooding, if user don't query
rx-filter after receives one event, new events won't be sent
to qmp monitor.

(qemu) info rx-filter vnet0
vnet0:
 \ promiscuous: on
 \ multicast: normal
 \ unicast: normal
 \ broadcast-allowed: off
 \ multicast-overflow: off
 \ unicast-overflow: off
 \ main-mac: 52:54:00:12:34:56
 \ unicast-table:
 \ multicast-table:
01:00:5e:00:00:01
33:33:00:00:00:01
33:33:ff:12:34:56

Signed-off-by: Amos Kong ak...@redhat.com
---
 hmp-commands.hx |  2 ++
 hmp.c   | 49 
 hmp.h   |  1 +
 hw/net/virtio-net.c | 93 +
 include/net/net.h   |  2 ++
 monitor.c   |  8 +
 net/net.c   | 47 +++
 qapi-schema.json| 73 +
 qmp-commands.hx | 55 +++
 9 files changed, 330 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 9cea415..b7863eb 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1639,6 +1639,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info rx-filter [net client name]
+show the rx-filter information for all nics (or for the given nic)
 @end table
 ETEXI
 
diff --git a/hmp.c b/hmp.c
index 4fb76ec..5b47382 100644
--- a/hmp.c
+++ b/hmp.c
@@ -653,6 +653,55 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
 qapi_free_TPMInfoList(info_list);
 }
 
+void hmp_info_rx_filter(Monitor *mon, const QDict *qdict)
+{
+RxFilterInfoList *filter_list, *entry;
+strList *str_entry;
+bool has_name = qdict_haskey(qdict, name);
+const char *name = NULL;
+
+if (has_name) {
+name = qdict_get_str(qdict, name);
+}
+
+filter_list = qmp_query_rx_filter(has_name, name, NULL);
+entry = filter_list;
+
+while (entry) {
+monitor_printf(mon, %s:\n, entry-value-name);
+monitor_printf(mon,  \\ promiscuous: %s\n,
+   entry-value-promiscuous ? on : off);
+monitor_printf(mon,  \\ multicast: %s\n,
+   RxState_lookup[entry-value-multicast]);
+monitor_printf(mon,  \\ unicast: %s\n,
+   RxState_lookup[entry-value-unicast]);
+monitor_printf(mon,  \\ broadcast-allowed: %s\n,
+   entry-value-broadcast_allowed ? on : off);
+monitor_printf(mon,  \\ multicast-overflow: %s\n,
+   entry-value-multicast_overflow ? on : off);
+monitor_printf(mon,  \\ unicast-overflow: %s\n,
+   entry-value-unicast_overflow ? on : off);
+monitor_printf(mon,  \\ main-mac: %s\n, entry-value-main_mac);
+
+str_entry = entry-value-unicast_table;
+monitor_printf(mon,  \\ unicast-table:\n);
+while (str_entry) {
+monitor_printf(mon, %s\n, str_entry-value);
+str_entry = str_entry-next;
+}
+
+str_entry = entry-value-multicast_table;
+monitor_printf(mon,  \\ multicast-table:\n);
+while (str_entry) {
+monitor_printf(mon, %s\n, str_entry-value);
+str_entry = str_entry-next;
+}
+
+entry = entry-next;
+}
+qapi_free_RxFilterInfoList(filter_list);
+}
+
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
 monitor_suspend(mon);
diff --git a/hmp.h b/hmp.h
index 95fe76e..9af733e 100644
--- a/hmp.h
+++ b/hmp.h
@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_tpm(Monitor *mon, const QDict *qdict);
+void hmp_info_rx_filter(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1ea9556..f93e021 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -21,6 +21,8 @@
 #include hw/virtio/virtio-net.h
 #include net/vhost_net.h
 #include hw/virtio/virtio-bus.h
+#include qapi/qmp/qjson.h
+#include monitor/monitor.h
 
 #define VIRTIO_NET_VM_VERSION11
 
@@ -192,6 +194,90 @@ static void virtio_net_set_link_status(NetClientState *nc)
 virtio_net_set_status(vdev, vdev-status);
 }
 
+static bool notify_enabled = true;
+
+static void rxfilter_notify(const char *name)
+{
+QObject *event_data;
+
+if (notify_enabled) {
+event_data = qobject_from_jsonf({ 'name': %s }, name);
+monitor_protocol_event(QEVENT_RX_FILTER_CHANGED, event_data);
+ 

[Qemu-devel] [PATCH 1/5] pci-assign: remove the duplicate function name in debug message

2013-05-23 Thread Wanlong Gao
While DEBUG() already includes the function name.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
Acked-by: Alex Williamson alex.william...@redhat.com
---
 hw/i386/kvm/pci-assign.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index ff85590..9896c28 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -226,7 +226,7 @@ static uint32_t slow_bar_readb(void *opaque, hwaddr addr)
 uint32_t r;
 
 r = *in;
-DEBUG(slow_bar_readl addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
 
 return r;
 }
@@ -238,7 +238,7 @@ static uint32_t slow_bar_readw(void *opaque, hwaddr addr)
 uint32_t r;
 
 r = *in;
-DEBUG(slow_bar_readl addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
 
 return r;
 }
@@ -250,7 +250,7 @@ static uint32_t slow_bar_readl(void *opaque, hwaddr addr)
 uint32_t r;
 
 r = *in;
-DEBUG(slow_bar_readl addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, r);
 
 return r;
 }
@@ -260,7 +260,7 @@ static void slow_bar_writeb(void *opaque, hwaddr addr, 
uint32_t val)
 AssignedDevRegion *d = opaque;
 uint8_t *out = d-u.r_virtbase + addr;
 
-DEBUG(slow_bar_writeb addr=0x TARGET_FMT_plx  val=0x%02x\n, addr, val);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%02x\n, addr, val);
 *out = val;
 }
 
@@ -269,7 +269,7 @@ static void slow_bar_writew(void *opaque, hwaddr addr, 
uint32_t val)
 AssignedDevRegion *d = opaque;
 uint16_t *out = (uint16_t *)(d-u.r_virtbase + addr);
 
-DEBUG(slow_bar_writew addr=0x TARGET_FMT_plx  val=0x%04x\n, addr, val);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%04x\n, addr, val);
 *out = val;
 }
 
@@ -278,7 +278,7 @@ static void slow_bar_writel(void *opaque, hwaddr addr, 
uint32_t val)
 AssignedDevRegion *d = opaque;
 uint32_t *out = (uint32_t *)(d-u.r_virtbase + addr);
 
-DEBUG(slow_bar_writel addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, val);
+DEBUG(addr=0x TARGET_FMT_plx  val=0x%08x\n, addr, val);
 *out = val;
 }
 
-- 
1.8.3.rc2.10.g0c2b1cf




[Qemu-devel] use O_DIRECT to open disk images for IDE failed under xen-4.1.2 and qemu upstream

2013-05-23 Thread Gonglei (Arei)
Hi, all

I use O_DIRECT to open disk images for IDE, but I'm failed. After debug, I get 
the below logs:
[2013-05-22 23:25:46] ide: CMD=c8
[2013-05-22 23:25:46] bmdma: readb 0x00 : 0x08
[2013-05-22 23:25:46] bmdma: writeb 0x00 : 0x09
[2013-05-22 23:25:46] bmdma_cmd_writeb: 0x0009
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
[2013-05-22 23:26:39] bmdma: writeb 0x00 : 0x08
[2013-05-22 23:26:39] bmdma_cmd_writeb: 0x0008
[2013-05-22 23:26:56] == offset:0 buf:0x7ff100f21c00 count:512 aio_offset:0
[2013-05-22 23:31:30] == offset:0 buf:0x7ff100f21c00 count:512 aio_offset:0
[2013-05-22 23:31:30] == handle_aiocb_rw_linear errno: -14
[2013-05-22 23:31:30] == paio_complete errno=14
[2013-05-22 23:31:30] == ide_dma_error!!!
[2013-05-22 23:31:30] ide: read status addr=0x3f6 val=41

QEMU command line :
qemu-system-i386 -xen-domid 837 -chardev 
socket,id=libxl-cmd,path=/var/run/xen/qmp-libxl-837,server,nowait -mon 
chardev=libxl-cmd,mode=control -name suse11 -vnc 0.0.0.0:1 -serial pty -boot 
order=c -usb -usbdevice tablet -smp 2,maxcpus=2 -device 
rtl8139,id=nic0,netdev=net0,mac=00:16:3e:13:d3:72 -netdev 
type=tap,id=net0,ifname=tap837.0,downscript=no -M xenfv -m 2040 -drive 
file=/mnt/sdd/image/suse.image,if=ide,index=0,media=disk,format=raw,cache=none

errno 14 shows Bad Address. And I find QEMU_AIO_MISALIGNED flag bit is not set 
through debug. 

/*
 * If O_DIRECT is used the buffer needs to be aligned on a sector
 * boundary.  Check if this is the case or tell the low-level
 * driver that it needs to copy the buffer.
 */
if ((bs-open_flags  BDRV_O_NOCACHE)) {
if (!bdrv_qiov_is_aligned(bs, qiov)) {//if the address is 
aligned-512, will no meet the conditions
type |= QEMU_AIO_MISALIGNED;
#ifdef CONFIG_LINUX_AIO
} else if (s-use_aio) {
return laio_submit(bs, s-aio_ctx, s-fd, sector_num, qiov,
   nb_sectors, cb, opaque, type);
#endif

Next process:
static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
{
ssize_t nbytes;
char *buf;

if (!(aiocb-aio_type  QEMU_AIO_MISALIGNED)) {
/*
 * If there is just a single buffer, and it is properly aligned
 * we can just use plain pread/pwrite without any problems.
 */
if (aiocb-aio_niov == 1)
 return handle_aiocb_rw_linear(aiocb, aiocb-aio_iov-iov_base); 
//this way, and reports errno 14 next

Anyone have a good method to resolve this bug? Thanks!

Best Regards!
-Gonglei



[Qemu-devel] [PATCH V2 2/5] block: move snapshot code in block.c to block/snapshot.c

2013-05-23 Thread Wenchao Xia
All snapshot related code, except bdrv_snapshot_dump(), is moved to
block/snapshot.c. bdrv_snapshot_dump() will be moved to another file later.
It also fixes small code style errors reported by check script.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 block.c  |  105 --
 block/Makefile.objs  |1 +
 block/snapshot.c |  162 ++
 include/block/block.h|   28 ++--
 include/block/snapshot.h |   54 +++
 savevm.c |   23 +--
 6 files changed, 224 insertions(+), 149 deletions(-)
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/snapshot.h

diff --git a/block.c b/block.c
index 478a3b2..2561800 100644
--- a/block.c
+++ b/block.c
@@ -3346,111 +3346,6 @@ bool bdrv_debug_is_suspended(BlockDriverState *bs, 
const char *tag)
 return false;
 }
 
-/**/
-/* handling of snapshots */
-
-int bdrv_can_snapshot(BlockDriverState *bs)
-{
-BlockDriver *drv = bs-drv;
-if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
-return 0;
-}
-
-if (!drv-bdrv_snapshot_create) {
-if (bs-file != NULL) {
-return bdrv_can_snapshot(bs-file);
-}
-return 0;
-}
-
-return 1;
-}
-
-int bdrv_is_snapshot(BlockDriverState *bs)
-{
-return !!(bs-open_flags  BDRV_O_SNAPSHOT);
-}
-
-int bdrv_snapshot_create(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info)
-{
-BlockDriver *drv = bs-drv;
-if (!drv)
-return -ENOMEDIUM;
-if (drv-bdrv_snapshot_create)
-return drv-bdrv_snapshot_create(bs, sn_info);
-if (bs-file)
-return bdrv_snapshot_create(bs-file, sn_info);
-return -ENOTSUP;
-}
-
-int bdrv_snapshot_goto(BlockDriverState *bs,
-   const char *snapshot_id)
-{
-BlockDriver *drv = bs-drv;
-int ret, open_ret;
-
-if (!drv)
-return -ENOMEDIUM;
-if (drv-bdrv_snapshot_goto)
-return drv-bdrv_snapshot_goto(bs, snapshot_id);
-
-if (bs-file) {
-drv-bdrv_close(bs);
-ret = bdrv_snapshot_goto(bs-file, snapshot_id);
-open_ret = drv-bdrv_open(bs, NULL, bs-open_flags);
-if (open_ret  0) {
-bdrv_delete(bs-file);
-bs-drv = NULL;
-return open_ret;
-}
-return ret;
-}
-
-return -ENOTSUP;
-}
-
-int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
-{
-BlockDriver *drv = bs-drv;
-if (!drv)
-return -ENOMEDIUM;
-if (drv-bdrv_snapshot_delete)
-return drv-bdrv_snapshot_delete(bs, snapshot_id);
-if (bs-file)
-return bdrv_snapshot_delete(bs-file, snapshot_id);
-return -ENOTSUP;
-}
-
-int bdrv_snapshot_list(BlockDriverState *bs,
-   QEMUSnapshotInfo **psn_info)
-{
-BlockDriver *drv = bs-drv;
-if (!drv)
-return -ENOMEDIUM;
-if (drv-bdrv_snapshot_list)
-return drv-bdrv_snapshot_list(bs, psn_info);
-if (bs-file)
-return bdrv_snapshot_list(bs-file, psn_info);
-return -ENOTSUP;
-}
-
-int bdrv_snapshot_load_tmp(BlockDriverState *bs,
-const char *snapshot_name)
-{
-BlockDriver *drv = bs-drv;
-if (!drv) {
-return -ENOMEDIUM;
-}
-if (!bs-read_only) {
-return -EINVAL;
-}
-if (drv-bdrv_snapshot_load_tmp) {
-return drv-bdrv_snapshot_load_tmp(bs, snapshot_name);
-}
-return -ENOTSUP;
-}
-
 /* backing_file can either be relative, or absolute, or a protocol.  If it is
  * relative, it must be relative to the chain.  So, passing in bs-filename
  * from a BDS as backing_file should not be done, as that may be relative to
diff --git a/block/Makefile.objs b/block/Makefile.objs
index 5f0358a..8670999 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -4,6 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o 
qed-cluster.o
 block-obj-y += qed-check.o
 block-obj-y += vhdx.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
+block-obj-y += snapshot.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
diff --git a/block/snapshot.c b/block/snapshot.c
new file mode 100644
index 000..cdc2a76
--- /dev/null
+++ b/block/snapshot.c
@@ -0,0 +1,162 @@
+/*
+ * Block layer snapshot related functions
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished 

Re: [Qemu-devel] [PATCH 1/2] target-i386/seg_helper: refactor 4 helper functions

2013-05-23 Thread Peter Maydell
On 23 May 2013 09:35, li guang lig.f...@cn.fujitsu.com wrote:
 ping ... again.

misc_check_helper is still a terrible function name.

-- PMM



Re: [Qemu-devel] qemu seabios issue with vhost-scsi

2013-05-23 Thread Gleb Natapov
On Thu, May 23, 2013 at 08:53:55AM +0800, Asias He wrote:
 On Wed, May 22, 2013 at 05:36:08PM -0700, Badari wrote:
  Hi,
  
  While testing vhost-scsi in the current qemu git, ran into an earlier issue
  with seabios. I had to disable scsi support in seabios to get it working.
  
  I was hoping this issue got resolved when vhost-scsi support got
  merged into qemu. Is this still being worked on ?
 
 Hmm, can you try seabios.git? Not sure if seabios shipped by qemu picked
 up the fixes for vhost-scsi.
 
Nothing in seabios should crash qemu.

  Thanks,
  Badari
  
  [root ~]# gdb /root/qemu/x86_64-softmmu/qemu-system-x86_64
  GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
  Copyright (C) 2010 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later
  http://gnu.org/licenses/gpl.html
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type show copying
  and show warranty for details.
  This GDB was configured as x86_64-redhat-linux-gnu.
  For bug reporting instructions, please see:
  http://www.gnu.org/software/gdb/bugs/...
  Reading symbols from /root/qemu/x86_64-softmmu/qemu-system-x86_64...done.
  (gdb) run  --cpu qemu64 --enable-kvm  -m 4096 -drive
  file=/var/lib/libvirt/images/lnx.img,if=ide,cache=writethrough
  -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off -vnc
  :10 -boot d
  Starting program: /root/qemu/x86_64-softmmu/qemu-system-x86_64 --cpu
  qemu64 --enable-kvm  -m 4096 -drive
  file=/var/lib/libvirt/images/window.img,if=ide,cache=writethrough
  -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off -vnc
  :10 -boot d
  warning: no loadable sections found in added symbol-file
  system-supplied DSO at 0x77ffa000
  [Thread debugging using libthread_db enabled]
  [New Thread 0x71c1c700 (LWP 4725)]
  [New Thread 0x71239700 (LWP 4726)]
  [New Thread 0x7fffeb7ff700 (LWP 4729)]
  
  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x71239700 (LWP 4726)]
  0x556b3191 in scsi_device_find (bus=0x565abb50, channel=0, id=0,
  lun=0) at hw/scsi/scsi-bus.c:1744
  1744QTAILQ_FOREACH_REVERSE(kid, bus-qbus.children,
  ChildrenHead, sibling) {
  Missing separate debuginfos, use: debuginfo-install
  cyrus-sasl-gssapi-2.1.23-13.el6_3.1.x86_64
  cyrus-sasl-lib-2.1.23-13.el6_3.1.x86_64
  cyrus-sasl-md5-2.1.23-13.el6_3.1.x86_64
  cyrus-sasl-plain-2.1.23-13.el6_3.1.x86_64 db4-4.7.25-17.el6.x86_64
  glib2-2.22.5-7.el6.x86_64 glibc-2.12-1.107.el6.x86_64
  gnutls-2.8.5-10.el6.x86_64 keyutils-libs-1.4-4.el6.x86_64
  krb5-libs-1.10.3-10.el6.x86_64 libcom_err-1.41.12-14.el6.x86_64
  libcurl-7.19.7-35.el6.x86_64 libgcrypt-1.4.5-9.el6_2.2.x86_64
  libgpg-error-1.7-4.el6.x86_64 libidn-1.18-2.el6.x86_64
  libpng-1.2.49-1.el6_2.x86_64 libselinux-2.0.94-5.3.el6.x86_64
  libssh2-1.4.2-1.el6.x86_64 libtasn1-2.3-3.el6_2.1.x86_64
  ncurses-libs-5.7-3.20090208.el6.x86_64 nspr-4.9.2-1.el6.x86_64
  nss-3.14.0.0-12.el6.x86_64 nss-softokn-freebl-3.12.9-11.el6.x86_64
  nss-util-3.14.0.0-2.el6.x86_64 openldap-2.4.23-31.el6.x86_64
  openssl-1.0.0-27.el6.x86_64 pixman-0.26.2-4.el6.x86_64
  zlib-1.2.3-29.el6.x86_64
  (gdb) bt
  #0  0x556b3191 in scsi_device_find (bus=0x565abb50,
  channel=0, id=
  0, lun=0) at hw/scsi/scsi-bus.c:1744
  #1  0x557a59f0 in virtio_scsi_device_find (vdev=0x565aba38, vq=
  0x565d1150) at /root/qemu/hw/scsi/virtio-scsi.c:56
  #2  virtio_scsi_handle_cmd (vdev=0x565aba38, vq=0x565d1150)
  at /root/qemu/hw/scsi/virtio-scsi.c:376
  #3  0x557b3410 in access_with_adjusted_size (addr=16, value=
  0x71238b78, size=2, access_size_min=value optimized out,
  access_size_max=value optimized out, access=
  0x557b4b80 memory_region_write_accessor, opaque=0x565ab8f0)
  at /root/qemu/memory.c:364
  #4  0x557b3a3b in memory_region_iorange_write (
  iorange=value optimized out, offset=value optimized out,
  width=value optimized out, data=2) at /root/qemu/memory.c:439
  #5  0x557b29a6 in kvm_handle_io (env=0x56520aa0)
  at /root/qemu/kvm-all.c:1485
  #6  kvm_cpu_exec (env=0x56520aa0) at /root/qemu/kvm-all.c:1634
  #7  0x5576108e in qemu_kvm_cpu_thread_fn (arg=0x56520aa0)
  at /root/qemu/cpus.c:759
  #8  0x76059851 in start_thread () from /lib64/libpthread.so.0
  #9  0x75da790d in clone () from /lib64/libc.so.6
  
  
 
 -- 
 Asias

--
Gleb.



Re: [Qemu-devel] [PATCH 17/30] memory: add address_space_translate

2013-05-23 Thread Paolo Bonzini
Il 23/05/2013 09:09, liu ping fan ha scritto:
   void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
 int len, bool is_write)
   {
  -AddressSpaceDispatch *d = as-dispatch;
  -int l;
  +hwaddr l;
   uint8_t *ptr;
   uint32_t val;
  -hwaddr page;
  +hwaddr addr1;
   MemoryRegionSection *section;
 
   while (len  0) {
  -page = addr  TARGET_PAGE_MASK;
  -l = (page + TARGET_PAGE_SIZE) - addr;
  -if (l  len)
  -l = len;
  -section = phys_page_find(d, page  TARGET_PAGE_BITS);
  +l = len;
  +section = address_space_translate(as, addr, addr1, l, is_write);
 
 Jan's Rework sub-page handling patch broke the tlb_set_page
 (anything else?)  But I think we still need a function based on
 address_space_translate to wrap the subpage logic inside and ease the
 incoming RCU style.

The idea is that address_space_translate gets a ref to the MemoryRegion,
and the ref is then released by the caller of address_space_translate.

That means that the actual memory accesses can run outside the RCU
critical section.

But I'm not sure how that is related to subpage logic.  Subpages are
simply MemoryRegions that only exist in the phys page map, rather than
within an AddressSpace.  Their destruction will be delayed anyway by
doing call_rcu on the old phys page map.

Paolo



Re: [Qemu-devel] [PATCH qom-cpu 4/4] memory_mapping: Move stubs to libqemustub.a

2013-05-23 Thread Paolo Bonzini
Il 22/05/2013 15:09, Andreas Färber ha scritto:
 Allows us to drop CONFIG_NO_GET_MEMORY_MAPPING with its indirect
 dependency on CONFIG_HAVE_GET_MEMORY_MAPPING in Makefile.target.
 
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
  Makefile.target | 2 --
  stubs/Makefile.objs | 1 +
  memory_mapping-stub.c = stubs/memory_mapping.c | 5 +++--
  3 files changed, 4 insertions(+), 4 deletions(-)
  rename memory_mapping-stub.c = stubs/memory_mapping.c (85%)
 
 diff --git a/Makefile.target b/Makefile.target
 index 5b02200..efc0b11 100644
 --- a/Makefile.target
 +++ b/Makefile.target
 @@ -63,7 +63,6 @@ all: $(PROGS) stap
  CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y)
  CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
  CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
 -CONFIG_NO_GET_MEMORY_MAPPING = $(if $(subst 
 n,,$(CONFIG_HAVE_GET_MEMORY_MAPPING)),n,y)
  
  #
  # cpu emulator library
 @@ -112,7 +111,6 @@ obj-$(CONFIG_KVM) += kvm-all.o
  obj-y += memory.o savevm.o cputlb.o
  obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
  obj-y += dump.o memory_mapping_common.o
 -obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
  LIBS+=$(libs_softmmu)
  
  # xen support
 diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
 index 9b701b4..b0bca4d 100644
 --- a/stubs/Makefile.objs
 +++ b/stubs/Makefile.objs
 @@ -10,6 +10,7 @@ stub-obj-y += fdset-remove-fd.o
  stub-obj-y += get-fd.o
  stub-obj-y += get-vm-name.o
  stub-obj-y += iothread-lock.o
 +stub-obj-y += memory_mapping.o
  stub-obj-y += migr-blocker.o
  stub-obj-y += mon-is-qmp.o
  stub-obj-y += mon-printf.o
 diff --git a/memory_mapping-stub.c b/stubs/memory_mapping.c
 similarity index 85%
 rename from memory_mapping-stub.c
 rename to stubs/memory_mapping.c
 index c48ea44..4db2108 100644
 --- a/memory_mapping-stub.c
 +++ b/stubs/memory_mapping.c
 @@ -11,8 +11,9 @@
   *
   */
  
 -#include cpu.h
 -#include exec/cpu-all.h
 +#include qemu-common.h
 +#include exec/cpu-common.h
 +#include qom/cpu.h
  #include sysemu/memory_mapping.h
  
  int qemu_get_guest_memory_mapping(MemoryMappingList *list)
 

Patches 1-3 are fine.  But I wonder if a better replacement for stubs is
methods in CPU.

Paolo



Re: [Qemu-devel] segfault in aio_bh_poll async.c:80 WAS: Re: kvm process disappears

2013-05-23 Thread Paolo Bonzini
Il 22/05/2013 14:24, Stefan Priebe - Profihost AG ha scritto:
 Am 22.05.2013 um 10:41 schrieb Paolo Bonzini pbonz...@redhat.com:
 
 Il 22/05/2013 08:26, Stefan Priebe - Profihost AG ha scritto:
 Hi,

 as i can't reproduce no ;-( i just saw the kernel segfault message and
 used addr2line and a qemu dbg package to get the code line.

 I've now seen this again for two or three times. It always happens
 when we do an fstrim inside the guest.


 And I've seen this first since josh async rbd patch.

 This one?

 commit dc7588c1eb3008bda53dde1d6b890cd299758155
 
 Yes. But i'm not sure whether this is coincendence.

Ok.

  Do you see it even with -drive discard=off?

 I use discard / trim for thin provisioning and need it. This is a
 production system so I can't test without it.
 
 I use scsi virtio with discard_granularity=512

Note that 1.5.0 won't need this anymore, but it will need -drive
discard=on.  Any chance you can try to reproduce it in a different
environment?

Paolo




Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 23, 2013 at 05:08:00PM +0800, Amos Kong wrote:
 We want to implement mac programming over macvtap through Libvirt,
 related rx-filter configuration contains main mac, some of rx-mode
 and mac-table.
 
 The previous patch adds QMP event to notify management of rx-filter
 change. This patch adds a monitor command to query rx-filter
 information.
 
 A flag is used to avoid events flooding, if user don't query
 rx-filter after receives one event, new events won't be sent
 to qmp monitor.
 
 (qemu) info rx-filter vnet0
 vnet0:
  \ promiscuous: on
  \ multicast: normal
  \ unicast: normal
  \ broadcast-allowed: off
  \ multicast-overflow: off
  \ unicast-overflow: off
  \ main-mac: 52:54:00:12:34:56
  \ unicast-table:
  \ multicast-table:
 01:00:5e:00:00:01
 33:33:00:00:00:01
 33:33:ff:12:34:56
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  hmp-commands.hx |  2 ++
  hmp.c   | 49 
  hmp.h   |  1 +
  hw/net/virtio-net.c | 93 
 +
  include/net/net.h   |  2 ++
  monitor.c   |  8 +
  net/net.c   | 47 +++
  qapi-schema.json| 73 +
  qmp-commands.hx | 55 +++
  9 files changed, 330 insertions(+)
 
 diff --git a/hmp-commands.hx b/hmp-commands.hx
 index 9cea415..b7863eb 100644
 --- a/hmp-commands.hx
 +++ b/hmp-commands.hx
 @@ -1639,6 +1639,8 @@ show qdev device model list
  show roms
  @item info tpm
  show the TPM device
 +@item info rx-filter [net client name]
 +show the rx-filter information for all nics (or for the given nic)
  @end table
  ETEXI
  
 diff --git a/hmp.c b/hmp.c
 index 4fb76ec..5b47382 100644
 --- a/hmp.c
 +++ b/hmp.c
 @@ -653,6 +653,55 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
  qapi_free_TPMInfoList(info_list);
  }
  
 +void hmp_info_rx_filter(Monitor *mon, const QDict *qdict)
 +{
 +RxFilterInfoList *filter_list, *entry;
 +strList *str_entry;
 +bool has_name = qdict_haskey(qdict, name);
 +const char *name = NULL;
 +
 +if (has_name) {
 +name = qdict_get_str(qdict, name);
 +}
 +
 +filter_list = qmp_query_rx_filter(has_name, name, NULL);
 +entry = filter_list;
 +
 +while (entry) {
 +monitor_printf(mon, %s:\n, entry-value-name);
 +monitor_printf(mon,  \\ promiscuous: %s\n,
 +   entry-value-promiscuous ? on : off);
 +monitor_printf(mon,  \\ multicast: %s\n,
 +   RxState_lookup[entry-value-multicast]);
 +monitor_printf(mon,  \\ unicast: %s\n,
 +   RxState_lookup[entry-value-unicast]);
 +monitor_printf(mon,  \\ broadcast-allowed: %s\n,
 +   entry-value-broadcast_allowed ? on : off);
 +monitor_printf(mon,  \\ multicast-overflow: %s\n,
 +   entry-value-multicast_overflow ? on : off);
 +monitor_printf(mon,  \\ unicast-overflow: %s\n,
 +   entry-value-unicast_overflow ? on : off);
 +monitor_printf(mon,  \\ main-mac: %s\n, entry-value-main_mac);
 +
 +str_entry = entry-value-unicast_table;
 +monitor_printf(mon,  \\ unicast-table:\n);
 +while (str_entry) {
 +monitor_printf(mon, %s\n, str_entry-value);
 +str_entry = str_entry-next;
 +}
 +
 +str_entry = entry-value-multicast_table;
 +monitor_printf(mon,  \\ multicast-table:\n);
 +while (str_entry) {
 +monitor_printf(mon, %s\n, str_entry-value);
 +str_entry = str_entry-next;
 +}
 +
 +entry = entry-next;
 +}
 +qapi_free_RxFilterInfoList(filter_list);
 +}
 +
  void hmp_quit(Monitor *mon, const QDict *qdict)
  {
  monitor_suspend(mon);
 diff --git a/hmp.h b/hmp.h
 index 95fe76e..9af733e 100644
 --- a/hmp.h
 +++ b/hmp.h
 @@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);
  void hmp_info_pci(Monitor *mon, const QDict *qdict);
  void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
  void hmp_info_tpm(Monitor *mon, const QDict *qdict);
 +void hmp_info_rx_filter(Monitor *mon, const QDict *qdict);
  void hmp_quit(Monitor *mon, const QDict *qdict);
  void hmp_stop(Monitor *mon, const QDict *qdict);
  void hmp_system_reset(Monitor *mon, const QDict *qdict);
 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
 index 1ea9556..f93e021 100644
 --- a/hw/net/virtio-net.c
 +++ b/hw/net/virtio-net.c
 @@ -21,6 +21,8 @@
  #include hw/virtio/virtio-net.h
  #include net/vhost_net.h
  #include hw/virtio/virtio-bus.h
 +#include qapi/qmp/qjson.h
 +#include monitor/monitor.h
  
  #define VIRTIO_NET_VM_VERSION11
  
 @@ -192,6 +194,90 @@ static void virtio_net_set_link_status(NetClientState 
 *nc)
  virtio_net_set_status(vdev, vdev-status);
  }
  
 +static bool notify_enabled = true;

Please, make this part of the device 

Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 23, 2013 at 05:07:59PM +0800, Amos Kong wrote:
 Introduce this new QMP event to notify management after guest changes
 rx-filter configuration.
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  QMP/qmp-events.txt| 14 ++
  include/monitor/monitor.h |  1 +
  monitor.c |  1 +
  3 files changed, 16 insertions(+)
 
 diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
 index 92fe5fb..ad6612b 100644
 --- a/QMP/qmp-events.txt
 +++ b/QMP/qmp-events.txt
 @@ -154,6 +154,20 @@ Data:
  path: /machine/peripheral/virtio-net-pci-0 },
timestamp: { seconds: 1265044230, microseconds: 450486 } }
  
 +RX_FILTER_CHANGED
 +-
 +
 +Emitted when rx-filter configuration is changed by the guest.

Please stress this is only for the NIC. It does not apply
to non-NIC netclients.

 +
 +Data:
 +
 +- name: net client name (json-string)

Maybe a device path here as well?

 +
 +{ event: RX_FILTER_CHANGED,
 +  data: { name: vnet0 },
 +  timestamp: { seconds: 1368697518, microseconds: 326866 }}
 +}
 +
  DEVICE_TRAY_MOVED
  -
  
 diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
 index 1a6cfcf..c495a67 100644
 --- a/include/monitor/monitor.h
 +++ b/include/monitor/monitor.h
 @@ -40,6 +40,7 @@ typedef enum MonitorEvent {
  QEVENT_BLOCK_JOB_ERROR,
  QEVENT_BLOCK_JOB_READY,
  QEVENT_DEVICE_DELETED,
 +QEVENT_RX_FILTER_CHANGED,
  QEVENT_DEVICE_TRAY_MOVED,
  QEVENT_SUSPEND,
  QEVENT_SUSPEND_DISK,
 diff --git a/monitor.c b/monitor.c
 index 6ce2a4e..4f7bd48 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -489,6 +489,7 @@ static const char *monitor_event_names[] = {
  [QEVENT_BLOCK_JOB_ERROR] = BLOCK_JOB_ERROR,
  [QEVENT_BLOCK_JOB_READY] = BLOCK_JOB_READY,
  [QEVENT_DEVICE_DELETED] = DEVICE_DELETED,
 +[QEVENT_RX_FILTER_CHANGED] = RX_FILTER_CHANGED,
  [QEVENT_DEVICE_TRAY_MOVED] = DEVICE_TRAY_MOVED,
  [QEVENT_SUSPEND] = SUSPEND,
  [QEVENT_SUSPEND_DISK] = SUSPEND_DISK,
 -- 
 1.8.1.4



Re: [Qemu-devel] [PATCH arm-devs v1 1/5] sd/sd.c: Fix inquiry ACMD41

2013-05-23 Thread Igor Mitsyanko
On 05/23/2013 03:42 AM, Peter Crosthwaite wrote:
 Hi Igor,

 On Wed, May 22, 2013 at 11:37 PM, Igor Mitsyanko i.mitsya...@gmail.com 
 wrote:

 On 05/21/2013 10:50 AM, peter.crosthwa...@xilinx.com wrote:

 From: Peter Crosthwaite peter.crosthwa...@xilinx.com

 the SD command ACMD41 can be used in a read only mode to query device
 state without doing the SD card initialisation. This is valid even
 which the device is already initialised. Fix the command to be
 responsive when in the ready state accordingly.

 Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
 ---

   hw/sd/sd.c | 1 +
   1 file changed, 1 insertion(+)

 diff --git a/hw/sd/sd.c b/hw/sd/sd.c
 index 2e0ef3e..89bfb7a 100644
 --- a/hw/sd/sd.c
 +++ b/hw/sd/sd.c
 @@ -1277,6 +1277,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
   }
   switch (sd-state) {
   case sd_idle_state:
 +case sd_ready_state:
   /* We accept any voltage.  1 V is nothing.  */
   if (req.arg)
   sd-state = sd_ready_state;


 I couldn't find any info in SD specification that would confirm this change
 correctness, what about
 table Table 4-29: Card State Transition Table which states that ACMD41 is
 illegal in ready state?


 By the letter of the spec I think you are right. Although this patch
 is needed to make my QEMU consistent with my real hardware. I'll dig
 deeper.


Hello, Peter, after thinking some more about this, I assume that table
4-29 might be incorrect. It depends on when idle-ready state transition
occurs, its not clear from specification.

Controller issues first ACMD41 to start card's initialisation. Spec
states that this process could take up to 1sec, and all this time
controller should query card's busy state in a loop with ACMD41. After
response to ACMD41 has busy flag deasserted, card is considered to be
ready. But this means that card was already in ready state when it
received last ACMD41 command, right? Unless card transitions to ready
state only after a response to last ACMD41 was sent.

If that's how real SD card behaves in your tests, then I think this
patch is OK, but it could benefit from a short comment explaining that
this behaviour is not covered by specification.


Reviewed-by: Igor Mitsyanko i.mitsya...@gmail.com


 Regards,
 Peter

 --
 Best wishes,
 Igor Mitsyanko
 email: i.mitsya...@gmail.com




--
Best wishes,
Igor Mitsyanko
email: i.mitsya...@gmail.com



Re: [Qemu-devel] [PATCH 6/8] pci: Simpler implementation of primary PCI bus

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:10AM +1000, David Gibson wrote:
 Currently pci_get_primary_bus() searches the list of root buses for one
 with domain 0.  But since host buses are always registered with domain 0,
 this just amounts to finding the only PCI host bus.
 
 This simplifies the implementation by defining the primary PCI bus to
 be the first one registered, using a global variable to track it.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au

This is the only part that I dislike.
How about an explicit API to set the primary bus?
Let machine types set it.

 ---
  hw/pci/pci.c |   18 +-
  1 file changed, 9 insertions(+), 9 deletions(-)
 
 diff --git a/hw/pci/pci.c b/hw/pci/pci.c
 index a3c192c..b25a1a1 100644
 --- a/hw/pci/pci.c
 +++ b/hw/pci/pci.c
 @@ -96,6 +96,7 @@ struct PCIHostBus {
  QLIST_ENTRY(PCIHostBus) next;
  };
  static QLIST_HEAD(, PCIHostBus) host_buses;
 +static PCIBus *pci_primary_bus;
  
  static const VMStateDescription vmstate_pcibus = {
  .name = PCIBUS,
 @@ -241,6 +242,12 @@ static int pcibus_reset(BusState *qbus)
  static void pci_host_bus_register(int domain, PCIBus *bus)
  {
  struct PCIHostBus *host;
 +
 +/* If this is the first one, assume it's the primary bus */
 +if (!pci_primary_bus) {
 +pci_primary_bus = bus;
 +}
 +
  host = g_malloc0(sizeof(*host));
  host-domain = domain;
  host-bus = bus;
 @@ -249,15 +256,7 @@ static void pci_host_bus_register(int domain, PCIBus 
 *bus)
  
  PCIBus *pci_get_primary_bus(void)
  {
 -struct PCIHostBus *host;
 -
 -QLIST_FOREACH(host, host_buses, next) {
 -if (host-domain == 0) {
 -return host-bus;
 -}
 -}
 -
 -return NULL;
 +return pci_primary_bus;
  }
  
  PCIBus *pci_device_root_bus(const PCIDevice *d)
 @@ -300,6 +299,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
  
  /* host bridge */
  QLIST_INIT(bus-child);
 +
  pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported 
 */
  
  vmstate_register(NULL, -1, vmstate_pcibus, bus);
 -- 
 1.7.10.4



Re: [Qemu-devel] [RFC PATCH v3 00/11] qemu-ga: fsfreeze on Windows using VSS

2013-05-23 Thread Laszlo Ersek
Sekiyama-san,

On 05/21/13 17:33, Tomoki Sekiyama wrote:

 * About errors in Windows 7 with patch v2
   VSS requires to write to snapshot volumes just before making them read-only
   at final commit phase. This feature is called `auto-recovery'
   (See 
 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384651(v=vs.85).aspx#base.vssgloss_auto_recoved_shadow_copy
  for details).
 
   Since qemu and libvirt don't have feature to handle writable snapshots,
   this patchset just disables auto-recovery by specifying
   VSS_VOLSNAP_ATTR_NO_AUTORECOVERY flag to SetContext.
   Unfortunately, this flag seems unsupported in Windows 7 or earlier.
   It tries to look up the snapshot volumes to write and fails in
   VSS_E_OBJECT_NOT_FOUND.
 
   For fundamental resolution we need a framework for guests to query snapshots
   and to mount them as writable snapshots, but we just ignore the error in
   this patchset.

I've been trying to understand VSS as documented in

http://technet.microsoft.com/en-us/library/ee923636%28v=ws.10%29.aspx

I'll be referring to the steps detailed there as VSS steps.

Currently I'm under the impression that the guest-fsfreeze-freeze and
guest-fsfreeze-thaw commands do not match VSS from a who has control
when perspective.

VSS steps 1 to 5 correspond to guest-fsfreeze-freeze. In the POSIX
flavor of qemu-ga, including fsfreeze hook scripts, at this point
qemu-ga gets back and returns control to the management stack, and
backup can be done.

VSS step 6 corresponds to the management stack preparing the snapshot(s)
or other means of backup.

VSS steps 7 to 8 correspond to guest-fsfreeze-thaw. The POSIX flavor
of qemu-ga thaws filesystems and reactivates applications / enables them
to dirty their own data stores. This action is initiated by the
management stack which has full control over its timing and conditions etc.

I believe to discover the following (orthogonal) mismatches between VSS
and our current freeze/thaw APIs:

(i) Once VSS starts running at step 1, it doesn't relinquish control
after step 5, and it doesn't allow an external controller to relaunch it
from step 7. In other words, VSS step 6 is a callout / callback
initiated by Windows logic that doesn't match our current control ownership.

In theory VSS step 6 should issue a QMP event (?) that allows libvirt to
make the snapshot, and until libvirt is done with that, VSS step 6
should block.


(ii) Somewhat similar is the control over backup storage:

An fsfreeze hook script causes the corresponding application to clean up
its live data store. The application doesn't encounter the notion of a
separate / detached copy, and no additional storage is visible (needs to
be visible) in the guest. The management stack exploits this guarantee
when it (basically blindly) snapshots the disk image.

Under VSS, in-guest components (VSS providers, basically drivers) are
responsible for incremental backup (copy-on-write etc.) features. I'm
not sure how this can be combined with qcow2 features managed by
libvirt. The VSS provider could target a separate disk, update it
incrementally to mirror the current live data, and libvirt could keep
snapshots of this backup disk.


(iii) VSS step 10 exists because in fact I cheated in (i) and VSS steps
1 to 5 do not correspond to guest-fsfreeze-freeze; the VSS design has
aspects that are completely absent from guest-fsfreeze-freeze.

guest-fsfreeze-freeze, including the hook scripts, gives as much time to
applications to quiesce as they need. When the main hook script returns
control to qemu-qa, and when qemu-ga returns control to libvirt, the
layer taking back control is assured that the lower layer has completed
all of its freezing responsibilities.

This is not so with VSS steps 1-5, and the root cause is performance /
avoidance of live service interruption. VSS puts a 60 second limit on
application data store quiescing, and a 10 second limit on actual
snapshotting / backup (VSS step 6). Live service should resume in no
more than 70 seconds apparently.

VSS realizes that many applications won't be able to satisfy this
requirement. Therefore the application level quiescing is split in a
synchronous handler and an asynchronous bottom half (which is VSS step
10).
- Up to and including VSS step 5, an application prepares but a separate
dirty context (in 60 seconds).
- In VSS step 6, this context (shadow copy) is detached (move to other
storage, probably).
- In VSS steps 7 and 8, the application resumes live service. Also,
- VSS step 10, the bottom half of the application (a subprocess or a
dedicated thread, maybe), cleans up the now detached dirty context, *in
parallel* to the live service of the application.

If we disable VSS step 10 (VSS_VOLSNAP_ATTR_NO_AUTORECOVERY), I'm still
confused / unsure about:

- the control ownership problem in (i) and the storage problem in (ii)
-- I believe your series must already solve this; can you please
describe it in a few words?

- the time limits for VSS steps 5 

Re: [Qemu-devel] [PATCH 5/8] pci: Replace pci_find_domain() with more general pci_root_bus_path()

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:09AM +1000, David Gibson wrote:
 pci_find_domain() is used in a number of places where we want an id for a
 whole PCI domain (i.e. the subtree under a PCI root bus).  The trouble is
 that many platforms may support multiple independent host bridges with no
 hardware supplied notion of domain number.
 
 This patch, therefore, replaces calls to pci_find_domain() with calls to
 a new pci_root_bus_path() returning a string.  The new call is implemented
 in terms of a new callback in the host bridge class, so it can be defined
 in some way that's well defined for the platform.  When no callback is
 available we fall back on the qbus name.
 
 Most current uses of pci_find_domain() are for error or informational
 messages, so the change in identifiers should be harmless.  The exception
 is pci_get_dev_path(), whose results form part of migration streams.  To
 maintain compatibility with old migration streams, the PIIX PCI host is
 altered to always supply  for this path, which matches the old domain
 number (since the code didn't actually support domains other than 0).
 
 For the pseries (spapr) PCI bridge we use a different platform-unique
 identifier (pseries machines can routinely have dozens of PCI host
 bridges).  Theoretically that breaks migration streams, but given that we
 don't yet have migration support for pseries, it doesn't matter.
 
 Any other machines that have working migration support including PCI
 devices will need to be updated to maintain migration stream compatibility.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au

AFAIK PC is the only one with working migration, yes, but
we have Q35 as well which can be migrated.

 ---
  hw/pci-host/piix.c|9 +
  hw/pci/pci-hotplug-old.c  |4 ++--
  hw/pci/pci.c  |   38 --
  hw/pci/pci_host.c |1 +
  hw/pci/pcie_aer.c |8 
  hw/ppc/spapr_pci.c|   10 ++
  include/hw/pci/pci.h  |2 +-
  include/hw/pci/pci_host.h |   10 ++
  8 files changed, 57 insertions(+), 25 deletions(-)
 
 diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
 index f9e68c3..c36e725 100644
 --- a/hw/pci-host/piix.c
 +++ b/hw/pci-host/piix.c
 @@ -629,11 +629,20 @@ static const TypeInfo i440fx_info = {
  .class_init= i440fx_class_init,
  };
  
 +static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
 +PCIBus *rootbus)
 +{
 +/* For backwards compat with old device paths */
 +return ;
 +}
 +
  static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
  {
  DeviceClass *dc = DEVICE_CLASS(klass);
  SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 +PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
  
 +hc-root_bus_path = i440fx_pcihost_root_bus_path;
  k-init = i440fx_pcihost_initfn;
  dc-fw_name = pci;
  dc-no_user = 1;
 diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
 index 98b4c18..d26674d 100644
 --- a/hw/pci/pci-hotplug-old.c
 +++ b/hw/pci/pci-hotplug-old.c
 @@ -273,8 +273,8 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
  }
  
  if (dev) {
 -monitor_printf(mon, OK domain %d, bus %d, slot %d, function %d\n,
 -   pci_find_domain(dev),
 +monitor_printf(mon, OK root bus %s, bus %d, slot %d, function %d\n,
 +   pci_root_bus_path(dev),
 pci_bus_num(dev-bus), PCI_SLOT(dev-devfn),
 PCI_FUNC(dev-devfn));
  } else
 diff --git a/hw/pci/pci.c b/hw/pci/pci.c
 index f1cee73..a3c192c 100644
 --- a/hw/pci/pci.c
 +++ b/hw/pci/pci.c
 @@ -25,6 +25,7 @@
  #include hw/pci/pci.h
  #include hw/pci/pci_bridge.h
  #include hw/pci/pci_bus.h
 +#include hw/pci/pci_host.h
  #include monitor/monitor.h
  #include net/net.h
  #include sysemu/sysemu.h
 @@ -270,19 +271,20 @@ PCIBus *pci_device_root_bus(const PCIDevice *d)
  return bus;
  }
  
 -int pci_find_domain(const PCIDevice *dev)
 +const char *pci_root_bus_path(PCIDevice *dev)
  {
 -const PCIBus *rootbus = pci_device_root_bus(dev);
 -struct PCIHostBus *host;
 +PCIBus *rootbus = pci_device_root_bus(dev);
 +PCIHostState *host_bridge = PCI_HOST_BRIDGE(rootbus-qbus.parent);
 +PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_GET_CLASS(host_bridge);
  
 -QLIST_FOREACH(host, host_buses, next) {
 -if (host-bus == rootbus) {
 -return host-domain;
 -}
 +assert(!rootbus-parent_dev);
 +assert(host_bridge-bus == rootbus);
 +
 +if (hc-root_bus_path) {
 +return (*hc-root_bus_path)(host_bridge, rootbus);
  }
  
 -abort();/* should not be reached */
 -return -1;
 +return rootbus-qbus.name;
  }
  
  static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 @@ -2005,10 +2007,10 @@ int pci_add_capability(PCIDevice *pdev, uint8_t 
 cap_id,
  

Re: [Qemu-devel] [PATCH 1/8] pci: Cleanup configuration for pci-hotplug.c

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:05AM +1000, David Gibson wrote:
 pci-hotplug.c and the CONFIG_PCI_HOTPLUG variable which controls its
 compilation are misnamed.  They're not about PCI hotplug in general, but
 rather about the pci_add/pci_del interface which are now deprecated in
 favour of the more general device_add/device_del interface.  This patch
 therefore renames them to pci-hotplug-old.c and CONFIG_PCI_HOTPLUG_OLD.
 
 CONFIG_PCI_HOTPLUG=y was listed twice in {i386,x86_64}-softmmu.make for no
 particular reason, so we clean that up too.  In addition it was included in
 ppc64-softmmu.mak for which the old hotplug interface was never used and is
 unsuitable, so we remove that too.
 
 Most of pci-hotplug.c was additionaly protected by #ifdef TARGET_I386.  The
 small piece which wasn't is only called from the pci_add and pci_del hooks
 in hmp-commands.hx, which themselves were protected by #ifdef TARGET_I386.
 This patch therefore also removes the #ifdef from pci-hotplug-old.c,
 and changes the ifdefs in hmp-commands.hx to use CONFIG_PCI_HOTPLUG_OLD.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 ---
  default-configs/i386-softmmu.mak   |3 +-
  default-configs/ppc64-softmmu.mak  |2 -
  default-configs/x86_64-softmmu.mak |3 +-
  hmp-commands.hx|4 +-
  hw/pci/Makefile.objs   |2 +-
  hw/pci/pci-hotplug-old.c   |  290 +++
  hw/pci/pci-hotplug.c   |  292 
 
  7 files changed, 295 insertions(+), 301 deletions(-)
  create mode 100644 hw/pci/pci-hotplug-old.c
  delete mode 100644 hw/pci/pci-hotplug.c
 
 diff --git a/default-configs/i386-softmmu.mak 
 b/default-configs/i386-softmmu.mak
 index 03deca2..4a0fc9c 100644
 --- a/default-configs/i386-softmmu.mak
 +++ b/default-configs/i386-softmmu.mak
 @@ -28,11 +28,10 @@ CONFIG_APPLESMC=y
  CONFIG_I8259=y
  CONFIG_PFLASH_CFI01=y
  CONFIG_TPM_TIS=$(CONFIG_TPM)
 -CONFIG_PCI_HOTPLUG=y
 +CONFIG_PCI_HOTPLUG_OLD=y
  CONFIG_MC146818RTC=y
  CONFIG_PAM=y
  CONFIG_PCI_PIIX=y
 -CONFIG_PCI_HOTPLUG=y
  CONFIG_WDT_IB700=y
  CONFIG_PC_SYSFW=y
  CONFIG_XEN_I386=$(CONFIG_XEN)
 diff --git a/default-configs/ppc64-softmmu.mak 
 b/default-configs/ppc64-softmmu.mak
 index 884ea8a..d7140c4 100644
 --- a/default-configs/ppc64-softmmu.mak
 +++ b/default-configs/ppc64-softmmu.mak
 @@ -44,7 +44,5 @@ CONFIG_XILINX_ETHLITE=y
  CONFIG_OPENPIC=y
  CONFIG_PSERIES=$(CONFIG_FDT)
  CONFIG_E500=$(CONFIG_FDT)
 -# For pSeries
 -CONFIG_PCI_HOTPLUG=y
  # For PReP
  CONFIG_MC146818RTC=y
 diff --git a/default-configs/x86_64-softmmu.mak 
 b/default-configs/x86_64-softmmu.mak
 index 599b630..10bb0c6 100644
 --- a/default-configs/x86_64-softmmu.mak
 +++ b/default-configs/x86_64-softmmu.mak
 @@ -28,11 +28,10 @@ CONFIG_APPLESMC=y
  CONFIG_I8259=y
  CONFIG_PFLASH_CFI01=y
  CONFIG_TPM_TIS=$(CONFIG_TPM)
 -CONFIG_PCI_HOTPLUG=y
 +CONFIG_PCI_HOTPLUG_OLD=y
  CONFIG_MC146818RTC=y
  CONFIG_PAM=y
  CONFIG_PCI_PIIX=y
 -CONFIG_PCI_HOTPLUG=y
  CONFIG_WDT_IB700=y
  CONFIG_PC_SYSFW=y
  CONFIG_XEN_I386=$(CONFIG_XEN)
 diff --git a/hmp-commands.hx b/hmp-commands.hx
 index 9cea415..1d88320 100644
 --- a/hmp-commands.hx
 +++ b/hmp-commands.hx
 @@ -1077,7 +1077,7 @@ STEXI
  Add drive to PCI storage controller.
  ETEXI
  
 -#if defined(TARGET_I386)
 +#if defined(CONFIG_PCI_HOTPLUG_OLD)
  {
  .name   = pci_add,
  .args_type  = pci_addr:s,type:s,opts:s?,
 @@ -1093,7 +1093,7 @@ STEXI
  Hot-add PCI device.
  ETEXI
  
 -#if defined(TARGET_I386)
 +#if defined(CONFIG_PCI_HOTPLUG_OLD)
  {
  .name   = pci_del,
  .args_type  = pci_addr:s,
 diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
 index a7fb9d0..2ad32b6 100644
 --- a/hw/pci/Makefile.objs
 +++ b/hw/pci/Makefile.objs
 @@ -8,4 +8,4 @@ common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
  common-obj-$(CONFIG_NO_PCI) += pci-stub.o
  common-obj-$(CONFIG_ALL) += pci-stub.o
  
 -obj-$(CONFIG_PCI_HOTPLUG) += pci-hotplug.o
 +obj-$(CONFIG_PCI_HOTPLUG_OLD) += pci-hotplug-old.o
 diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
 new file mode 100644
 index 000..724a80b
 --- /dev/null
 +++ b/hw/pci/pci-hotplug-old.c

Please use git format-patch -M so renames are
properly shown. I can't see whether anything changed here.

 @@ -0,0 +1,290 @@
 +/*
 + * QEMU PCI hotplug support

I don't particularly mind whether it's called pci-hotplug or
pci-hotplug-old, but I'm prepared to go with you on this.
However, what we really should do is fix the comment
to match reality.

I think this needs two commits:
- fix comment
- rename

to make format-patch -M detect this as a rename

 + *
 + * Copyright (c) 2004 Fabrice Bellard
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a 
 copy
 + * of this software and associated documentation files (the Software), to 
 deal
 + * in the Software without restriction, including without limitation the 
 rights
 + * to use, 

Re: [Qemu-devel] [0/8] Clean up PCI code to allow for multiple root buses

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:04AM +1000, David Gibson wrote:
 The current PCI subsystem has kind of half-hearted support for
 multiple independent root buses - aka PCI domains - in the form of the
 PCIHostBus structure and its domain field.  However, it doesn't quite
 work because pci_host_bus_register() is always called with a domain of
 0.
 
 Worse, though, the whole concept of numbered domains isn't general
 enough.  Many platforms can have independent root buses (usually on
 wholly independent host bridges), but only x86 gives them a
 hardware-significant domain number, essentially as a hack to allow all
 the separate config spaces to be accessed via the same IO ports.
 Linux guests on other platforms will show domain numbers in lspci, but
 these are purely guest assigned, so qemu won't know about them.
 
 This patch series, therefore, removes the broken-as-is domain concept
 from qemu, and replaces it with a different way of handling multiple
 root buses, based on a host bridge class method to provide a
 identifier for the root bus.  This hook is designed in such a way as
 to allow a single bridge object to support mutiple root buses with
 future changes, which will allow future implementations of x86 north
 bridges with multiple domains to be supported correctly, and in way
 that matches the existing practice for all external interfaces.

I agree with the direction this patchset takes.
I sent some comments on the individual patches separately.

Thanks!


-- 
MST



Re: [Qemu-devel] [PATCH 6/8] pci: Simpler implementation of primary PCI bus

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:10AM +1000, David Gibson wrote:
 Currently pci_get_primary_bus() searches the list of root buses for one
 with domain 0.  But since host buses are always registered with domain 0,
 this just amounts to finding the only PCI host bus.
 
 This simplifies the implementation by defining the primary PCI bus to
 be the first one registered, using a global variable to track it.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au

Or better: can we just fail if there is more than
one root?

 ---
  hw/pci/pci.c |   18 +-
  1 file changed, 9 insertions(+), 9 deletions(-)
 
 diff --git a/hw/pci/pci.c b/hw/pci/pci.c
 index a3c192c..b25a1a1 100644
 --- a/hw/pci/pci.c
 +++ b/hw/pci/pci.c
 @@ -96,6 +96,7 @@ struct PCIHostBus {
  QLIST_ENTRY(PCIHostBus) next;
  };
  static QLIST_HEAD(, PCIHostBus) host_buses;
 +static PCIBus *pci_primary_bus;
  
  static const VMStateDescription vmstate_pcibus = {
  .name = PCIBUS,
 @@ -241,6 +242,12 @@ static int pcibus_reset(BusState *qbus)
  static void pci_host_bus_register(int domain, PCIBus *bus)
  {
  struct PCIHostBus *host;
 +
 +/* If this is the first one, assume it's the primary bus */
 +if (!pci_primary_bus) {
 +pci_primary_bus = bus;
 +}
 +
  host = g_malloc0(sizeof(*host));
  host-domain = domain;
  host-bus = bus;
 @@ -249,15 +256,7 @@ static void pci_host_bus_register(int domain, PCIBus 
 *bus)
  
  PCIBus *pci_get_primary_bus(void)
  {
 -struct PCIHostBus *host;
 -
 -QLIST_FOREACH(host, host_buses, next) {
 -if (host-domain == 0) {
 -return host-bus;
 -}
 -}
 -
 -return NULL;
 +return pci_primary_bus;
  }
  
  PCIBus *pci_device_root_bus(const PCIDevice *d)
 @@ -300,6 +299,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
  
  /* host bridge */
  QLIST_INIT(bus-child);
 +
  pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported 
 */
  
  vmstate_register(NULL, -1, vmstate_pcibus, bus);
 -- 
 1.7.10.4



Re: [Qemu-devel] [PATCH v2] wdt_i6300esb: fix vmstate versioning

2013-05-23 Thread Amit Shah
On (Wed) 22 May 2013 [11:32:51], Michael Roth wrote:
 When this VMSD was introduced it's version fields were set to
 sizeof(I6300State), making them essentially random from build to build,
 version to version.
 
 To fix this, we lock in a high version id and low minimum version id to
 support old-new migration from all prior versions of this device's
 state. This should work since the device state has not changed since
 its introduction.
 
 The potentially breaks migration from 1.5+ to 1.5, but since the
 versioning was essentially random prior to this patch, new-old
 migration was not consistently functional to begin with.
 
 Reported-by: Nicholas Thomas n...@bytemark.co.uk
 Suggested-by: Peter Maydell peter.mayd...@linaro.org
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
 ---
 v2:
  * Fixed s/except/accept/ typo (Laszlo)

Reviewed-by: Amit Shah amit.s...@redhat.com

Amit



Re: [Qemu-devel] [PATCH 3/8] pci: Abolish pci_find_root_bus()

2013-05-23 Thread Michael S. Tsirkin
On Thu, May 09, 2013 at 10:31:07AM +1000, David Gibson wrote:
 pci_find_root_bus() takes a domain parameter.  Currently PCI root buses
 with domain other than 0 can't be created, so this is more or less a long
 winded way of retrieving the main PCI root bus.  Numbered domains don't
 actually properly cover the (non x86) possibilities for multiple PCI root
 buses, so this patch for now enforces the domain == 0 restriction in other
 places to replace pci_find_root_bus() with an explicit
 pci_get_primary_bus().
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au

Can we instead just drop the domain parameter
from pci_find_root_bus and add a comment
saying that it fails if there is more than one root?


 ---
  hw/pci/pci-hotplug-old.c |   34 +-
  hw/pci/pci.c |   19 +++
  include/hw/pci/pci.h |2 +-
  3 files changed, 41 insertions(+), 14 deletions(-)
 
 diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
 index 1aa0ab8..55441c6 100644
 --- a/hw/pci/pci-hotplug-old.c
 +++ b/hw/pci/pci-hotplug-old.c
 @@ -34,17 +34,23 @@
  #include sysemu/blockdev.h
  #include qapi/error.h
  
 -static int pci_read_devaddr(Monitor *mon, const char *addr, int *domp,
 +static int pci_read_devaddr(Monitor *mon, const char *addr,
  int *busp, unsigned *slotp)
  {
 +int dom;
 +
  /* strip legacy tag */
  if (!strncmp(addr, pci_addr=, 9)) {
  addr += 9;
  }
 -if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
 +if (pci_parse_devaddr(addr, dom, busp, slotp, NULL)) {
  monitor_printf(mon, Invalid pci address\n);
  return -1;
  }
 +if (dom != 0) {
 +monitor_printf(mon, Multiple PCI domains not supported, use 
 device_add\n);
 +return -1;
 +}
  return 0;
  }
  
 @@ -126,18 +132,22 @@ static int scsi_hot_add(Monitor *mon, DeviceState 
 *adapter,
  
  int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo)
  {
 -int dom, pci_bus;
 +int pci_bus;
  unsigned slot;
 +PCIBus *root = pci_get_primary_bus();
  PCIDevice *dev;
  const char *pci_addr = qdict_get_str(qdict, pci_addr);
  
  switch (dinfo-type) {
  case IF_SCSI:
 -if (pci_read_devaddr(mon, pci_addr, dom, pci_bus, slot)) {
 +if (!root) {
 +monitor_printf(mon, no primary PCI bus\n);
 +goto err;
 +}
 +if (pci_read_devaddr(mon, pci_addr, pci_bus, slot)) {
  goto err;
  }
 -dev = pci_find_device(pci_find_root_bus(dom), pci_bus,
 -  PCI_DEVFN(slot, 0));
 +dev = pci_find_device(root, pci_bus, PCI_DEVFN(slot, 0));
  if (!dev) {
  monitor_printf(mon, no pci device with address %s\n, pci_addr);
  goto err;
 @@ -273,16 +283,22 @@ void pci_device_hot_add(Monitor *mon, const QDict 
 *qdict)
  
  static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
  {
 +PCIBus *root = pci_get_primary_bus();
  PCIDevice *d;
 -int dom, bus;
 +int bus;
  unsigned slot;
  Error *local_err = NULL;
  
 -if (pci_read_devaddr(mon, pci_addr, dom, bus, slot)) {
 +if (!root) {
 +monitor_printf(mon, no primary PCI bus\n);
 +return -1;
 +}
 +
 +if (pci_read_devaddr(mon, pci_addr, bus, slot)) {
  return -1;
  }
  
 -d = pci_find_device(pci_find_root_bus(dom), bus, PCI_DEVFN(slot, 0));
 +d = pci_find_device(root, bus, PCI_DEVFN(slot, 0));
  if (!d) {
  monitor_printf(mon, slot %d empty\n, slot);
  return -1;
 diff --git a/hw/pci/pci.c b/hw/pci/pci.c
 index 9906e84..9503d56 100644
 --- a/hw/pci/pci.c
 +++ b/hw/pci/pci.c
 @@ -246,12 +246,12 @@ static void pci_host_bus_register(int domain, PCIBus 
 *bus)
  QLIST_INSERT_HEAD(host_buses, host, next);
  }
  
 -PCIBus *pci_find_root_bus(int domain)
 +PCIBus *pci_get_primary_bus(void)
  {
  struct PCIHostBus *host;
  
  QLIST_FOREACH(host, host_buses, next) {
 -if (host-domain == domain) {
 +if (host-domain == 0) {
  return host-bus;
  }
  }
 @@ -583,20 +583,31 @@ int pci_parse_devaddr(const char *addr, int *domp, int 
 *busp,
  
  PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
  {
 +PCIBus *root = pci_get_primary_bus();
  int dom, bus;
  unsigned slot;
  
 +if (!root) {
 +fprintf(stderr, No primary PCI bus\n);
 +return NULL;
 +}
 +
  if (!devaddr) {
  *devfnp = -1;
 -return pci_find_bus_nr(pci_find_root_bus(0), 0);
 +return pci_find_bus_nr(root, 0);
  }
  
  if (pci_parse_devaddr(devaddr, dom, bus, slot, NULL)  0) {
  return NULL;
  }
  
 +if (dom != 0) {
 +fprintf(stderr, No support for non-zero PCI domains\n);
 +return NULL;
 +}
 +
  *devfnp = PCI_DEVFN(slot, 0);
 -return 

Re: [Qemu-devel] [PATCH] wdt_i6300esb: fix vmstate versioning

2013-05-23 Thread Amit Shah
On (Tue) 21 May 2013 [17:32:57], Michael Roth wrote:
 When this VMSD was introduced it's version fields were set to
 sizeof(I6300State), making them essentially random from build to build,
 version to version.
 
 To fix this, we lock in a high version id and low minimum version id to
 support old-new migration from all prior versions of this device's
 state. This should work since the device state has not changed since
 its introduction.
 
 The potentially breaks migration from 1.5+ to 1.5, but since the
 versioning was essentially random prior to this patch, new-old
 migration was not consistently functional to begin with.
 
 Reported-by: Nicholas Thomas n...@bytemark.co.uk
 Suggested-by: Peter Maydell peter.mayd...@linaro.org
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

Please fix the comment below per Laszlo's comment, and you can add:

Reviewed-by: Amit Shah amit.s...@redhat.com

Amit



[Qemu-devel] [PATCH] s390/ipl: Fix spurious errors in virtio

2013-05-23 Thread Christian Borntraeger
With the ccw ipl code sometimes an error message like
virtio: trying to map MMIO memory or
Guest moved used index from %u to %u appeared. Turns out
that the ccw bios did not zero out the vring, which might
cause stale values in avail-idx and friends, especially
on reboot.

Lets zero out the relevant fields. To activate the patch we
need to rebuild s390-ccw.img as well.

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 pc-bios/s390-ccw/virtio.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
index 5b9e1dc..f438af1 100644
--- a/pc-bios/s390-ccw/virtio.c
+++ b/pc-bios/s390-ccw/virtio.c
@@ -114,8 +114,13 @@ static void vring_init(struct vring *vr, unsigned int num, 
void *p,
 vr-used = (void *)(((unsigned long)vr-avail-ring[num] + align-1)
  ~(align - 1));
 
+/* Zero out all relevant field */
+vr-avail-flags = 0;
+vr-avail-idx = 0;
+
 /* We're running with interrupts off anyways, so don't bother */
 vr-used-flags = VRING_USED_F_NO_NOTIFY;
+vr-used-idx = 0;
 
 debug_print_addr(init vr, vr);
 }
-- 
1.8.1.4




Re: [Qemu-devel] QMP interface for drive-add (or even blockdev-add)

2013-05-23 Thread Stefan Hajnoczi
On Wed, May 22, 2013 at 03:53:05PM +0200, Kevin Wolf wrote:
 Am 16.05.2013 um 21:05 hat Eric Blake geschrieben:
  On 05/16/2013 02:24 AM, Kevin Wolf wrote:
 The other thing that I'm not sure about is whether we should teach QAPI
 to parse certain data structures just into QDicts instead of C structs,
 or if dealing with the big unions inside the block layer actually makes
 sense.

This is an interesting question.  It's very convenient from the code
side - we don't have to worry about laying down a schema.

However, the point of QAPI is to offer that schema that allows for us to
reason about things like compatibility (hard to sneak in a patch that
modifies the schema, easy to sneak in a patch that modifies block driver
parameter code) and eliminates the boilerplate of type-checking/basic
input validation.

Even if it requires some effort, I think we should avoid tunneling
schema-less data over QAPI.

Stefan



Re: [Qemu-devel] [PATCH 0/2] coroutine: dataplane support

2013-05-23 Thread Stefan Hajnoczi
On Fri, May 17, 2013 at 03:51:24PM +0200, Stefan Hajnoczi wrote:
 There is ongoing work to enable multiple event loop threads.  This will allow
 QEMU itself to take advantage of SMP and reduce Big QEMU Lock (BQL) 
 contention.
 This series is one step in that effort.
 
 These patches make coroutines safe in a multi-event loop/multi-threaded world.
 I have successfully tested them running qcow2 in a dataplane thread (further
 patches are required which I'll be sending soon).
 
 Patch 1 protects the global coroutine freelist with a lock :).
 
 Patch 2 drops the CoQueue dependency on AioContext.  This allows CoMutex and
 CoRwlock to operate in a dataplane thread whereas previously we always
 scheduled coroutines in the QEMU iothread.
 
 Stefan Hajnoczi (2):
   coroutine: protect global pool with a mutex
   coroutine: stop using AioContext in CoQueue
 
  include/block/coroutine_int.h |  4 
  qemu-coroutine-lock.c | 56 
 ---
  qemu-coroutine.c  | 23 --
  trace-events  |  2 +-
  4 files changed, 47 insertions(+), 38 deletions(-)
 
 -- 
 1.8.1.4
 
 

Applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [Bug 1182490] [NEW] [qemu-1.5] coroutine-win32.c broken on NULL pointer

2013-05-23 Thread Stefan Hajnoczi
On Tue, May 21, 2013 at 02:11:05PM -, Cauchy Song wrote:
 Public bug reported:
 
 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 4340.0x163c]
 qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0, from_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 (gdb) bt
 #0  qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0,
 from_=0x3ba1c80) at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 #1  coroutine_trampoline (co_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:58
 #2  0x77098fed in ?? ()
 #3  0x in ?? ()

What is the command-line?

How do you reproduce the crash?

Stefan



Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Anthony Liguori
Kevin Wolf kw...@redhat.com writes:

 Am 22.05.2013 um 18:14 hat Anthony Liguori geschrieben:
 Kevin Wolf kw...@redhat.com writes:
  For example, libvirt wants to query which block drivers it can use. It
  doesn't really matter for which drivers we had the source initially, but
  only which drivers are compiled in (possibly loaded) and can actually be
  used.
 
 The schema is the wrong place to discover this.
 
 Loading a module wouldn't add an enumeration value.  The enumeration
 values are fixed.
 
 We should introduce commands to query this kind of information.
 
 Schema introspection is primarily useful for dynamic languages to
 autogenerate bindings.  It's not terribly useful for query
 capabilities/features.

 Then you won't get real modularity. It means that all modules must
 already be known during the build time, and if they aren't available
 (because they weren't built or aren't loaded) you include them anyway,
 some parts of them are a static part of the core. You don't get fully
 rid of modules by not linking their object file in, but you always have
 the QAPI part left over.

There are two things here: the schema and the generated code.  The
generated code can and should live in the module.

But the schema always stays the same.

Think of the schema like kernel headers.  The kernel headers are always
fixed regardless of what kernel modules are loaded or how the kernel is
configured.

 It also makes the schema totally useless. If you can't use it to tell
 which commands this qemu can execute and which it can't,

query-commands serves that purpose.

 then we don't need introspection at all. There's no user for it then.

Introspection is not the right approach to feature discovery.  The
schema does answer the question of what features are enabled, it just
answers the question of what the signature of the methods are.

 We can have hundreds of individual query commands like you suggest
 (query-qcow2-creation-option-values, yay!) or we do the modularity
 thing and the schema introspection properly and make it dynamic. I
 prefer the latter.

Let's consider a real example.  It sounds like you have something in
mind, can you be more specific?

Regards,

Anthony Liguori


 Kevin




Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event

2013-05-23 Thread Eric Blake
On 05/23/2013 03:07 AM, Amos Kong wrote:
 Introduce this new QMP event to notify management after guest changes
 rx-filter configuration.
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  QMP/qmp-events.txt| 14 ++
  include/monitor/monitor.h |  1 +
  monitor.c |  1 +
  3 files changed, 16 insertions(+)
 
 diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
 index 92fe5fb..ad6612b 100644
 --- a/QMP/qmp-events.txt
 +++ b/QMP/qmp-events.txt
 @@ -154,6 +154,20 @@ Data:
  path: /machine/peripheral/virtio-net-pci-0 },
timestamp: { seconds: 1265044230, microseconds: 450486 } }
  
 +RX_FILTER_CHANGED
 +-

 +
  DEVICE_TRAY_MOVED
  -

Isn't this file supposed to be kept in sorted order, to minimize merge
conflicts when backporting events?

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC PATCH v3 02/11] Fix errors and warnings while compiling with c++ compilier

2013-05-23 Thread Stefan Hajnoczi
On Tue, May 21, 2013 at 11:33:41AM -0400, Tomoki Sekiyama wrote:
 Add C++ keywords to avoid errors in compiling with c++ compiler.
 This also renames class member of PciDeviceInfo to q_class.
 
 Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
 ---
  hmp.c   |2 +-
  hw/pci/pci.c|2 +-
  scripts/qapi.py |9 -
  3 files changed, 10 insertions(+), 3 deletions(-)

Please also extend scripts/checkpatch.pl.  Otherwise it is very likely
that C++ keywords will be introduced again in the future.  Most people
will not build the VSS code and therefore checkpatch.pl needs to ensure
that patches with C++ keywords will not be accepted.

Stefan



Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information

2013-05-23 Thread Eric Blake
On 05/23/2013 03:08 AM, Amos Kong wrote:
 We want to implement mac programming over macvtap through Libvirt,
 related rx-filter configuration contains main mac, some of rx-mode
 and mac-table.
 
 The previous patch adds QMP event to notify management of rx-filter
 change. This patch adds a monitor command to query rx-filter
 information.
 
 A flag is used to avoid events flooding, if user don't query

s/don't/doesn't/

 rx-filter after receives one event, new events won't be sent

s/after/after it/

 to qmp monitor.
 
 +++ b/net/net.c
 @@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc)
 nc-info_str);
  }
  
 +RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
 +  Error **errp)
 +{
 +NetClientState *nc;
 +RxFilterInfoList *filter_list = NULL, *last_entry = NULL;
 +
 +QTAILQ_FOREACH(nc, net_clients, next) {
 +RxFilterInfoList *entry;
 +RxFilterInfo *info;
 +
 +if (nc-info-type != NET_CLIENT_OPTIONS_KIND_NIC) {
 +continue;
 +}
 +if (has_name  strcmp(nc-name, name) != 0) {

Do you need the has_name argument here, or can you ensure that the
caller passes NULL when the caller's has_name was false, for one less
parameter and the same amount of information?

 +++ b/qapi-schema.json
 @@ -3619,3 +3619,76 @@
  '*cpuid-input-ecx': 'int',
  'cpuid-register': 'X86CPURegister32',
  'features': 'int' } }
 +
 +##
 +# @RxState:
 +#
 +# Packets receiving state
 +#
 +# @normal: filter assigned packets according to the mac-table
 +#
 +# @no: don't receive any assigned packet
 +#
 +# @all: receive all assigned packets
 +#
 +##
 +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] }

I think s/no/none/ would make slightly more sense (usually, you pair
no/yes and none/all, not no/all).

 +
 +##
 +# @RxFilterInfo:
 +#
 +# Rx-filter information for a net client, it contains main mac, some
 +# of rx-mode items and mac-table.
 +#
 +# @name: net client name
 +#
 +# @promiscuous: whether to ether promiscuous mode

s/to ether//; s/$/is enabled/

 +#
 +# @multicast: multicast receive state
 +#
 +# @unicast: unicast receive state
 +#
 +# @broadcast-allowed: whether to receive broadcast
 +#
 +# @multicast-overflow: multicast table is overflow or not
 +#
 +# @unicast-overflow: unicast table is overflow or not
 +#
 +# @main-mac: the main macaddr string
 +#
 +# @unicast-table: a list of unicast macaddr string
 +#
 +# @multicast-table: a list of multicast macaddr string

Naming is reasonable; thanks for improving things from v1.

 +#
 +# Since 1.6
 +##
 +
 +{ 'type': 'RxFilterInfo',
 +  'data': {
 +'name':   'str',
 +'promiscuous':'bool',
 +'multicast':  'RxState',
 +'unicast':'RxState',
 +'broadcast-allowed':  'bool',
 +'multicast-overflow': 'bool',
 +'unicast-overflow':   'bool',
 +'main-mac':   'str',
 +'unicast-table':  ['str'],
 +'multicast-table':['str'] }}
 +
 +##
 +# @query-rx-filter:
 +#
 +# Return rx-filter information for all nics (or for the given nic).
 +#
 +# @name: #optional net client name
 +#
 +# Returns: list of @RxFilterInfo for all nics (or for the given nic).
 +#  Returns an error if the given @name doesn't exist, or given
 +#  nic doesn't support rx-filter querying, or no net client
 +#  supports rx-filter querying
 +#
 +# Since: 1.6
 +##
 +{ 'command': 'query-rx-filter', 'data': { '*name': 'str' },
 +  'returns': ['RxFilterInfo'] }

Interface looks reasonable.  I didn't check the code closely, but agree
with Michael's assessment that the event-suppression flag has to be
per-device, not global.

 +
 +Each array entry contains the following:
 +
 +- name: net client name (jaso-string)
 +- promiscuous: enter promiscuous mode (json-bool)
 +- multicast: multicast receive state (one of 'normal', 'no', 'all')
 +- unicast: unicast receive state  (one of 'normal', 'no', 'all')
 +- broadcast-allowed: allow to receive broadcast (json-bool)
 +- multicast-overflow: multicast table is overflow (json-bool)

s/is overflow/overflowed/

 +- unicast-overflow: unicast table is overflow (json-bool)

and again

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC PATCH v3 00/11] qemu-ga: fsfreeze on Windows using VSS

2013-05-23 Thread Stefan Hajnoczi
On Tue, May 21, 2013 at 11:33:33AM -0400, Tomoki Sekiyama wrote:
 * How to build  run qemu-ga with VSS support
 
  - Download Microsoft VSS SDK from:
http://www.microsoft.com/en-us/download/details.aspx?id=23490
 
  - Setup the SDK
scripts/extract-vsssdk-headers setup.exe (on POSIX-systems)
 
  - Specify installed SDK directory to configure option as:
./configure -with-vss-sdk=path/to/VSS SDK 
 --cross-prefix=i686-w64-mingw32-

Are there any plans to make this more developer-friendly?  In the Linux
world it's unusual to download third-party SDKs; development headers are
available as packages from the distro.

I haven't looked at the SDK license but hopefully the VSS headers can be
added to the mingw cross-build toolchain?

Stefan



[Qemu-devel] ANNOUNCE: libguestfs 1.22 has been released

2013-05-23 Thread Richard W.M. Jones
I'm pleased to announce the next stable release of libguestfs (1.22).

libguestfs is a set of tools for accessing and modifying virtual
machine disk images.  http://libguestfs.org/

This release represents 5 months of development and has many
significant new features including:

 - access remote disk images over nbd, ssh, http, ftp, iscsi, ceph, and more

 - syslinux and extlinux bootloader support

 - full support for btrfs guests

 - large performance improvements in virt-df and virt-alignment-scan tools

 - new bash completions for tools

 - many bug fixes

 - full release notes: http://libguestfs.org/guestfs-release-notes.1.html

Download source:
http://libguestfs.org/download/1.22-stable/
or: git clone git://github.com/libguestfs/libguestfs.git

Binaries will be available shortly for Fedora 19 in the Fedora repository.

Ubuntu 12.10  13.04 binary packages will be available shortly here:
http://libguestfs.org/download/binaries/

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/



[Qemu-devel] [PATCH 04/10] target-arm: Remove uses of gen_{ld, st}* from Neon code

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   46 --
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 7ce9a1c..057b180 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -2572,18 +2572,18 @@ static void gen_neon_dup_high16(TCGv_i32 var)
 static TCGv_i32 gen_load_and_replicate(DisasContext *s, TCGv_i32 addr, int 
size)
 {
 /* Load a single Neon element and replicate into a 32 bit TCG reg */
-TCGv_i32 tmp;
+TCGv_i32 tmp = tcg_temp_new_i32();
 switch (size) {
 case 0:
-tmp = gen_ld8u(addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 gen_neon_dup_u8(tmp, 0);
 break;
 case 1:
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 gen_neon_dup_low16(tmp);
 break;
 case 2:
-tmp = gen_ld32(addr, IS_USER(s));
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 break;
 default: /* Avoid compiler warnings.  */
 abort();
@@ -3872,18 +3872,22 @@ static int disas_neon_ls_insn(CPUARMState * env, 
DisasContext *s, uint32_t insn)
 for (pass = 0; pass  2; pass++) {
 if (size == 2) {
 if (load) {
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 neon_store_reg(rd, pass, tmp);
 } else {
 tmp = neon_load_reg(rd, pass);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_gen_addi_i32(addr, addr, stride);
 } else if (size == 1) {
 if (load) {
-tmp = gen_ld16u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 tcg_gen_addi_i32(addr, addr, stride);
-tmp2 = gen_ld16u(addr, IS_USER(s));
+tmp2 = tcg_temp_new_i32();
+tcg_gen_qemu_ld16u(tmp2, addr, IS_USER(s));
 tcg_gen_addi_i32(addr, addr, stride);
 tcg_gen_shli_i32(tmp2, tmp2, 16);
 tcg_gen_or_i32(tmp, tmp, tmp2);
@@ -3893,16 +3897,19 @@ static int disas_neon_ls_insn(CPUARMState * env, 
DisasContext *s, uint32_t insn)
 tmp = neon_load_reg(rd, pass);
 tmp2 = tcg_temp_new_i32();
 tcg_gen_shri_i32(tmp2, tmp, 16);
-gen_st16(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 tcg_gen_addi_i32(addr, addr, stride);
-gen_st16(tmp2, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp2, addr, IS_USER(s));
+tcg_temp_free_i32(tmp2);
 tcg_gen_addi_i32(addr, addr, stride);
 }
 } else /* size == 0 */ {
 if (load) {
 TCGV_UNUSED_I32(tmp2);
 for (n = 0; n  4; n++) {
-tmp = gen_ld8u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 tcg_gen_addi_i32(addr, addr, stride);
 if (n == 0) {
 tmp2 = tmp;
@@ -3922,7 +3929,8 @@ static int disas_neon_ls_insn(CPUARMState * env, 
DisasContext *s, uint32_t insn)
 } else {
 tcg_gen_shri_i32(tmp, tmp2, n * 8);
 }
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 tcg_gen_addi_i32(addr, addr, stride);
 }
 tcg_temp_free_i32(tmp2);
@@ -4042,15 +4050,16 @@ static int disas_neon_ls_insn(CPUARMState * env, 
DisasContext *s, uint32_t insn)
 load_reg_var(s, addr, rn);
 for (reg = 0; reg  nregs; reg++) {
 if (load) {
+tmp = tcg_temp_new_i32();
  

[Qemu-devel] [PATCH 00/10] target-arm: fix TCGv usage (AArch64 prep)

2013-05-23 Thread Peter Maydell
This patch series is preparatory cleanup for the impending
AArch64 support.

Patch 1 replaces all the uses of TCGv, tcg_temp_new(), etc in the
current 32 bit ARM decoder with the specifically-TCGv_i32 versions. 
This is necessary for supporting a 64-bit core, which will have
TARGET_LONG_BITS==64 (and so TCGv == TCGv_i64) but still wants 32 bit
vaddrs, register sizes, etc in the A32/T32/T16 instruction sets.  The
mechanical conversion is correct for everything except the arguments
to tcg_gen_qemu_{ld,st}*, which we handle separately later.

Patches 2-9 remove the gen_ld* and gen_st* helper functions in favour
of open-coding the creation/deletion of the TCG temp.  I think this
makes the code easier to understand because the temp creation and
deletion is all at the same level of the code and it reduces the
current confusing situation where some gen_ functions will destroy a
temp they're passed and some will not.  I think it also brings it
closer into line with other targets.  That said, if there's pushback
that this part of the patchset is going in the wrong direction I can
drop it.  (Conversely, if people like it then there are other
functions like load_reg() and store_reg() which could also be changed
not to create/destroy temporaries.)

Patch 10 fixes the load/store bits that patch 1 did not, by
abstracting out AArch32 load/store into gen functions which
extend/truncate the 32 bit values to 64 bits as necessary.  NB that
the TARGET_LONG_BITS==64 parts are only compile-tested.  I include it
in this series because it completes the work that patch 1 starts,
and as motivation/indication of direction.

Peter Maydell (10):
  target-arm: Don't use TCGv when we mean TCGv_i32
  target-arm: Remove gen_ld64() and gen_st64()
  target-arm: Remove uses of gen_{ld,st}* from iWMMXt code
  target-arm: Remove uses of gen_{ld,st}* from Neon code
  target-arm: Remove use of gen_{ld,st}* from ldrex/strex
  target-arm: Remove gen_{ld,st}* from basic ARM insns
  target-arm: Remove gen_{ld,st}* from Thumb insns
  target-arm: Remove gen_{ld,st}* from thumb2 decoder
  target-arm: Remove gen_{ld,st}* definitions
  target-arm: Abstract out load/store from a vaddr in AArch32

 target-arm/translate.c |  862 +++-
 1 file changed, 490 insertions(+), 372 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH 05/10] target-arm: Remove use of gen_{ld, st}* from ldrex/strex

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   31 ++-
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 057b180..3899d0a 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -6493,18 +6493,18 @@ static void gen_logicq_cc(TCGv_i32 lo, TCGv_i32 hi)
 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
TCGv_i32 addr, int size)
 {
-TCGv_i32 tmp;
+TCGv_i32 tmp = tcg_temp_new_i32();
 
 switch (size) {
 case 0:
-tmp = gen_ld8u(addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 break;
 case 1:
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 break;
 case 2:
 case 3:
-tmp = gen_ld32(addr, IS_USER(s));
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 break;
 default:
 abort();
@@ -6514,7 +6514,8 @@ static void gen_load_exclusive(DisasContext *s, int rt, 
int rt2,
 if (size == 3) {
 TCGv_i32 tmp2 = tcg_temp_new_i32();
 tcg_gen_addi_i32(tmp2, addr, 4);
-tmp = gen_ld32(tmp2, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, tmp2, IS_USER(s));
 tcg_temp_free_i32(tmp2);
 tcg_gen_mov_i32(cpu_exclusive_high, tmp);
 store_reg(s, rt2, tmp);
@@ -6553,16 +6554,17 @@ static void gen_store_exclusive(DisasContext *s, int 
rd, int rt, int rt2,
 fail_label = gen_new_label();
 done_label = gen_new_label();
 tcg_gen_brcond_i32(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
+tmp = tcg_temp_new_i32();
 switch (size) {
 case 0:
-tmp = gen_ld8u(addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 break;
 case 1:
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 break;
 case 2:
 case 3:
-tmp = gen_ld32(addr, IS_USER(s));
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 break;
 default:
 abort();
@@ -6572,7 +6574,8 @@ static void gen_store_exclusive(DisasContext *s, int rd, 
int rt, int rt2,
 if (size == 3) {
 TCGv_i32 tmp2 = tcg_temp_new_i32();
 tcg_gen_addi_i32(tmp2, addr, 4);
-tmp = gen_ld32(tmp2, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, tmp2, IS_USER(s));
 tcg_temp_free_i32(tmp2);
 tcg_gen_brcond_i32(TCG_COND_NE, tmp, cpu_exclusive_high, fail_label);
 tcg_temp_free_i32(tmp);
@@ -6580,22 +6583,24 @@ static void gen_store_exclusive(DisasContext *s, int 
rd, int rt, int rt2,
 tmp = load_reg(s, rt);
 switch (size) {
 case 0:
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
 break;
 case 1:
-gen_st16(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp, addr, IS_USER(s));
 break;
 case 2:
 case 3:
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
 break;
 default:
 abort();
 }
+tcg_temp_free_i32(tmp);
 if (size == 3) {
 tcg_gen_addi_i32(addr, addr, 4);
 tmp = load_reg(s, rt2);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_gen_movi_i32(cpu_R[rd], 0);
 tcg_gen_br(done_label);
-- 
1.7.9.5




[Qemu-devel] [PATCH 01/10] target-arm: Don't use TCGv when we mean TCGv_i32

2013-05-23 Thread Peter Maydell
TCGv changes size depending on the compile time value of
TARGET_LONG_BITS.  This is useful for generating code for MIPS style
instructions are the same but the register width changes CPUs, and
also for the generic bits of QEMU which operate on width of a
virtual address values, but mostly in the ARM target code we were
using it purely as a shorthand for any 32 bit value.

This needs to change in preparation for AArch64 support, since an
AArch64-capable v8 core will have 64 bit virtual addresses but still
use 32 bit values for the 32 bit instruction set.

This patch mechanically converts all the occurrences of TCGv,
tcg_temp_new(), tcg_temp_free(), tcg_temp_local_new() and
TCGV_UNUSED() to their explicitly 32 bit counterparts.  This is
correct for everything except the arguments to tcg_gen_qemu_{ld,st}*,
which really do need to be TCGv and so will require a 32-to-64
conversion when building the 32 bit code for AArch64.  Those changes
will be in a separate patch for easier review.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |  453 
 1 file changed, 229 insertions(+), 224 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index a1b7b8c..75972cf 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -95,7 +95,7 @@ static TCGv_i32 cpu_exclusive_info;
 #endif
 
 /* FIXME:  These should be removed.  */
-static TCGv cpu_F0s, cpu_F1s;
+static TCGv_i32 cpu_F0s, cpu_F1s;
 static TCGv_i64 cpu_F0d, cpu_F1d;
 
 #include exec/gen-icount.h
@@ -138,16 +138,16 @@ void arm_translate_init(void)
 #include helper.h
 }
 
-static inline TCGv load_cpu_offset(int offset)
+static inline TCGv_i32 load_cpu_offset(int offset)
 {
-TCGv tmp = tcg_temp_new_i32();
+TCGv_i32 tmp = tcg_temp_new_i32();
 tcg_gen_ld_i32(tmp, cpu_env, offset);
 return tmp;
 }
 
 #define load_cpu_field(name) load_cpu_offset(offsetof(CPUARMState, name))
 
-static inline void store_cpu_offset(TCGv var, int offset)
+static inline void store_cpu_offset(TCGv_i32 var, int offset)
 {
 tcg_gen_st_i32(var, cpu_env, offset);
 tcg_temp_free_i32(var);
@@ -157,7 +157,7 @@ static inline void store_cpu_offset(TCGv var, int offset)
 store_cpu_offset(var, offsetof(CPUARMState, name))
 
 /* Set a variable to the value of a CPU register.  */
-static void load_reg_var(DisasContext *s, TCGv var, int reg)
+static void load_reg_var(DisasContext *s, TCGv_i32 var, int reg)
 {
 if (reg == 15) {
 uint32_t addr;
@@ -173,16 +173,16 @@ static void load_reg_var(DisasContext *s, TCGv var, int 
reg)
 }
 
 /* Create a new temporary and set it to the value of a CPU register.  */
-static inline TCGv load_reg(DisasContext *s, int reg)
+static inline TCGv_i32 load_reg(DisasContext *s, int reg)
 {
-TCGv tmp = tcg_temp_new_i32();
+TCGv_i32 tmp = tcg_temp_new_i32();
 load_reg_var(s, tmp, reg);
 return tmp;
 }
 
 /* Set a CPU register.  The source must be a temporary and will be
marked as dead.  */
-static void store_reg(DisasContext *s, int reg, TCGv var)
+static void store_reg(DisasContext *s, int reg, TCGv_i32 var)
 {
 if (reg == 15) {
 tcg_gen_andi_i32(var, var, ~1);
@@ -202,9 +202,9 @@ static void store_reg(DisasContext *s, int reg, TCGv var)
 #define gen_uxtb16(var) gen_helper_uxtb16(var, var)
 
 
-static inline void gen_set_cpsr(TCGv var, uint32_t mask)
+static inline void gen_set_cpsr(TCGv_i32 var, uint32_t mask)
 {
-TCGv tmp_mask = tcg_const_i32(mask);
+TCGv_i32 tmp_mask = tcg_const_i32(mask);
 gen_helper_cpsr_write(cpu_env, var, tmp_mask);
 tcg_temp_free_i32(tmp_mask);
 }
@@ -213,16 +213,16 @@ static inline void gen_set_cpsr(TCGv var, uint32_t mask)
 
 static void gen_exception(int excp)
 {
-TCGv tmp = tcg_temp_new_i32();
+TCGv_i32 tmp = tcg_temp_new_i32();
 tcg_gen_movi_i32(tmp, excp);
 gen_helper_exception(cpu_env, tmp);
 tcg_temp_free_i32(tmp);
 }
 
-static void gen_smul_dual(TCGv a, TCGv b)
+static void gen_smul_dual(TCGv_i32 a, TCGv_i32 b)
 {
-TCGv tmp1 = tcg_temp_new_i32();
-TCGv tmp2 = tcg_temp_new_i32();
+TCGv_i32 tmp1 = tcg_temp_new_i32();
+TCGv_i32 tmp2 = tcg_temp_new_i32();
 tcg_gen_ext16s_i32(tmp1, a);
 tcg_gen_ext16s_i32(tmp2, b);
 tcg_gen_mul_i32(tmp1, tmp1, tmp2);
@@ -235,9 +235,9 @@ static void gen_smul_dual(TCGv a, TCGv b)
 }
 
 /* Byteswap each halfword.  */
-static void gen_rev16(TCGv var)
+static void gen_rev16(TCGv_i32 var)
 {
-TCGv tmp = tcg_temp_new_i32();
+TCGv_i32 tmp = tcg_temp_new_i32();
 tcg_gen_shri_i32(tmp, var, 8);
 tcg_gen_andi_i32(tmp, tmp, 0x00ff00ff);
 tcg_gen_shli_i32(var, var, 8);
@@ -247,7 +247,7 @@ static void gen_rev16(TCGv var)
 }
 
 /* Byteswap low halfword and sign extend.  */
-static void gen_revsh(TCGv var)
+static void gen_revsh(TCGv_i32 var)
 {
 tcg_gen_ext16u_i32(var, var);
 tcg_gen_bswap16_i32(var, var);
@@ -255,7 +255,7 @@ static void gen_revsh(TCGv var)
 }
 
 

[Qemu-devel] [PATCH 06/10] target-arm: Remove gen_{ld, st}* from basic ARM insns

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |  101 +---
 1 file changed, 69 insertions(+), 32 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 3899d0a..e5a2e4c 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -6646,10 +6646,12 @@ static void gen_srs(DisasContext *s,
 }
 tcg_gen_addi_i32(addr, addr, offset);
 tmp = load_reg(s, 14);
-gen_st32(tmp, addr, 0);
+tcg_gen_qemu_st32(tmp, addr, 0);
+tcg_temp_free_i32(tmp);
 tmp = load_cpu_field(spsr);
 tcg_gen_addi_i32(addr, addr, 4);
-gen_st32(tmp, addr, 0);
+tcg_gen_qemu_st32(tmp, addr, 0);
+tcg_temp_free_i32(tmp);
 if (writeback) {
 switch (amode) {
 case 0:
@@ -6792,9 +6794,11 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 if (offset)
 tcg_gen_addi_i32(addr, addr, offset);
 /* Load PC into tmp and CPSR into tmp2.  */
-tmp = gen_ld32(addr, 0);
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, 0);
 tcg_gen_addi_i32(addr, addr, 4);
-tmp2 = gen_ld32(addr, 0);
+tmp2 = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, 0);
 if (insn  (1  21)) {
 /* Base writeback.  */
 switch (i) {
@@ -7368,13 +7372,15 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
so it is good enough.  */
 addr = load_reg(s, rn);
 tmp = load_reg(s, rm);
+tmp2 = tcg_temp_new_i32();
 if (insn  (1  22)) {
-tmp2 = gen_ld8u(addr, IS_USER(s));
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp2, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
 } else {
-tmp2 = gen_ld32(addr, IS_USER(s));
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_ld32u(tmp2, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
 }
+tcg_temp_free_i32(tmp);
 tcg_temp_free_i32(addr);
 store_reg(s, rd, tmp2);
 }
@@ -7391,16 +7397,17 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 address_offset = 0;
 if (insn  (1  20)) {
 /* load */
+tmp = tcg_temp_new_i32();
 switch(sh) {
 case 1:
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 break;
 case 2:
-tmp = gen_ld8s(addr, IS_USER(s));
+tcg_gen_qemu_ld8s(tmp, addr, IS_USER(s));
 break;
 default:
 case 3:
-tmp = gen_ld16s(addr, IS_USER(s));
+tcg_gen_qemu_ld16s(tmp, addr, IS_USER(s));
 break;
 }
 load = 1;
@@ -7410,17 +7417,21 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 if (sh  1) {
 /* store */
 tmp = load_reg(s, rd);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 tcg_gen_addi_i32(addr, addr, 4);
 tmp = load_reg(s, rd + 1);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 load = 0;
 } else {
 /* load */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 tcg_gen_addi_i32(addr, addr, 4);
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 rd++;
 load = 1;
 }
@@ -7428,7 +7439,8 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 } else {
 /* store */
 tmp = load_reg(s, rd);
-

[Qemu-devel] [PATCH 07/10] target-arm: Remove gen_{ld, st}* from Thumb insns

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   71 +++-
 1 file changed, 46 insertions(+), 25 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index e5a2e4c..953c5fb 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -9217,7 +9217,8 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 val = ~(uint32_t)2;
 addr = tcg_temp_new_i32();
 tcg_gen_movi_i32(addr, val);
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 tcg_temp_free_i32(addr);
 store_reg(s, rd, tmp);
 break;
@@ -9412,37 +9413,43 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 tcg_gen_add_i32(addr, addr, tmp);
 tcg_temp_free_i32(tmp);
 
-if (op  3) /* store */
+if (op  3) { /* store */
 tmp = load_reg(s, rd);
+} else {
+tmp = tcg_temp_new_i32();
+}
 
 switch (op) {
 case 0: /* str */
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
 break;
 case 1: /* strh */
-gen_st16(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp, addr, IS_USER(s));
 break;
 case 2: /* strb */
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
 break;
 case 3: /* ldrsb */
-tmp = gen_ld8s(addr, IS_USER(s));
+tcg_gen_qemu_ld8s(tmp, addr, IS_USER(s));
 break;
 case 4: /* ldr */
-tmp = gen_ld32(addr, IS_USER(s));
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 break;
 case 5: /* ldrh */
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 break;
 case 6: /* ldrb */
-tmp = gen_ld8u(addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 break;
 case 7: /* ldrsh */
-tmp = gen_ld16s(addr, IS_USER(s));
+tcg_gen_qemu_ld16s(tmp, addr, IS_USER(s));
 break;
 }
-if (op = 3) /* load */
+if (op = 3) { /* load */
 store_reg(s, rd, tmp);
+} else {
+tcg_temp_free_i32(tmp);
+}
 tcg_temp_free_i32(addr);
 break;
 
@@ -9456,12 +9463,14 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 
 if (insn  (1  11)) {
 /* load */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 } else {
 /* store */
 tmp = load_reg(s, rd);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_temp_free_i32(addr);
 break;
@@ -9476,12 +9485,14 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 
 if (insn  (1  11)) {
 /* load */
-tmp = gen_ld8u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 } else {
 /* store */
 tmp = load_reg(s, rd);
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_temp_free_i32(addr);
 break;
@@ -9496,12 +9507,14 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 
 if (insn  (1  11)) {
 /* load */
-tmp = gen_ld16u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 } else {
 /* store */
 tmp = load_reg(s, rd);
-gen_st16(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_temp_free_i32(addr);
 break;
@@ -9515,12 +9528,14 @@ static void disas_thumb_insn(CPUARMState *env, 
DisasContext *s)
 
 if (insn  (1  11)) {
 /* load */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 } else {
 /* store */
 tmp = load_reg(s, rd);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_temp_free_i32(addr);
 break;
@@ -9586,12 +9601,14 @@ 

[Qemu-devel] [PATCH 08/10] target-arm: Remove gen_{ld, st}* from thumb2 decoder

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   30 --
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 953c5fb..0ca68fe 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -8134,18 +8134,22 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 }
 if (insn  (1  20)) {
 /* ldrd */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 store_reg(s, rs, tmp);
 tcg_gen_addi_i32(addr, addr, 4);
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 store_reg(s, rd, tmp);
 } else {
 /* strd */
 tmp = load_reg(s, rs);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 tcg_gen_addi_i32(addr, addr, 4);
 tmp = load_reg(s, rd);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 if (insn  (1  21)) {
 /* Base writeback.  */
@@ -8181,10 +8185,12 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 /* tbh */
 tcg_gen_add_i32(addr, addr, tmp);
 tcg_temp_free_i32(tmp);
-tmp = gen_ld16u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 } else { /* tbb */
 tcg_temp_free_i32(tmp);
-tmp = gen_ld8u(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 }
 tcg_temp_free_i32(addr);
 tcg_gen_shli_i32(tmp, tmp, 1);
@@ -8219,9 +8225,11 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 if ((insn  (1  24)) == 0)
 tcg_gen_addi_i32(addr, addr, -8);
 /* Load PC into tmp and CPSR into tmp2.  */
-tmp = gen_ld32(addr, 0);
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, 0);
 tcg_gen_addi_i32(addr, addr, 4);
-tmp2 = gen_ld32(addr, 0);
+tmp2 = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp2, addr, 0);
 if (insn  (1  21)) {
 /* Base writeback.  */
 if (insn  (1  24)) {
@@ -8259,7 +8267,8 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 continue;
 if (insn  (1  20)) {
 /* Load.  */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 if (i == 15) {
 gen_bx(s, tmp);
 } else if (i == rn) {
@@ -8271,7 +8280,8 @@ static int disas_thumb2_insn(CPUARMState *env, 
DisasContext *s, uint16_t insn_hw
 } else {
 /* Store.  */
 tmp = load_reg(s, i);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
+tcg_temp_free_i32(tmp);
 }
 tcg_gen_addi_i32(addr, addr, 4);
 }
-- 
1.7.9.5




Re: [Qemu-devel] [RFC PATCH v3 11/11] QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

2013-05-23 Thread Stefan Hajnoczi
On Tue, May 21, 2013 at 11:34:16AM -0400, Tomoki Sekiyama wrote:
 qemu-ga in Windows may return error message with multibyte characters
 when the guest OS language is set to other than English. To display such
 messages correctly, this encodes the message based on the locale settings.
 
 Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
 ---
  QMP/qmp.py |4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
 
 diff --git a/QMP/qmp.py b/QMP/qmp.py
 index c551df1..ee21819 100644
 --- a/QMP/qmp.py
 +++ b/QMP/qmp.py
 @@ -11,6 +11,7 @@
  import json
  import errno
  import socket
 +import locale
  
  class QMPError(Exception):
  pass
 @@ -133,7 +134,8 @@ class QEMUMonitorProtocol:
  def command(self, cmd, **kwds):
  ret = self.cmd(cmd, kwds)
  if ret.has_key('error'):
 -raise Exception(ret['error']['desc'])
 +enc = locale.getpreferredencoding()
 +raise Exception(ret['error']['desc'].encode(enc))

You should not need to explicitly encode the error descriptor.  The
error description should be UTF-8 on the wire and a Unicode Python
string in this script.

I think the real problem is:

1. Guest qga is writing strings in local encoding onto the wire.

or

2. qmp.py isn't UTF-8-decoding strings received over the wire.

Either or both bugs could be present.  Once they are fixed you shouldn't
see encoding problems.

Stefan



[Qemu-devel] [PATCH 10/10] target-arm: Abstract out load/store from a vaddr in AArch32

2013-05-23 Thread Peter Maydell
AArch32 code (ie traditional 32 bit world) expects to be
able to pass a vaddr in a TCGv_i32. However when QEMU is
compiled with TARGET_LONG_BITS=32 the TCG load/store
functions take a TCGv_i64. Abstract out load/store with
a 32 bit vaddr so we have a place to put the zero extension
of the vaddr and the extension/truncation of the data value.

Apart from the function definitions most of this patch is
a simple s/tcg_gen_qemu_/gen_aa32_/.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |  309 ++--
 1 file changed, 197 insertions(+), 112 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 71135bd..426e22a 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -841,6 +841,89 @@ static inline void store_reg_from_load(CPUARMState *env, 
DisasContext *s,
 }
 }
 
+/* Abstractions of generate code to do a guest load/store for
+ * AArch32, where a vaddr is always 32 bits (and is zero
+ * extended if we're a 64 bit core) and  data is also
+ * 32 bits unless specifically doing a 64 bit access.
+ * These functions work like tcg_gen_qemu_{ld,st}* except
+ * that their arguments are TCGv_i32 rather than TCGv.
+ */
+#if TARGET_LONG_BITS == 32
+
+#define DO_GEN_LD(OP)\
+static inline void gen_aa32_##OP(TCGv_i32 val, TCGv_i32 addr, int index) \
+{\
+tcg_gen_qemu_##OP(val, addr, index); \
+}
+
+#define DO_GEN_ST(OP)\
+static inline void gen_aa32_##OP(TCGv_i32 val, TCGv_i32 addr, int index) \
+{\
+tcg_gen_qemu_##OP(val, addr, index); \
+}
+
+static inline void gen_aa32_ld64(TCGv_i64 val, TCGv_i32 addr, int index)
+{
+tcg_gen_qemu_ld64(val, addr, index);
+}
+
+static inline void gen_aa32_st64(TCGv_i64 val, TCGv_i32 addr, int index)
+{
+tcg_gen_qemu_st64(val, addr, index);
+}
+
+#else
+
+#define DO_GEN_LD(OP)\
+static inline void gen_aa32_##OP(TCGv_i32 val, TCGv_i32 addr, int index) \
+{\
+TCGv addr64 = tcg_temp_new();\
+TCGv val64 = tcg_temp_new(); \
+tcg_gen_extu_i32_i64(addr64, addr);  \
+tcg_gen_qemu_##OP(val64, addr64, index); \
+tcg_temp_free(addr64);   \
+tcg_gen_trunc_i64_i32(val, val64);   \
+tcg_temp_free(val64);\
+}
+
+#define DO_GEN_ST(OP)\
+static inline void gen_aa32_##OP(TCGv_i32 val, TCGv_i32 addr, int index) \
+{\
+TCGv addr64 = tcg_temp_new();\
+TCGv val64 = tcg_temp_new(); \
+tcg_gen_extu_i32_i64(addr64, addr);  \
+tcg_gen_extu_i32_i64(val64, val);\
+tcg_gen_qemu_##OP(val64, addr64, index); \
+tcg_temp_free(addr64);   \
+}
+
+static inline void gen_aa32_ld64(TCGv_i64 val, TCGv_i32 addr, int index)
+{
+TCGv addr64 = tcg_temp_new();
+tcg_gen_extu_i32_i64(addr64, addr);
+tcg_gen_qemu_ld64(val, addr64, index);
+tcg_temp_free(addr64);
+}
+
+static inline void gen_aa32_st64(TCGv_i64 val, TCGv_i32 addr, int index)
+{
+TCGv addr64 = tcg_temp_new();
+tcg_gen_extu_i32_i64(addr64, addr);
+tcg_gen_qemu_st64(val, addr64, index);
+tcg_temp_free(addr64);
+}
+
+#endif
+
+DO_GEN_LD(ld8s)
+DO_GEN_LD(ld8u)
+DO_GEN_LD(ld16s)
+DO_GEN_LD(ld16u)
+DO_GEN_LD(ld32u)
+DO_GEN_ST(st8)
+DO_GEN_ST(st16)
+DO_GEN_ST(st32)
+
 static inline void gen_set_pc_im(uint32_t val)
 {
 tcg_gen_movi_i32(cpu_R[15], val);
@@ -1070,18 +1153,20 @@ VFP_GEN_FIX(ulto)
 
 static inline void gen_vfp_ld(DisasContext *s, int dp, TCGv_i32 addr)
 {
-if (dp)
-tcg_gen_qemu_ld64(cpu_F0d, addr, IS_USER(s));
-else
-tcg_gen_qemu_ld32u(cpu_F0s, addr, IS_USER(s));
+if (dp) {
+gen_aa32_ld64(cpu_F0d, addr, IS_USER(s));
+} else {
+gen_aa32_ld32u(cpu_F0s, addr, IS_USER(s));
+}
 }
 
 static inline void gen_vfp_st(DisasContext *s, int dp, TCGv_i32 addr)
 {
-if (dp)
-tcg_gen_qemu_st64(cpu_F0d, addr, IS_USER(s));
-else
-tcg_gen_qemu_st32(cpu_F0s, addr, IS_USER(s));
+if (dp) {
+gen_aa32_st64(cpu_F0d, addr, IS_USER(s));
+} else {
+

[Qemu-devel] [PATCH 02/10] target-arm: Remove gen_ld64() and gen_st64()

2013-05-23 Thread Peter Maydell
gen_ld64() and gen_st64() are used only in one place, so just
expand them out.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 75972cf..8e46527 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -871,12 +871,6 @@ static inline TCGv_i32 gen_ld32(TCGv_i32 addr, int index)
 tcg_gen_qemu_ld32u(tmp, addr, index);
 return tmp;
 }
-static inline TCGv_i64 gen_ld64(TCGv_i32 addr, int index)
-{
-TCGv_i64 tmp = tcg_temp_new_i64();
-tcg_gen_qemu_ld64(tmp, addr, index);
-return tmp;
-}
 static inline void gen_st8(TCGv_i32 val, TCGv_i32 addr, int index)
 {
 tcg_gen_qemu_st8(val, addr, index);
@@ -892,11 +886,6 @@ static inline void gen_st32(TCGv_i32 val, TCGv_i32 addr, 
int index)
 tcg_gen_qemu_st32(val, addr, index);
 tcg_temp_free_i32(val);
 }
-static inline void gen_st64(TCGv_i64 val, TCGv_i32 addr, int index)
-{
-tcg_gen_qemu_st64(val, addr, index);
-tcg_temp_free_i64(val);
-}
 
 static inline void gen_set_pc_im(uint32_t val)
 {
@@ -3867,15 +3856,15 @@ static int disas_neon_ls_insn(CPUARMState * env, 
DisasContext *s, uint32_t insn)
 tcg_gen_addi_i32(addr, addr, 1  size);
 }
 if (size == 3) {
+tmp64 = tcg_temp_new_i64();
 if (load) {
-tmp64 = gen_ld64(addr, IS_USER(s));
+tcg_gen_qemu_ld64(tmp64, addr, IS_USER(s));
 neon_store_reg64(tmp64, rd);
-tcg_temp_free_i64(tmp64);
 } else {
-tmp64 = tcg_temp_new_i64();
 neon_load_reg64(tmp64, rd);
-gen_st64(tmp64, addr, IS_USER(s));
+tcg_gen_qemu_st64(tmp64, addr, IS_USER(s));
 }
+tcg_temp_free_i64(tmp64);
 tcg_gen_addi_i32(addr, addr, stride);
 } else {
 for (pass = 0; pass  2; pass++) {
-- 
1.7.9.5




[Qemu-devel] Designing QMP APIs at KVM Forum

2013-05-23 Thread Stefan Hajnoczi
With better QMP introspection on the horizon and work in various
subsystems pushing QMP boundaries it would be useful to bring together
the latest best practices for designing QMP APIs.

There are design rules for keeping QMP APIs extensible and for
allowing clients to detect the presence of features.  There is also
QEMU-side infrastructure like event rate-limiting, which developers
should make use of where appropriate.

Is anyone willing to bring together the best practices and present
them at KVM Forum this year?

I think that could help set the standard for QMP APIs.  A set of
slides or wiki page can be a reference to developers that stops us
working from first pricinples every time a new API is added.

Stefan



Re: [Qemu-devel] use O_DIRECT to open disk images for IDE failed under xen-4.1.2 and qemu upstream

2013-05-23 Thread Stefano Stabellini
On Thu, 23 May 2013, Gonglei (Arei) wrote:
 Hi, all
 
 I use O_DIRECT to open disk images for IDE, but I'm failed. After debug, I 
 get the below logs:
 [2013-05-22 23:25:46] ide: CMD=c8
 [2013-05-22 23:25:46] bmdma: readb 0x00 : 0x08
 [2013-05-22 23:25:46] bmdma: writeb 0x00 : 0x09
 [2013-05-22 23:25:46] bmdma_cmd_writeb: 0x0009
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:25:46] bmdma: readb 0x02 : 0x01
 [2013-05-22 23:26:39] bmdma: writeb 0x00 : 0x08
 [2013-05-22 23:26:39] bmdma_cmd_writeb: 0x0008
 [2013-05-22 23:26:56] == offset:0 buf:0x7ff100f21c00 count:512 
 aio_offset:0
 [2013-05-22 23:31:30] == offset:0 buf:0x7ff100f21c00 count:512 
 aio_offset:0
 [2013-05-22 23:31:30] == handle_aiocb_rw_linear errno: -14
 [2013-05-22 23:31:30] == paio_complete errno=14
 [2013-05-22 23:31:30] == ide_dma_error!!!
 [2013-05-22 23:31:30] ide: read status addr=0x3f6 val=41
 
 QEMU command line :
 qemu-system-i386 -xen-domid 837 -chardev 
 socket,id=libxl-cmd,path=/var/run/xen/qmp-libxl-837,server,nowait -mon 
 chardev=libxl-cmd,mode=control -name suse11 -vnc 0.0.0.0:1 -serial pty -boot 
 order=c -usb -usbdevice tablet -smp 2,maxcpus=2 -device 
 rtl8139,id=nic0,netdev=net0,mac=00:16:3e:13:d3:72 -netdev 
 type=tap,id=net0,ifname=tap837.0,downscript=no -M xenfv -m 2040 -drive 
 file=/mnt/sdd/image/suse.image,if=ide,index=0,media=disk,format=raw,cache=none
 
 errno 14 shows Bad Address. And I find QEMU_AIO_MISALIGNED flag bit is not 
 set through debug. 
 
 /*
  * If O_DIRECT is used the buffer needs to be aligned on a sector
  * boundary.  Check if this is the case or tell the low-level
  * driver that it needs to copy the buffer.
  */
 if ((bs-open_flags  BDRV_O_NOCACHE)) {
 if (!bdrv_qiov_is_aligned(bs, qiov)) {//if the address is 
 aligned-512, will no meet the conditions
 type |= QEMU_AIO_MISALIGNED;
 #ifdef CONFIG_LINUX_AIO
 } else if (s-use_aio) {
 return laio_submit(bs, s-aio_ctx, s-fd, sector_num, qiov,
nb_sectors, cb, opaque, type);
 #endif
 
 Next process:
 static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
 {
 ssize_t nbytes;
 char *buf;
 
 if (!(aiocb-aio_type  QEMU_AIO_MISALIGNED)) {
 /*
  * If there is just a single buffer, and it is properly aligned
  * we can just use plain pread/pwrite without any problems.
  */
 if (aiocb-aio_niov == 1)
  return handle_aiocb_rw_linear(aiocb, aiocb-aio_iov-iov_base); 
 //this way, and reports errno 14 next
 
 Anyone have a good method to resolve this bug? Thanks!
 
I know that this is not the answer you are looking for but why do you
want to use O_DIRECT with IDE?
It should be perfectly safe to use write-back.



Re: [Qemu-devel] [PATCH 0/4] ARM aarch64 TCG target VERSION 2

2013-05-23 Thread Andreas Färber
Hi,

Am 23.05.2013 10:09, schrieb Claudio Fontana:
 
 This series implements preliminary support for the ARM aarch64 TCG target.
[snip]

Generally, please post patch series without --in-reply-to= and use
--subject-prefix=PATCH v2 etc. plus a change log in the cover letter
to distinguish iterations.

http://wiki.qemu.org/Contribute/SubmitAPatch

If Big Endian targets are not yet supported, should this rather be an
RFC? Or is that just about some unimplemented opcodes?

Regards,
Andreas

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



Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Luiz Capitulino
On Thu, 23 May 2013 07:08:59 -0500
Anthony Liguori aligu...@us.ibm.com wrote:

  then we don't need introspection at all. There's no user for it then.
 
 Introspection is not the right approach to feature discovery.  The
 schema does answer the question of what features are enabled, it just
 answers the question of what the signature of the methods are.

(s/does answer/does not answer)

But there's an intersection here: a new enum value or new argument can
be a new feature too.

If we add new commands to query features, than I'm afraid that in the
long run feature discovery will be split in query-qmp-schema and the
specific feature discovery commands.

I'm not arguing in favor of one or another way, but we need to know
why and where we're going. The real motivation behind full introspection
is to allow commands to be extended.



[Qemu-devel] KVM call agenda for 2013-05-28

2013-05-23 Thread Michael S. Tsirkin
Juan is not available now, and Anthony asked for
agenda to be sent early.
So here comes:

Agenda for the meeting Tue, May 28:

- Generating acpi tables

- Switching the call to a bi-weekly schedule

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

Thanks, MST

-- 
MST



[Qemu-devel] [PATCH 09/10] target-arm: Remove gen_{ld, st}* definitions

2013-05-23 Thread Peter Maydell
All the uses of the gen_{ld,st}* functions are gone now, so remove
the functions themselves.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   46 --
 1 file changed, 46 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 0ca68fe..71135bd 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -841,52 +841,6 @@ static inline void store_reg_from_load(CPUARMState *env, 
DisasContext *s,
 }
 }
 
-static inline TCGv_i32 gen_ld8s(TCGv_i32 addr, int index)
-{
-TCGv_i32 tmp = tcg_temp_new_i32();
-tcg_gen_qemu_ld8s(tmp, addr, index);
-return tmp;
-}
-static inline TCGv_i32 gen_ld8u(TCGv_i32 addr, int index)
-{
-TCGv_i32 tmp = tcg_temp_new_i32();
-tcg_gen_qemu_ld8u(tmp, addr, index);
-return tmp;
-}
-static inline TCGv_i32 gen_ld16s(TCGv_i32 addr, int index)
-{
-TCGv_i32 tmp = tcg_temp_new_i32();
-tcg_gen_qemu_ld16s(tmp, addr, index);
-return tmp;
-}
-static inline TCGv_i32 gen_ld16u(TCGv_i32 addr, int index)
-{
-TCGv_i32 tmp = tcg_temp_new_i32();
-tcg_gen_qemu_ld16u(tmp, addr, index);
-return tmp;
-}
-static inline TCGv_i32 gen_ld32(TCGv_i32 addr, int index)
-{
-TCGv_i32 tmp = tcg_temp_new_i32();
-tcg_gen_qemu_ld32u(tmp, addr, index);
-return tmp;
-}
-static inline void gen_st8(TCGv_i32 val, TCGv_i32 addr, int index)
-{
-tcg_gen_qemu_st8(val, addr, index);
-tcg_temp_free_i32(val);
-}
-static inline void gen_st16(TCGv_i32 val, TCGv_i32 addr, int index)
-{
-tcg_gen_qemu_st16(val, addr, index);
-tcg_temp_free_i32(val);
-}
-static inline void gen_st32(TCGv_i32 val, TCGv_i32 addr, int index)
-{
-tcg_gen_qemu_st32(val, addr, index);
-tcg_temp_free_i32(val);
-}
-
 static inline void gen_set_pc_im(uint32_t val)
 {
 tcg_gen_movi_i32(cpu_R[15], val);
-- 
1.7.9.5




Re: [Qemu-devel] qemu seabios issue with vhost-scsi

2013-05-23 Thread Stefan Hajnoczi
On Wed, May 22, 2013 at 05:36:08PM -0700, Badari wrote:
 Hi,
 
 While testing vhost-scsi in the current qemu git, ran into an earlier issue
 with seabios. I had to disable scsi support in seabios to get it working.
 
 I was hoping this issue got resolved when vhost-scsi support got
 merged into qemu. Is this still being worked on ?
 
 Thanks,
 Badari
 
 [root ~]# gdb /root/qemu/x86_64-softmmu/qemu-system-x86_64
 GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
 Copyright (C) 2010 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later
 http://gnu.org/licenses/gpl.html
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type show copying
 and show warranty for details.
 This GDB was configured as x86_64-redhat-linux-gnu.
 For bug reporting instructions, please see:
 http://www.gnu.org/software/gdb/bugs/...
 Reading symbols from /root/qemu/x86_64-softmmu/qemu-system-x86_64...done.
 (gdb) run  --cpu qemu64 --enable-kvm  -m 4096 -drive
 file=/var/lib/libvirt/images/lnx.img,if=ide,cache=writethrough
 -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off -vnc
 :10 -boot d
 Starting program: /root/qemu/x86_64-softmmu/qemu-system-x86_64 --cpu
 qemu64 --enable-kvm  -m 4096 -drive
 file=/var/lib/libvirt/images/window.img,if=ide,cache=writethrough
 -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off -vnc
 :10 -boot d
 warning: no loadable sections found in added symbol-file
 system-supplied DSO at 0x77ffa000
 [Thread debugging using libthread_db enabled]
 [New Thread 0x71c1c700 (LWP 4725)]
 [New Thread 0x71239700 (LWP 4726)]
 [New Thread 0x7fffeb7ff700 (LWP 4729)]
 
 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 0x71239700 (LWP 4726)]
 0x556b3191 in scsi_device_find (bus=0x565abb50, channel=0, id=0,
 lun=0) at hw/scsi/scsi-bus.c:1744
 1744QTAILQ_FOREACH_REVERSE(kid, bus-qbus.children,
 ChildrenHead, sibling) {
 Missing separate debuginfos, use: debuginfo-install
 cyrus-sasl-gssapi-2.1.23-13.el6_3.1.x86_64
 cyrus-sasl-lib-2.1.23-13.el6_3.1.x86_64
 cyrus-sasl-md5-2.1.23-13.el6_3.1.x86_64
 cyrus-sasl-plain-2.1.23-13.el6_3.1.x86_64 db4-4.7.25-17.el6.x86_64
 glib2-2.22.5-7.el6.x86_64 glibc-2.12-1.107.el6.x86_64
 gnutls-2.8.5-10.el6.x86_64 keyutils-libs-1.4-4.el6.x86_64
 krb5-libs-1.10.3-10.el6.x86_64 libcom_err-1.41.12-14.el6.x86_64
 libcurl-7.19.7-35.el6.x86_64 libgcrypt-1.4.5-9.el6_2.2.x86_64
 libgpg-error-1.7-4.el6.x86_64 libidn-1.18-2.el6.x86_64
 libpng-1.2.49-1.el6_2.x86_64 libselinux-2.0.94-5.3.el6.x86_64
 libssh2-1.4.2-1.el6.x86_64 libtasn1-2.3-3.el6_2.1.x86_64
 ncurses-libs-5.7-3.20090208.el6.x86_64 nspr-4.9.2-1.el6.x86_64
 nss-3.14.0.0-12.el6.x86_64 nss-softokn-freebl-3.12.9-11.el6.x86_64
 nss-util-3.14.0.0-2.el6.x86_64 openldap-2.4.23-31.el6.x86_64
 openssl-1.0.0-27.el6.x86_64 pixman-0.26.2-4.el6.x86_64
 zlib-1.2.3-29.el6.x86_64
 (gdb) bt
 #0  0x556b3191 in scsi_device_find (bus=0x565abb50,
 channel=0, id=
 0, lun=0) at hw/scsi/scsi-bus.c:1744
 #1  0x557a59f0 in virtio_scsi_device_find (vdev=0x565aba38, vq=
 0x565d1150) at /root/qemu/hw/scsi/virtio-scsi.c:56
 #2  virtio_scsi_handle_cmd (vdev=0x565aba38, vq=0x565d1150)
 at /root/qemu/hw/scsi/virtio-scsi.c:376

We should never get here with vhost-scsi.  This function is processing
the command virtqueue in QEMU userspace - if vhost is active then we
shouldn't reach this.

AFAICT the s-bus was not initialized in the vhost codepath.  Therefore
the crash in scsi_device_find(bus, ...).

Can you check vhost_scsi_set_status() was called and if it successfully
enabled vhost?

Is it possible that the guest is notifying the virtqueue before setting
the status register to DRIVER_OK?  That would explain why vhost hasn't
been activated yet.

Stefan



[Qemu-devel] [PATCH 03/10] target-arm: Remove uses of gen_{ld, st}* from iWMMXt code

2013-05-23 Thread Peter Maydell
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |   18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 8e46527..7ce9a1c 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -1473,13 +1473,15 @@ static int disas_iwmmxt_insn(CPUARMState *env, 
DisasContext *s, uint32_t insn)
 tcg_gen_qemu_ld64(cpu_M0, addr, IS_USER(s));
 i = 0;
 } else {   /* WLDRW wRd */
-tmp = gen_ld32(addr, IS_USER(s));
+tmp = tcg_temp_new_i32();
+tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
 }
 } else {
+tmp = tcg_temp_new_i32();
 if (insn  (1  22)) {/* WLDRH */
-tmp = gen_ld16u(addr, IS_USER(s));
+tcg_gen_qemu_ld16u(tmp, addr, IS_USER(s));
 } else {   /* WLDRB */
-tmp = gen_ld8u(addr, IS_USER(s));
+tcg_gen_qemu_ld8u(tmp, addr, IS_USER(s));
 }
 }
 if (i) {
@@ -1491,28 +1493,28 @@ static int disas_iwmmxt_insn(CPUARMState *env, 
DisasContext *s, uint32_t insn)
 } else {
 if ((insn  28) == 0xf) { /* WSTRW wCx */
 tmp = iwmmxt_load_creg(wrd);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
 } else {
 gen_op_iwmmxt_movq_M0_wRn(wrd);
 tmp = tcg_temp_new_i32();
 if (insn  (1  8)) {
 if (insn  (1  22)) {/* WSTRD */
-tcg_temp_free_i32(tmp);
 tcg_gen_qemu_st64(cpu_M0, addr, IS_USER(s));
 } else {   /* WSTRW wRd */
 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
-gen_st32(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st32(tmp, addr, IS_USER(s));
 }
 } else {
 if (insn  (1  22)) {/* WSTRH */
 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
-gen_st16(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st16(tmp, addr, IS_USER(s));
 } else {   /* WSTRB */
 tcg_gen_trunc_i64_i32(tmp, cpu_M0);
-gen_st8(tmp, addr, IS_USER(s));
+tcg_gen_qemu_st8(tmp, addr, IS_USER(s));
 }
 }
 }
+tcg_temp_free_i32(tmp);
 }
 tcg_temp_free_i32(addr);
 return 0;
-- 
1.7.9.5




Re: [Qemu-devel] Designing QMP APIs at KVM Forum

2013-05-23 Thread Luiz Capitulino
On Thu, 23 May 2013 13:51:22 +0200
Stefan Hajnoczi stefa...@gmail.com wrote:

 With better QMP introspection on the horizon and work in various
 subsystems pushing QMP boundaries it would be useful to bring together
 the latest best practices for designing QMP APIs.
 
 There are design rules for keeping QMP APIs extensible and for
 allowing clients to detect the presence of features.  There is also
 QEMU-side infrastructure like event rate-limiting, which developers
 should make use of where appropriate.
 
 Is anyone willing to bring together the best practices and present
 them at KVM Forum this year?

I think this is a great idea and I vote for Eric to prepare a presentation.
Eric is doing an exceptional work on QMP command review, he is also
experienced on the client side.

 I think that could help set the standard for QMP APIs.  A set of
 slides or wiki page can be a reference to developers that stops us
 working from first pricinples every time a new API is added.

I was working on a doc to be added to docs/. It wouldn't be anything
fancy, but I ended up not finishing it.



Re: [Qemu-devel] [PATCH 0/4] ARM aarch64 TCG target VERSION 2

2013-05-23 Thread Peter Maydell
On 23 May 2013 13:37, Andreas Färber afaer...@suse.de wrote:
 If Big Endian targets are not yet supported, should this rather be an
 RFC? Or is that just about some unimplemented opcodes?

I'm happy for us to wait until an actual big-endian system
running Linux appears before we worry about it. #error if anybody
tries it is perfectly fine. (I would be surprised if we got
it right for the 32 bit bigendian hosts, for that matter:
there simply aren't really any systems out there running
big-endian Linux ARM which you could test it on.)

thanks
-- PMM



Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Anthony Liguori
Luiz Capitulino lcapitul...@redhat.com writes:

 On Thu, 23 May 2013 07:08:59 -0500
 Anthony Liguori aligu...@us.ibm.com wrote:

  then we don't need introspection at all. There's no user for it then.
 
 Introspection is not the right approach to feature discovery.  The
 schema does answer the question of what features are enabled, it just
 answers the question of what the signature of the methods are.

 (s/does answer/does not answer)

Yes, -ENOCAFFIENE :-/

 But there's an intersection here: a new enum value or new argument can
 be a new feature too.

 If we add new commands to query features, than I'm afraid that in the
 long run feature discovery will be split in query-qmp-schema and the
 specific feature discovery commands.

 I'm not arguing in favor of one or another way, but we need to know
 why and where we're going. The real motivation behind full introspection
 is to allow commands to be extended.

Right, so let's look at some examples and see how the introspection
would work for feature detection vs. some other form of feature
detection.

Regards,

Anthony Liguori




Re: [Qemu-devel] [Bug 1182490] [NEW] [qemu-1.5] coroutine-win32.c broken on NULL pointer

2013-05-23 Thread Dongsheng Song
Use rootfs download from
https://i18n-zh.googlecode.com/files/armhf_wheezy_qemu_20130518.7z

SET PATH=E:\opt\qemu-1.5.0-win64
SET QEMU_LD_PREFIX=E:\opt\qemu-1.5.0-win64

cd E:\var\tmp\armhf_wheezy_qemu

E:\var\tmp\armhf_wheezy_qemuqemu-system-arm -M vexpress-a9 -cpu
cortex-a9 -m 512 -uuid e04ec652-8bed-11e2-86b9-000c290c10de -drive
file=armhf_wheezy.img,if=sd,cache=writeback -kernel
vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append
root=/dev/mmcblk0 rw init=/sbin/init

E:\var\tmp\armhf_wheezy_qemugdb qemu-system-arm
(gdb) set args -M vexpress-a9 -cpu cortex-a9 -m 512 -uuid
e04ec652-8bed-11e2-86b9-000c290c10de -drive
file=armhf_wheezy.img,if=sd,cache=writeback -kernel
vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append
root=/dev/mmcblk0 rw init=/sbin/init

(gdb) run
Starting program: E:\opt\qemu-1.5.0-win64\qemu-system-arm.exe -M vexpress-a9 -cp
u cortex-a9 -m 512 -uuid e04ec652-8bed-11e2-86b9-000c290c10de -drive file=armhf_
wheezy.img,if=sd,cache=writeback -kernel vmlinuz-3.2.0-4-vexpress -initrd initrd
.img-3.2.0-4-vexpress -append root=/dev/mmcblk0 rw init=/sbin/init
[New Thread 2164.0x480]
[New Thread 2164.0x1ac]
[New Thread 2164.0x162c]
[New Thread 2164.0x514]
[New Thread 2164.0xa6c]
[New Thread 2164.0xc14]
[New Thread 2164.0x854]
[New Thread 2164.0xc1c]
[New Thread 2164.0x169c]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 2164.0x162c]
0x0043e2cd in ?? ()

On Thu, May 23, 2013 at 8:08 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Tue, May 21, 2013 at 02:11:05PM -, Cauchy Song wrote:
 Public bug reported:

 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 4340.0x163c]
 qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0, from_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 (gdb) bt
 #0  qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0,
 from_=0x3ba1c80) at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 #1  coroutine_trampoline (co_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:58
 #2  0x77098fed in ?? ()
 #3  0x in ?? ()

 What is the command-line?

 How do you reproduce the crash?

 Stefan




Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Kevin Wolf
Am 23.05.2013 um 14:08 hat Anthony Liguori geschrieben:
 Kevin Wolf kw...@redhat.com writes:
 
  Am 22.05.2013 um 18:14 hat Anthony Liguori geschrieben:
  Kevin Wolf kw...@redhat.com writes:
   For example, libvirt wants to query which block drivers it can use. It
   doesn't really matter for which drivers we had the source initially, but
   only which drivers are compiled in (possibly loaded) and can actually be
   used.
  
  The schema is the wrong place to discover this.
  
  Loading a module wouldn't add an enumeration value.  The enumeration
  values are fixed.
  
  We should introduce commands to query this kind of information.
  
  Schema introspection is primarily useful for dynamic languages to
  autogenerate bindings.  It's not terribly useful for query
  capabilities/features.
 
  Then you won't get real modularity. It means that all modules must
  already be known during the build time, and if they aren't available
  (because they weren't built or aren't loaded) you include them anyway,
  some parts of them are a static part of the core. You don't get fully
  rid of modules by not linking their object file in, but you always have
  the QAPI part left over.
 
 There are two things here: the schema and the generated code.  The
 generated code can and should live in the module.
 
 But the schema always stays the same.
 
 Think of the schema like kernel headers.  The kernel headers are always
 fixed regardless of what kernel modules are loaded or how the kernel is
 configured.
 
  then we don't need introspection at all. There's no user for it then.
 
 Introspection is not the right approach to feature discovery.  The
 schema does answer the question of what features are enabled, it just
 answers the question of what the signature of the methods are.

You can see it like this. Then, as I said, it's totally useless, because
nobody has ever asked this question. The context in which libvirt wants
to use it is feature discovery. If we don't support that, then there's
no reason to provide introspection at all.

libvirt already knows how to use features. It must know it, just parsing
the schema doesn't automagically give you libvirt code, so someone must
have coded the libvirt side of things. The interesting part is whether a
given interface is available on this specific qemu binary.

  It also makes the schema totally useless. If you can't use it to tell
  which commands this qemu can execute and which it can't,
 
 query-commands serves that purpose.

It solves a subset of this problem. Optional fields can be added as
arguments or to returned structs, enums can be extended, and so far
we're having a hard time making use of it because the client can't
discover it.

  We can have hundreds of individual query commands like you suggest
  (query-qcow2-creation-option-values, yay!) or we do the modularity
  thing and the schema introspection properly and make it dynamic. I
  prefer the latter.
 
 Let's consider a real example.  It sounds like you have something in
 mind, can you be more specific?

Not a very specific one, it's just that the more I discuss about things
like blockdev-add, the more I get the impression that there is an awful
lot of information to query. Each image format can provide different
options, for creating images and for opening them, and some of them may
be enums that could be extended and whose values must be queried etc.

Schema introspection allows you to have one single way to check for all
optional fields, enum values, union branches. The other way is to have a
separate command for each of them.

Basically instead of query-enum(Qcow2PreallocationType) you get
query-qcow2-prellocation-types(). You can imagine how the set of
commands grows once you start doing things this way.

When I discussed with Eric (who is one of the few actual consumers of
the API), he preferred introspection of a dynamic schema as well,
compared to many separate query-* commands.

Kevin



Re: [Qemu-devel] [Bug 1182490] [NEW] [qemu-1.5] coroutine-win32.c broken on NULL pointer

2013-05-23 Thread Dongsheng Song
When I use qemu 1.4, it running smoothly:

SET PATH=E:\opt\qemu-1.4.1-win64
SET QEMU_LD_PREFIX=E:\opt\qemu-1.4.1-win64

E:\var\tmp\armhf_wheezy_qemuqemu-system-arm -M vexpress-a9 -cpu
cortex-a9 -m 512 -uuid e04ec652-8bed-11e2-86b9-000c290c10de -drive
file=armhf_wheezy.img,if=sd,cache=writeback -kernel
vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append
root=/dev/mmcblk0 rw init=/sbin/init

On Thu, May 23, 2013 at 8:52 PM, Dongsheng Song
dongsheng.s...@gmail.com wrote:
 Use rootfs download from
 https://i18n-zh.googlecode.com/files/armhf_wheezy_qemu_20130518.7z

 SET PATH=E:\opt\qemu-1.5.0-win64
 SET QEMU_LD_PREFIX=E:\opt\qemu-1.5.0-win64

 cd E:\var\tmp\armhf_wheezy_qemu

 E:\var\tmp\armhf_wheezy_qemuqemu-system-arm -M vexpress-a9 -cpu
 cortex-a9 -m 512 -uuid e04ec652-8bed-11e2-86b9-000c290c10de -drive
 file=armhf_wheezy.img,if=sd,cache=writeback -kernel
 vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append
 root=/dev/mmcblk0 rw init=/sbin/init

 E:\var\tmp\armhf_wheezy_qemugdb qemu-system-arm
 (gdb) set args -M vexpress-a9 -cpu cortex-a9 -m 512 -uuid
 e04ec652-8bed-11e2-86b9-000c290c10de -drive
 file=armhf_wheezy.img,if=sd,cache=writeback -kernel
 vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append
 root=/dev/mmcblk0 rw init=/sbin/init

 (gdb) run
 Starting program: E:\opt\qemu-1.5.0-win64\qemu-system-arm.exe -M vexpress-a9 
 -cp
 u cortex-a9 -m 512 -uuid e04ec652-8bed-11e2-86b9-000c290c10de -drive 
 file=armhf_
 wheezy.img,if=sd,cache=writeback -kernel vmlinuz-3.2.0-4-vexpress -initrd 
 initrd
 .img-3.2.0-4-vexpress -append root=/dev/mmcblk0 rw init=/sbin/init
 [New Thread 2164.0x480]
 [New Thread 2164.0x1ac]
 [New Thread 2164.0x162c]
 [New Thread 2164.0x514]
 [New Thread 2164.0xa6c]
 [New Thread 2164.0xc14]
 [New Thread 2164.0x854]
 [New Thread 2164.0xc1c]
 [New Thread 2164.0x169c]

 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 2164.0x162c]
 0x0043e2cd in ?? ()

 On Thu, May 23, 2013 at 8:08 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Tue, May 21, 2013 at 02:11:05PM -, Cauchy Song wrote:
 Public bug reported:

 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 4340.0x163c]
 qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0, from_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 (gdb) bt
 #0  qemu_coroutine_switch (action=COROUTINE_TERMINATE, to_=0x0,
 from_=0x3ba1c80) at /home/cauchy/vcs/git/qemu/coroutine-win32.c:47
 #1  coroutine_trampoline (co_=0x3ba1c80)
 at /home/cauchy/vcs/git/qemu/coroutine-win32.c:58
 #2  0x77098fed in ?? ()
 #3  0x in ?? ()

 What is the command-line?

 How do you reproduce the crash?

 Stefan




Re: [Qemu-devel] [RFC PATCH v3 05/11] qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze

2013-05-23 Thread Stefan Hajnoczi
On Tue, May 21, 2013 at 11:33:52AM -0400, Tomoki Sekiyama wrote:
 Implements a basic stub of software VSS provider. Currently, this modules
 only provides a relay function of events between qemu-guest-agent and
 Windows VSS when VSS finished filesystem freeze and when qemu snapshot
 is done.
 
 In the future, this module could be extended to support the other VSS
 functions, such as query for snapshot volumes and recovery.
 
 Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
 ---
  Makefile.objs   |2 
  configure   |5 
  qga/Makefile.objs   |6 
  qga/vss-win32-provider.h|   26 ++
  qga/vss-win32-provider/Makefile.objs|   21 +
  qga/vss-win32-provider/install.cpp  |  494 
 +++
  qga/vss-win32-provider/provider.cpp |  474 ++
  qga/vss-win32-provider/qga-provider.def |   10 +
  qga/vss-win32-provider/qga-provider.idl |   20 +
  qga/vss-win32.h |   85 +
  10 files changed, 1142 insertions(+), 1 deletion(-)
  create mode 100644 qga/vss-win32-provider.h
  create mode 100644 qga/vss-win32-provider/Makefile.objs
  create mode 100644 qga/vss-win32-provider/install.cpp
  create mode 100644 qga/vss-win32-provider/provider.cpp
  create mode 100644 qga/vss-win32-provider/qga-provider.def
  create mode 100644 qga/vss-win32-provider/qga-provider.idl
  create mode 100644 qga/vss-win32.h

Please run scripts/checkpatch.pl and use QEMU coding style (see
./CODING_STYLE and ./HACKING).

 diff --git a/qga/vss-win32-provider/Makefile.objs 
 b/qga/vss-win32-provider/Makefile.objs
 new file mode 100644
 index 000..73ef752
 --- /dev/null
 +++ b/qga/vss-win32-provider/Makefile.objs
 @@ -0,0 +1,21 @@
 +# rules to build qga-provider.dll
 +
 +qga-obj-y += qga-provider.dll
 +qga-prv-obj-y += provider.o install.o
 +
 +obj-qga-prv-obj-y = $(addprefix $(obj)/, $(qga-prv-obj-y))
 +$(obj-qga-prv-obj-y): QEMU_CXXFLAGS = $(filter-out -Wstrict-prototypes 
 -Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
 -Wold-style-definition -Wredundant-decls -fstack-protector-all, 
 $(QEMU_CFLAGS)) -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor
 +
 +$(obj)/qga-provider.dll: LDFLAGS = -shared 
 -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi 
 -luuid -static
 +$(obj)/qga-provider.dll: $(obj-qga-prv-obj-y) 
 $(SRC_PATH)/$(obj)/qga-provider.def $(obj)/qga-provider.tlb
 + $(call quiet-command,$(CXX) -o $@ $(qga-prv-obj-y) 
 $(SRC_PATH)/qga/vss-win32-provider/qga-provider.def $(CXXFLAGS) $(LDFLAGS),  
 LINK  $(TARGET_DIR)$@)
 +
 +
 +# rules to build qga-provider.tlb
 +# Currently, only native build is supported because building .tlb
 +# (TypeLibrary) from .idl requires WindowsSDK and MIDL (included in VC++).
 +MIDL=midl
 +WINSDK=C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include

This needs to be a ./configure option.

 diff --git a/qga/vss-win32.h b/qga/vss-win32.h
 new file mode 100644
 index 000..7600087
 --- /dev/null
 +++ b/qga/vss-win32.h
 @@ -0,0 +1,85 @@
 +/*
 + * QEMU Guest Agent win32 VSS common declarations
 + *
 + * Copyright Hitachi Data Systems Corp. 2013
 + *
 + * Authors:
 + *  Tomoki Sekiyama   tomoki.sekiy...@hds.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
 + * See the COPYING file in the top-level directory.
 + */
 +
 +#ifndef VSS_WIN32_H
 +#define VSS_WIN32_H
 +
 +#define __MIDL_user_allocate_free_DEFINED__
 +#include config-host.h
 +#include windows.h
 +#include shlwapi.h
 +
 +/* Reduce warnings to include vss.h */
 +#define __in  IN
 +#define __out OUT
 +#define __RPC_unique_pointer
 +#define __RPC_string
 +#define __RPC__deref_inout_opt
 +#define __RPC__out
 +#ifndef __RPC__out_ecount_part
 +#define __RPC__out_ecount_part(x, y)
 +#endif
 +#define _declspec(x)
 +#undef uuid
 +#define uuid(x)

This looks hacky.  Why are you stubbing out macros that vss.h uses?



Re: [Qemu-devel] RFC: Full introspection support for QMP

2013-05-23 Thread Eric Blake
On 05/22/2013 07:40 AM, Amos Kong wrote:
 Hi all,
 
 We already have query-command-line-options to query details of command-line
 options. As we discussed in the list, we also need full introspection of QMP
 (command). The qmp-events also need to be dumped, we can define events in
 qai-schema.json. We can also dump QMP errors in future if it's needed.
 
 Command name: query-qmp-schema
 Return: returns the contents of qapi-schema.json in json format.
 
 Solution to query json content from C code:
   qapi-schema.json is processed by qapi python scripts to generate C
   files, I found the content is good enough for Libvirt to know the
   QMP command schema. We can change qapi scripts to generate a talbe/list
   to record the raw string, then we can return the raw string in
   qmp_query_qmp_schema().
 
 By default, return the complete schema in one go.
 
 And support to query of unknown type in new command.
   - { execute: query-qmp-schema arguments: { command: query-status 
 }}
   - { return : data: { command': query-status, returns: 
 StatusInfo }}

If you are planning on returning everything in one shot, then this has
to be an array-of-dict return, rather than a single dict return.  If
filtering is used, the result should be an array-of-one, and I
definitely want to have a non-filtered mode that returns everything at once.

   - { execute: query-qmp-schema arguments: { type: StatusInfo }}
   - { return : data: { type: StatusInfo, data: {running: bool,
 singlestep: bool, status: RunState} }
   - { execute: query-qmp-schema arguments: { event: 
 RX-FILTER-CHANGE }}

You need a schema for this command :)  It looks like you are proposing
something like:

{ 'command': 'query-qmp-schema', 'arguments': {
'*command':'str', '*type':'str', '*event':'str' },
  'returns': [ 'SchemaData' ] }

and 'SchemaData' needs to be spelled out as what an actual entry in
qapi-schema.json must actually look like (goes back to Stefan's
complaint on the 'drive-add' thread that we should avoid sending
schema-less data over QAPI).  Besides, having a schema in place for what
all QAPI must look like may force us to be more robust in our additions
to QAPI.

Hmm, my schema doesn't adequately express that you are probably only
allowing a single 'command', 'type', or 'event' filtering to be used at
once.  We've had some ideas on other threads about providing smarter
magic on handling a discriminated union embedded inside a top-level
dictionary, rather than nesting type/data members of a nested
dictionary; figuring out how to express this may improve ease of use of
other aspects of QAPI.  In fact, it would be simpler to just say that
filtering uses a 'name' argument, and hold ourselves to a design that
command names, types, and events never have overlapping namespace, as in:

{ 'command': 'query-qmp-schema',
  'arguments': { '*name':'str' },
  'returns': [ 'SchemaData' ] }

Another issue (or rather, more thoughts on my opaque 'SchemaData' type).
 QAPI expresses optional elements with markup, as in:

{ 'command': 'blockdev-snapshot-sync',
  'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str',
'*mode': 'NewImageMode'} }

But our argument has always been that if you have to post-process a QAPI
argument, you were cramming too much information into a single element.
 Optional arguments are a case of post-processing - libvirt would have
to check if an option name begins with '*' to learn whether an option is
optional.  If you return qapi-schema.json contents as-is, you are
forcing management to post-process.  Contrast that with
query-command-line-options, where we INTENTIONALLY called out a rather
nested layout, but where that layout allows us to give additional
details.  In other words, rather than replaying qemu-schema.json as-is,
I think your C code should munge the text into a format more useful over
QAPI.  That is, I'd rather see:

- { execute: query-qmp-schema, arguments:
 { name: blockdev-snapshot-sync }}
- { return : data: [
 { metatype: command,
   name: blockdev-snapshot-sync,
   data: [
{ option: device, type: str },
{ option: snapshot-file, type, str },
{ option: format, type, str, optional: true },
{ option: mode, type, NewImageMode, optional: true }
 ] } }

and possibly with further extensions that express the default value of
an optional argument.  Note that this post-processing (turning a
free-form dictionary from the .json file into an array of dictionaries
that all match a given schema) makes the data a little easier to handle.
 In fact, with that layer of structuring, I can now define what the
schema looks like:

{ 'type': 'SchemaDataMember', 'data': {
'option': 'str', 'type': 'str', '*optional': 'bool' } }
{ 'enum': 'SchemaMetatype', 'data': [ 'command', 'type', 'event' ] }
{ 'type': 'SchemaData', 'data': {
'name': 'str',
'metatype': 'SchemaMetatype',
'*returns': 'str',
'*data': [ 'SchemaDataMember' 

Re: [Qemu-devel] [PATCH 0/4] ARM aarch64 TCG target VERSION 2

2013-05-23 Thread Andreas Färber
Am 23.05.2013 14:50, schrieb Peter Maydell:
 On 23 May 2013 13:37, Andreas Färber afaer...@suse.de wrote:
 If Big Endian targets are not yet supported, should this rather be an
 RFC? Or is that just about some unimplemented opcodes?
 
 I'm happy for us to wait until an actual big-endian system
 running Linux appears before we worry about it. #error if anybody
 tries it is perfectly fine. (I would be surprised if we got
 it right for the 32 bit bigendian hosts, for that matter:
 there simply aren't really any systems out there running
 big-endian Linux ARM which you could test it on.)

I was worried about Big Endian QEMU targets (ppc, sparc, etc.), not
about Big Endian ARM hosts. If only half our targets are supported by a
TCG backend, then the default target list is busted, whether hardcoded
or default-configs-generated.

Andreas

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



Re: [Qemu-devel] [PATCH 0/4] ARM aarch64 TCG target VERSION 2

2013-05-23 Thread Peter Maydell
On 23 May 2013 13:53, Andreas Färber afaer...@suse.de wrote:
 Am 23.05.2013 14:50, schrieb Peter Maydell:
 I'm happy for us to wait until an actual big-endian system
 running Linux appears before we worry about it.

 I was worried about Big Endian QEMU targets (ppc, sparc, etc.), not
 about Big Endian ARM hosts.

Oops, yes; I agree. guest big-endian support is pretty trivial
(all you need to do is byteswap on load and store) and easily
testable (run a BE guest) so the TCG backend should just
implement it from the start.

-- PMM



Re: [Qemu-devel] [PATCH 1/8] pci: Cleanup configuration for pci-hotplug.c

2013-05-23 Thread David Gibson
On Thu, May 23, 2013 at 02:11:35PM +0300, Michael S. Tsirkin wrote:
 On Thu, May 09, 2013 at 10:31:05AM +1000, David Gibson wrote:
[snip]
  diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
  new file mode 100644
  index 000..724a80b
  --- /dev/null
  +++ b/hw/pci/pci-hotplug-old.c
 
 Please use git format-patch -M so renames are
 properly shown. I can't see whether anything changed here.

Ah, sorry.  Forgot that wasn't the default.

  @@ -0,0 +1,290 @@
  +/*
  + * QEMU PCI hotplug support
 
 I don't particularly mind whether it's called pci-hotplug or
 pci-hotplug-old, but I'm prepared to go with you on this.
 However, what we really should do is fix the comment
 to match reality.

Good point.

 I think this needs two commits:
 - fix comment
 - rename
 
 to make format-patch -M detect this as a rename

Hrm, I think it should detect the rename, even with a change to the
comment.   But I'll check to make sure, and split if necessary.

-- 
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 5/8] pci: Replace pci_find_domain() with more general pci_root_bus_path()

2013-05-23 Thread David Gibson
On Thu, May 23, 2013 at 02:04:08PM +0300, Michael S. Tsirkin wrote:
 On Thu, May 09, 2013 at 10:31:09AM +1000, David Gibson wrote:
  pci_find_domain() is used in a number of places where we want an id for a
  whole PCI domain (i.e. the subtree under a PCI root bus).  The trouble is
  that many platforms may support multiple independent host bridges with no
  hardware supplied notion of domain number.
  
  This patch, therefore, replaces calls to pci_find_domain() with calls to
  a new pci_root_bus_path() returning a string.  The new call is implemented
  in terms of a new callback in the host bridge class, so it can be defined
  in some way that's well defined for the platform.  When no callback is
  available we fall back on the qbus name.
  
  Most current uses of pci_find_domain() are for error or informational
  messages, so the change in identifiers should be harmless.  The exception
  is pci_get_dev_path(), whose results form part of migration streams.  To
  maintain compatibility with old migration streams, the PIIX PCI host is
  altered to always supply  for this path, which matches the old domain
  number (since the code didn't actually support domains other than 0).
  
  For the pseries (spapr) PCI bridge we use a different platform-unique
  identifier (pseries machines can routinely have dozens of PCI host
  bridges).  Theoretically that breaks migration streams, but given that we
  don't yet have migration support for pseries, it doesn't matter.
  
  Any other machines that have working migration support including PCI
  devices will need to be updated to maintain migration stream compatibility.
  
  Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 
 AFAIK PC is the only one with working migration, yes, but
 we have Q35 as well which can be migrated.

Good point, I'll add a similar hook to q35.

-- 
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 15/30] memory: add address_space_valid

2013-05-23 Thread David Gibson
On Tue, May 21, 2013 at 12:57:16PM +0200, Paolo Bonzini wrote:
 The old-style IOMMU lets you check whether an access is valid in a
 given DMAContext.  There is no equivalent for AddressSpace in the
 memory API, implement it with a lookup of the dispatch tree.

I don't love the name - address_space_valid suggests to me it tests
the validity of the whole address space, not a specific range.  But
an obviously better name doesn't quickly occur to me.

Obviously I like the functionality, since I wrote that into the
DMAContext stuff specifically to support the spapr_llan driver :).


 
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  dma-helpers.c |  5 +
  exec.c| 25 +
  include/exec/memory.h | 14 ++
  include/sysemu/dma.h  |  3 ++-
  4 files changed, 46 insertions(+), 1 deletion(-)
 
 diff --git a/dma-helpers.c b/dma-helpers.c
 index 272632f..2962b69 100644
 --- a/dma-helpers.c
 +++ b/dma-helpers.c
 @@ -298,6 +298,11 @@ bool iommu_dma_memory_valid(DMAContext *dma, dma_addr_t 
 addr, dma_addr_t len,
  plen = len;
  }
  
 +if (!address_space_valid(dma-as, paddr, len,
 + dir == DMA_DIRECTION_FROM_DEVICE)) {
 +return false;
 +}
 +
  len -= plen;
  addr += plen;
  }
 diff --git a/exec.c b/exec.c
 index 8d91221..8f1b507 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -2079,6 +2079,31 @@ static void cpu_notify_map_clients(void)
  }
  }
  
 +bool address_space_valid(AddressSpace *as, hwaddr addr, int len, bool 
 is_write)
 +{
 +AddressSpaceDispatch *d = as-dispatch;
 +MemoryRegionSection *section;
 +int l;
 +hwaddr page;
 +
 +while (len  0) {
 +page = addr  TARGET_PAGE_MASK;
 +l = (page + TARGET_PAGE_SIZE) - addr;
 +if (l  len) {
 +l = len;
 +}
 +section = phys_page_find(d, addr  TARGET_PAGE_BITS);
 +if (section-mr == io_mem_unassigned ||
 +(is_write  section-mr-readonly)) {
 +return false;
 +}
 +
 +len -= l;
 +addr += l;
 +}
 +return true;
 +}
 +
  /* Map a physical memory region into a host virtual address.
   * May map a subset of the requested range, given by and returned in *plen.
   * May return NULL if resources needed to perform the mapping are exhausted.
 diff --git a/include/exec/memory.h b/include/exec/memory.h
 index 6ed593c..2e5fd11 100644
 --- a/include/exec/memory.h
 +++ b/include/exec/memory.h
 @@ -860,6 +860,20 @@ void address_space_write(AddressSpace *as, hwaddr addr,
   */
  void address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int 
 len);
  
 +/* address_space_valid: check for validity of an address space range
 + *
 + * Check whether memory is assigned to the given address space range.
 + *
 + * For now, addr and len should be aligned to a page size.  This limitation
 + * will be lifted in the future.
 + *
 + * @as: #AddressSpace to be accessed
 + * @addr: address within that address space
 + * @len: length of the area to be checked
 + * @is_write: indicates the transfer direction
 + */
 +bool address_space_valid(AddressSpace *as, hwaddr addr, int len, bool 
 is_write);
 +
  /* address_space_map: map a physical memory region into a host virtual 
 address
   *
   * May map a subset of the requested range, given by and returned in @plen.
 diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
 index a52c93a..2e239dc 100644
 --- a/include/sysemu/dma.h
 +++ b/include/sysemu/dma.h
 @@ -113,7 +113,8 @@ static inline bool dma_memory_valid(DMAContext *dma,
  DMADirection dir)
  {
  if (!dma_has_iommu(dma)) {
 -return true;
 +return address_space_valid(dma-as, addr, len,
 +   dir == DMA_DIRECTION_FROM_DEVICE);
  } else {
  return iommu_dma_memory_valid(dma, addr, len, dir);
  }

-- 
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 6/8] pci: Simpler implementation of primary PCI bus

2013-05-23 Thread David Gibson
On Thu, May 23, 2013 at 02:01:57PM +0300, Michael S. Tsirkin wrote:
 On Thu, May 09, 2013 at 10:31:10AM +1000, David Gibson wrote:
  Currently pci_get_primary_bus() searches the list of root buses for one
  with domain 0.  But since host buses are always registered with domain 0,
  this just amounts to finding the only PCI host bus.
  
  This simplifies the implementation by defining the primary PCI bus to
  be the first one registered, using a global variable to track it.
  
  Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 
 This is the only part that I dislike.
 How about an explicit API to set the primary bus?
 Let machine types set it.

I guess, though I was hoping to avoid changing every bit of platform
code that sets up a PCI bus.

-- 
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][v4 2/3] debugcon: make debug message more readable

2013-05-23 Thread Andreas Färber
Am 23.05.2013 08:58, schrieb liguang:
 before change:
 Bdebugcon: write addr=0x val=0x6f
 odebugcon: write addr=0x val=0x6f
 odebugcon: write addr=0x val=0x74
 tdebugcon: write addr=0x val=0x69
 idebugcon: write addr=0x val=0x6e
 ndebugcon: write addr=0x val=0x67
 gdebugcon: write addr=0x val=0x20
  debugcon: write addr=0x val=0x66
 
 after change:
 B [debugcon: write addr=0x val=0x6f]
 o [debugcon: write addr=0x val=0x6f]
 o [debugcon: write addr=0x val=0x74]
 t [debugcon: write addr=0x val=0x69]
 i [debugcon: write addr=0x val=0x6e]
 n [debugcon: write addr=0x val=0x67]
 g [debugcon: write addr=0x val=0x20]
   [debugcon: write addr=0x val=0x66]
 
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  hw/char/debugcon.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
 index 7e41c90..52fa0ab 100644
 --- a/hw/char/debugcon.c
 +++ b/hw/char/debugcon.c
 @@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr 
 addr, uint64_t val,
  unsigned char ch = val;
  
  #ifdef DEBUG_DEBUGCON
 -printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
 val);
 +printf( [debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x]\n, 
 addr, val);

While not wrong, this is rather exotic - wouldn't it be better to
fprintf() to stderr instead or to use qemu_log() or tracepoints?

Andreas

  #endif
  
  qemu_chr_fe_write(s-chr, ch, 1);
 


-- 
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 17/30] memory: add address_space_translate

2013-05-23 Thread liu ping fan
On Thu, May 23, 2013 at 5:59 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 23/05/2013 09:09, liu ping fan ha scritto:
   void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
 int len, bool is_write)
   {
  -AddressSpaceDispatch *d = as-dispatch;
  -int l;
  +hwaddr l;
   uint8_t *ptr;
   uint32_t val;
  -hwaddr page;
  +hwaddr addr1;
   MemoryRegionSection *section;
 
   while (len  0) {
  -page = addr  TARGET_PAGE_MASK;
  -l = (page + TARGET_PAGE_SIZE) - addr;
  -if (l  len)
  -l = len;
  -section = phys_page_find(d, page  TARGET_PAGE_BITS);
  +l = len;
  +section = address_space_translate(as, addr, addr1, l, 
  is_write);
 
 Jan's Rework sub-page handling patch broke the tlb_set_page
 (anything else?)  But I think we still need a function based on
 address_space_translate to wrap the subpage logic inside and ease the
 incoming RCU style.

 The idea is that address_space_translate gets a ref to the MemoryRegion,
 and the ref is then released by the caller of address_space_translate.

This will require subpage hold a reference to real mr. But I think it
is needless. Maybe when later in your these series, we will see how to
resolve it.  BTW,  do you target URCU patches to 1.6

Regards,
Pingfan

 That means that the actual memory accesses can run outside the RCU
 critical section.

 But I'm not sure how that is related to subpage logic.  Subpages are
 simply MemoryRegions that only exist in the phys page map, rather than
 within an AddressSpace.  Their destruction will be delayed anyway by
 doing call_rcu on the old phys page map.

 Paolo



Re: [Qemu-devel] [PATCH 6/8] pci: Simpler implementation of primary PCI bus

2013-05-23 Thread David Gibson
On Thu, May 23, 2013 at 02:22:30PM +0300, Michael S. Tsirkin wrote:
 On Thu, May 09, 2013 at 10:31:10AM +1000, David Gibson wrote:
  Currently pci_get_primary_bus() searches the list of root buses for one
  with domain 0.  But since host buses are always registered with domain 0,
  this just amounts to finding the only PCI host bus.
  
  This simplifies the implementation by defining the primary PCI bus to
  be the first one registered, using a global variable to track it.
  
  Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 
 Or better: can we just fail if there is more than
 one root?

That might work, I'll look into doing 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


Re: [Qemu-devel] [PATCH][v4 1/3] debugcon: fix always print addr=0x0, val=0x0 bug when use DEBUG_DEBUGCON

2013-05-23 Thread Andreas Färber
Am 23.05.2013 08:58, schrieb liguang:
 when use DEBUG_DEBUGCON, screen spits:
 debugcon: write addr=0x val=0x00
 Rdebugcon: write addr=0x val=0x00
 udebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 idebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
 gdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 pdebugcon: write addr=0x val=0x00
 tdebugcon: write addr=0x val=0x00
 idebugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 ndebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 rdebugcon: write addr=0x val=0x00
 odebugcon: write addr=0x val=0x00
 mdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 adebugcon: write addr=0x val=0x00
 tdebugcon: write addr=0x val=0x00
  debugcon: write addr=0x val=0x00
 
 Oh, that's wrong, val is not always be 0.
 this bug caused by lack of length modifier
 for specifier 'x'.
 
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
 v4: fix misleading subject

As I've reminded before, please prepend a cover letter (0/x) when
sending more than once patch!

 ---
  hw/char/debugcon.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
 index 02c9577..7e41c90 100644
 --- a/hw/char/debugcon.c
 +++ b/hw/char/debugcon.c
 @@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr 
 addr, uint64_t val,
  unsigned char ch = val;
  
  #ifdef DEBUG_DEBUGCON
 -printf(debugcon: write addr=0x%04x val=0x%02x\n, addr, val);
 +printf(debugcon: write addr=0x%04 HWADDR_PRIx  val=0x%02x\n, addr, 
 val);

Please merge 3/3 with this patch - the changes are pretty obviously
correct, so you can shorten the commit message by dropping the example
output.

Andreas

  #endif
  
  qemu_chr_fe_write(s-chr, ch, 1);
 


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



  1   2   3   >