Re: [Qemu-devel] [PULL 00/18] ppc patch queue 2013-09-02

2013-09-03 Thread Aurelien Jarno
On Mon, Sep 02, 2013 at 10:11:15AM +0200, Alexander Graf wrote:
 Hi Blue / Aurelien / Anthony,
 
 This is my current patch queue for ppc.  Please pull.
 

Done, thanks.

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



Re: [Qemu-devel] [PULL 00/29] Three tcg patch sets

2013-09-03 Thread Aurelien Jarno
On Mon, Sep 02, 2013 at 09:28:45AM -0700, Richard Henderson wrote:
 
 Aurelien has now reviewed three tcg related patch sets.  This is a pull
 request for all of them, fixing a trivial patch conflict in the process.
 

Done, thanks.


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



[Qemu-devel] [PATCH 2/4] tcg/optimize: fix known-zero bits for right shift ops

2013-09-03 Thread Aurelien Jarno
32-bit versions of sar and shr ops should not propagate known-zero bits
from the unused 32 high bits. For sar it could even lead to wrong code
being generated.

Cc: Richard Henderson r...@twiddle.net
Cc: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 tcg/optimize.c |   21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 41f2906..0ed8983 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -731,16 +731,29 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
uint16_t *tcg_opc_ptr,
 mask = temps[args[1]].mask  mask;
 break;
 
-CASE_OP_32_64(sar):
+case INDEX_op_sar_i32:
+if (temps[args[2]].state == TCG_TEMP_CONST) {
+mask = ((int32_t)temps[args[1]].mask
+ temps[args[2]].val);
+}
+break;
+case INDEX_op_sar_i64:
 if (temps[args[2]].state == TCG_TEMP_CONST) {
-mask = ((tcg_target_long)temps[args[1]].mask
+mask = ((int64_t)temps[args[1]].mask
  temps[args[2]].val);
 }
 break;
 
-CASE_OP_32_64(shr):
+case INDEX_op_shr_i32:
 if (temps[args[2]].state == TCG_TEMP_CONST) {
-mask = temps[args[1]].mask  temps[args[2]].val;
+mask = ((uint32_t)temps[args[1]].mask
+ temps[args[2]].val);
+}
+break;
+case INDEX_op_shr_i64:
+if (temps[args[2]].state == TCG_TEMP_CONST) {
+mask = ((uint64_t)temps[args[1]].mask
+ temps[args[2]].val);
 }
 break;
 
-- 
1.7.10.4




[Qemu-devel] [PATCH 0/4] tcg/optimize: fixes and improvements

2013-09-03 Thread Aurelien Jarno
This patchset first fixes known-zero bits optimization so that it is
actually used, and does some further optimizations for 32-bit ops and
unsigned loads.

Aurelien Jarno (4):
  tcg/optimize: fix know-zero bits optimization
  tcg/optimize: fix known-zero bits for right shift ops
  tcg/optimize: improve known-zero bits for 32-bit ops
  tcg/optimize: add known-zero bits compute for load ops

 tcg/optimize.c |   48 +++-
 1 file changed, 43 insertions(+), 5 deletions(-)

-- 
1.7.10.4




[Qemu-devel] [PATCH 3/4] tcg/optimize: improve known-zero bits for 32-bit ops

2013-09-03 Thread Aurelien Jarno
The shl_i32 op might set some bits of the unused 32 high bits of the
mask. Fix that by clearing the unused 32 high bits for all 32-bit ops
except load/store which operate on tl values.

Cc: Richard Henderson r...@twiddle.net
Cc: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 tcg/optimize.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 0ed8983..b1f736b 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -791,6 +791,12 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
uint16_t *tcg_opc_ptr,
 break;
 }
 
+/* 32-bit ops (non 64-bit ops and non load/store ops) generate 32-bit
+   results */
+if (!(tcg_op_defs[op].flags  (TCG_OPF_CALL_CLOBBER | TCG_OPF_64BIT))) 
{
+mask = 0xu;
+}
+
 if (mask == 0) {
 assert(def-nb_oargs == 1);
 s-gen_opc_buf[op_index] = op_to_movi(op);
-- 
1.7.10.4




[Qemu-devel] [PATCH 4/4] tcg/optimize: add known-zero bits compute for load ops

2013-09-03 Thread Aurelien Jarno
Cc: Richard Henderson r...@twiddle.net
Cc: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 tcg/optimize.c |   13 +
 1 file changed, 13 insertions(+)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index b1f736b..044f456 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -787,6 +787,19 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
uint16_t *tcg_opc_ptr,
 mask = temps[args[3]].mask | temps[args[4]].mask;
 break;
 
+CASE_OP_32_64(ld8u):
+case INDEX_op_qemu_ld8u:
+mask = 0xff;
+break;
+CASE_OP_32_64(ld16u):
+case INDEX_op_qemu_ld16u:
+mask = 0x;
+break;
+case INDEX_op_ld32u_i64:
+case INDEX_op_qemu_ld32u:
+mask = 0xu;
+break;
+
 default:
 break;
 }
-- 
1.7.10.4




[Qemu-devel] [PATCH 1/4] tcg/optimize: fix know-zero bits optimization

2013-09-03 Thread Aurelien Jarno
Known-zero bits optimization is a great idea that helps to generate more
optimized code. However the current implementation is basically useless
as the computed mask is not saved.

Fix this to make it really working.

Cc: Richard Henderson r...@twiddle.net
Cc: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 tcg/optimize.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index b29bf25..41f2906 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -695,7 +695,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t 
*tcg_opc_ptr,
 break;
 }
 
-/* Simplify using known-zero bits */
+/* Simplify using known-zero bits. Currently only ops with a single
+   output argument is supported. */
 mask = -1;
 affected = -1;
 switch (op) {
@@ -1144,6 +1145,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
uint16_t *tcg_opc_ptr,
 } else {
 for (i = 0; i  def-nb_oargs; i++) {
 reset_temp(args[i]);
+/* Save the corresponding known-zero bits mask for the
+   first output argument (only one supported so far). */
+if (i == 0) {
+temps[args[i]].mask = mask;
+}
 }
 }
 for (i = 0; i  def-nb_args; i++) {
-- 
1.7.10.4




[Qemu-devel] [PATCH] kvm: fix traces to use %x instead of %d

2013-09-03 Thread Alexey Kardashevskiy
KVM request types are normally defined using hex constants but QEMU traces
print decimal values instead what is not very convinient.

This changes the request type format from %d to %x.

Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---
 trace-events | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/trace-events b/trace-events
index 4574f29..24cf4d2 100644
--- a/trace-events
+++ b/trace-events
@@ -1171,9 +1171,9 @@ virtio_ccw_new_device(int cssid, int ssid, int schid, int 
devno, const char *dev
 migrate_set_state(int new_state) new state %d
 
 # kvm-all.c
-kvm_ioctl(int type, void *arg) type %d, arg %p
-kvm_vm_ioctl(int type, void *arg) type %d, arg %p
-kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %d, arg 
%p
+kvm_ioctl(int type, void *arg) type %x, arg %p
+kvm_vm_ioctl(int type, void *arg) type %x, arg %p
+kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %x, arg 
%p
 kvm_run_exit(int cpu_index, uint32_t reason) cpu_index %d, reason %d
 
 # memory.c
-- 
1.8.4.rc4




[Qemu-devel] [PATCH] exec: avoid tcg_commit when kvm_enabled

2013-09-03 Thread liguang
Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 exec.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/exec.c b/exec.c
index 3ca9381..4509daa 100644
--- a/exec.c
+++ b/exec.c
@@ -1824,7 +1824,9 @@ static void memory_map_init(void)
 address_space_init(address_space_io, system_io, I/O);
 
 memory_listener_register(core_memory_listener, address_space_memory);
-memory_listener_register(tcg_memory_listener, address_space_memory);
+if (!kvm_enabled()) {
+memory_listener_register(tcg_memory_listener, address_space_memory);
+}
 }
 
 MemoryRegion *get_system_memory(void)
-- 
1.7.2.5




[Qemu-devel] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread liguang
Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 cputlb.c |   15 ---
 1 files changed, 0 insertions(+), 15 deletions(-)

diff --git a/cputlb.c b/cputlb.c
index 977c0ca..08e50e0 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -169,21 +169,6 @@ static inline ram_addr_t 
qemu_ram_addr_from_host_nofail(void *ptr)
 return ram_addr;
 }
 
-static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
-{
-ram_addr_t ram_addr;
-void *p;
-
-if (tlb_is_dirty_ram(tlb_entry)) {
-p = (void *)(uintptr_t)((tlb_entry-addr_write  TARGET_PAGE_MASK)
-+ tlb_entry-addend);
-ram_addr = qemu_ram_addr_from_host_nofail(p);
-if (!cpu_physical_memory_is_dirty(ram_addr)) {
-tlb_entry-addr_write |= TLB_NOTDIRTY;
-}
-}
-}
-
 void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length)
 {
 CPUState *cpu;
-- 
1.7.2.5




[Qemu-devel] [PATCH] gitignore: ignore files generated by GNU GLOBAL

2013-09-03 Thread liguang
Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 .gitignore |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index d2c5c2f..97d7a2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -108,4 +108,7 @@ pc-bios/s390-ccw/s390-ccw.img
 cscope.*
 tags
 TAGS
+GTAGS
+GRTAGS
+GPATH
 *~
-- 
1.7.2.5




Re: [Qemu-devel] [PATCH v4 2/5] qcow2-cluster: Expand zero clusters

2013-09-03 Thread Max Reitz

Am 02.09.2013 17:13, schrieb Kevin Wolf:

Am 02.09.2013 um 12:04 hat Max Reitz geschrieben:

Add functionality for expanding zero clusters. This is necessary for
downgrading the image version to one without zero cluster support.

For non-backed images, this function may also just discard zero clusters
instead of truly expanding them.

Signed-off-by: Max Reitz mre...@redhat.com
---
  block/qcow2-cluster.c  | 228 +
  block/qcow2-refcount.c |  29 ---
  block/qcow2.h  |   5 ++
  3 files changed, 248 insertions(+), 14 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 2d5aa92..c90fb51 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1497,3 +1497,231 @@ fail:
  
  return ret;

  }
+
+/*
+ * Expands all zero clusters in a specific L1 table (or deallocates them, for
+ * non-backed non-pre-allocated zero clusters).
+ *
+ * expanded_clusters is a bitmap where every bit corresponds to one cluster in
+ * the image file; a bit gets set if the corresponding cluster has been used 
for
+ * zero expansion (i.e., has been filled with zeroes and is referenced from an
+ * L2 table). nb_clusters contains the total cluster count of the image file,
+ * i.e., the number of bits in expanded_clusters.
+ */
+static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
+  int l1_size, uint8_t *expanded_clusters,
+  uint64_t nb_clusters)
+{
+BDRVQcowState *s = bs-opaque;
+bool is_active_l1 = (l1_table == s-l1_table);
+uint64_t *l2_table = NULL;
+int ret;
+int i, j;
+
+if (!is_active_l1) {
+/* inactive L2 tables require a buffer to be stored in when loading
+ * them from disk */
+l2_table = qemu_blockalign(bs, s-cluster_size);
+}
+
+for (i = 0; i  l1_size; i++) {
+uint64_t l2_offset = l1_table[i]  L1E_OFFSET_MASK;
+bool l2_dirty = false;
+
+if (!l2_offset) {
+/* unallocated */
+continue;
+}
+
+if (is_active_l1) {
+/* get active L2 tables from cache */
+ret = qcow2_cache_get(bs, s-l2_table_cache, l2_offset,
+(void **)l2_table);
+} else {
+/* load inactive L2 tables from disk */
+ret = bdrv_read(bs-file, l2_offset / BDRV_SECTOR_SIZE,
+(void *)l2_table, s-cluster_sectors);
+}
+if (ret  0) {
+goto fail;
+}
+
+for (j = 0; j  s-l2_size; j++) {
+uint64_t l2_entry = be64_to_cpu(l2_table[j]);
+int64_t offset = l2_entry  L2E_OFFSET_MASK, cluster_index;
+int cluster_type = qcow2_get_cluster_type(l2_entry);
+
+if (cluster_type == QCOW2_CLUSTER_NORMAL) {
+cluster_index = offset  s-cluster_bits;
+assert((cluster_index = 0)  (cluster_index  nb_clusters));
+if (expanded_clusters[cluster_index / 8] 
+(1  (cluster_index % 8))) {
+/* Probably a shared L2 table; this cluster was a zero
+ * cluster which has been expanded, its refcount
+ * therefore most likely requires an update. */
+ret = qcow2_update_cluster_refcount(bs, cluster_index, 1,
+QCOW2_DISCARD_NEVER);
+if (ret  0) {
+goto fail;
+}
+/* Since we just increased the refcount, the COPIED flag 
may
+ * no longer be set. */
+l2_table[j] = cpu_to_be64(l2_entry  ~QCOW_OFLAG_COPIED);
+l2_dirty = true;
+}
+continue;
+}
+else if (qcow2_get_cluster_type(l2_entry) != QCOW2_CLUSTER_ZERO) {
+continue;
+}
+
+if (!offset) {
+/* not preallocated */
+if (!bs-backing_hd) {
+/* not backed; therefore we can simply deallocate the
+ * cluster */
+l2_table[j] = 0;
+l2_dirty = true;
+continue;
+}
+
+offset = qcow2_alloc_clusters(bs, s-cluster_size);
+if (offset  0) {
+ret = offset;
+goto fail;
+}
+}
+
+ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
+offset, s-cluster_size);
+if (ret  0) {
+qcow2_free_clusters(bs, offset, s-cluster_size,
+QCOW2_DISCARD_ALWAYS);
+goto fail;
+}
+
+ret = bdrv_write_zeroes(bs-file, offset / BDRV_SECTOR_SIZE,
+

Re: [Qemu-devel] [PATCH v4 5/5] qemu-iotest: qcow2 image option amendment

2013-09-03 Thread Max Reitz

Am 02.09.2013 17:36, schrieb Kevin Wolf:

Am 02.09.2013 um 12:04 hat Max Reitz geschrieben:

Add tests for qemu-img amend on qcow2 image files.

Signed-off-by: Max Reitz mre...@redhat.com
---
  tests/qemu-iotests/061 | 178 +++
  tests/qemu-iotests/061.out | 349 +
  tests/qemu-iotests/group   |   1 +
  3 files changed, 528 insertions(+)
  create mode 100755 tests/qemu-iotests/061
  create mode 100644 tests/qemu-iotests/061.out
+echo
+echo === Testing version upgrade and resize ===
+echo
+IMGOPTS=compat=0.10 _make_test_img 64M
+$QEMU_IO -c write -P 0x2a 42M 64k $TEST_IMG | _filter_qemu_io
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o compat=1.1,lazy_refcounts=on,size=128M $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IO -c read -P 0x2a 42M 64k $TEST_IMG | _filter_qemu_io
+_check_test_img

Your reference output isn't correct for this test: It expects a 64 MB
image after the amend. Looks like there's a bug somewhere.

Kevin

Oh, right, thanks for catching it!

Max



Re: [Qemu-devel] [PATCH 0/4] tcg/optimize: fixes and improvements

2013-09-03 Thread Paolo Bonzini
Il 03/09/2013 08:27, Aurelien Jarno ha scritto:
 This patchset first fixes known-zero bits optimization so that it is
 actually used, and does some further optimizations for 32-bit ops and
 unsigned loads.
 
 Aurelien Jarno (4):
   tcg/optimize: fix know-zero bits optimization
   tcg/optimize: fix known-zero bits for right shift ops
   tcg/optimize: improve known-zero bits for 32-bit ops
   tcg/optimize: add known-zero bits compute for load ops
 
  tcg/optimize.c |   48 +++-
  1 file changed, 43 insertions(+), 5 deletions(-)
 

Commit message 1 is a bit misleading, because the optimization still
works for quite a few cases involving constant and copy propagation.
However, I had the same patch in my queue, so I can't deny that there is
a problem. :)

Two questions:

1) should patch 2 be CCed to qemu-stable?

2) should patches 1 and 2 be inverted to avoid triggering bugs?

Paolo



Re: [Qemu-devel] [PULL v2 22/26] qcow2-refcount: Move OFLAG_COPIED checks

2013-09-03 Thread Kevin Wolf
Am 02.09.2013 um 15:52 hat Stefan Hajnoczi geschrieben:
 On Mon, Sep 2, 2013 at 10:49 AM, Kevin Wolf kw...@redhat.com wrote:
  From: Max Reitz mre...@redhat.com
 
  Move the OFLAG_COPIED checks out of check_refcounts_l1 and
  check_refcounts_l2 and after the actual refcount checks/fixes (since the
  refcounts might actually change there).
 
  Signed-off-by: Max Reitz mre...@redhat.com
  Signed-off-by: Kevin Wolf kw...@redhat.com
  ---
   block/qcow2-refcount.c | 115 
  +++--
   1 file changed, 82 insertions(+), 33 deletions(-)
 
 This patch breaks qemu-iotests 039 as follows:

Anthony, please pull anyway.

This is just a missing update to the reference output of the test case
when run with cache=writethrough. Max sent a follow-up that Stefan will
include in the next pull request.

Kevin



Re: [Qemu-devel] [PATCH] kvm: fix traces to use %x instead of %d

2013-09-03 Thread Paolo Bonzini
Il 03/09/2013 08:43, Alexey Kardashevskiy ha scritto:
 KVM request types are normally defined using hex constants but QEMU traces
 print decimal values instead what is not very convinient.
 
 This changes the request type format from %d to %x.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
  trace-events | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/trace-events b/trace-events
 index 4574f29..24cf4d2 100644
 --- a/trace-events
 +++ b/trace-events
 @@ -1171,9 +1171,9 @@ virtio_ccw_new_device(int cssid, int ssid, int schid, 
 int devno, const char *dev
  migrate_set_state(int new_state) new state %d
  
  # kvm-all.c
 -kvm_ioctl(int type, void *arg) type %d, arg %p
 -kvm_vm_ioctl(int type, void *arg) type %d, arg %p
 -kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %d, 
 arg %p
 +kvm_ioctl(int type, void *arg) type %x, arg %p
 +kvm_vm_ioctl(int type, void *arg) type %x, arg %p
 +kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %x, 
 arg %p
  kvm_run_exit(int cpu_index, uint32_t reason) cpu_index %d, reason %d
  
  # memory.c
 

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




Re: [Qemu-devel] [PATCH] gitignore: ignore files generated by GNU GLOBAL

2013-09-03 Thread Peter Maydell
On 3 September 2013 08:06, liguang lig.f...@cn.fujitsu.com wrote:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  .gitignore |3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)

 diff --git a/.gitignore b/.gitignore
 index d2c5c2f..97d7a2f 100644
 --- a/.gitignore
 +++ b/.gitignore
 @@ -108,4 +108,7 @@ pc-bios/s390-ccw/s390-ccw.img
  cscope.*
  tags
  TAGS
 +GTAGS
 +GRTAGS
 +GPATH
  *~

Please do this sort of thing in your local git configuration;
if it's not a file that QEMU's own build process produces
it shouldn't really be in our .gitignore. (We already have too
much in there in my opinion.)

Previous discussion on the subject:
http://lists.nongnu.org/archive/html/qemu-devel/2013-06/msg01888.html

thanks
-- PMM



Re: [Qemu-devel] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread Paolo Bonzini
Il 03/09/2013 09:05, liguang ha scritto:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  cputlb.c |   15 ---
  1 files changed, 0 insertions(+), 15 deletions(-)
 
 diff --git a/cputlb.c b/cputlb.c
 index 977c0ca..08e50e0 100644
 --- a/cputlb.c
 +++ b/cputlb.c
 @@ -169,21 +169,6 @@ static inline ram_addr_t 
 qemu_ram_addr_from_host_nofail(void *ptr)
  return ram_addr;
  }
  
 -static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
 -{
 -ram_addr_t ram_addr;
 -void *p;
 -
 -if (tlb_is_dirty_ram(tlb_entry)) {
 -p = (void *)(uintptr_t)((tlb_entry-addr_write  TARGET_PAGE_MASK)
 -+ tlb_entry-addend);
 -ram_addr = qemu_ram_addr_from_host_nofail(p);
 -if (!cpu_physical_memory_is_dirty(ram_addr)) {
 -tlb_entry-addr_write |= TLB_NOTDIRTY;
 -}
 -}
 -}
 -
  void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length)
  {
  CPUState *cpu;
 

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

and CCing qemu-trivial.

Paolo



[Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable

2013-09-03 Thread mrezanin
From: Miroslav Rezanina mreza...@redhat.com

Use usb_legacy_register handling to create bt-dongle device. This allows
to disable usb-bt-dongle device using CONFIG_BLUETOOTH option.

Signed-off-by: Miroslav Rezanina mreza...@redhat.com
---
 hw/bt/core.c   | 25 
 hw/bt/hci.c| 51 
 hw/usb/Makefile.objs   |  3 --
 hw/usb/dev-bluetooth.c | 10 ++-
 include/hw/bt.h|  3 ++
 include/hw/usb.h   |  3 --
 vl.c   | 79 ++
 7 files changed, 91 insertions(+), 83 deletions(-)

diff --git a/hw/bt/core.c b/hw/bt/core.c
index 49012e0..ef27b15 100644
--- a/hw/bt/core.c
+++ b/hw/bt/core.c
@@ -119,3 +119,28 @@ void bt_device_done(struct bt_device_s *dev)
 
 *p = dev-next;
 }
+
+static struct bt_vlan_s {
+struct bt_scatternet_s net;
+int id;
+struct bt_vlan_s *next;
+} *first_bt_vlan;
+
+/* find or alloc a new bluetooth VLAN */
+struct bt_scatternet_s *qemu_find_bt_vlan(int id)
+{
+struct bt_vlan_s **pvlan, *vlan;
+for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) {
+if (vlan-id == id) {
+return vlan-net;
+}
+}
+vlan = g_malloc0(sizeof(struct bt_vlan_s));
+vlan-id = id;
+pvlan = first_bt_vlan;
+while (*pvlan != NULL) {
+pvlan = (*pvlan)-next;
+}
+*pvlan = vlan;
+return vlan-net;
+}
diff --git a/hw/bt/hci.c b/hw/bt/hci.c
index d1c0604..d69ab53 100644
--- a/hw/bt/hci.c
+++ b/hw/bt/hci.c
@@ -429,6 +429,24 @@ static const uint8_t bt_event_reserved_mask[8] = {
 0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00,
 };
 
+
+static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
+{
+}
+
+static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
+{
+return -ENOTSUP;
+}
+
+struct HCIInfo null_hci = {
+.cmd_send = null_hci_send,
+.sco_send = null_hci_send,
+.acl_send = null_hci_send,
+.bdaddr_set = null_hci_addr_set,
+};
+
+
 static inline uint8_t *bt_hci_event_start(struct bt_hci_s *hci,
 int evt, int len)
 {
@@ -2176,6 +2194,39 @@ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
 return s-info;
 }
 
+struct HCIInfo *hci_init(const char *str)
+{
+char *endp;
+struct bt_scatternet_s *vlan = 0;
+
+if (!strcmp(str, null)) {
+/* null */
+return null_hci;
+} else if (!strncmp(str, host, 4)  (str[4] == '\0' || str[4] == ':')) {
+/* host[:hciN] */
+return bt_host_hci(str[4] ? str + 5 : hci0);
+} else if (!strncmp(str, hci, 3)) {
+/* hci[,vlan=n] */
+if (str[3]) {
+if (!strncmp(str + 3, ,vlan=, 6)) {
+vlan = qemu_find_bt_vlan(strtol(str + 9, endp, 0));
+if (*endp) {
+vlan = 0;
+}
+}
+} else {
+vlan = qemu_find_bt_vlan(0);
+}
+if (vlan) {
+return bt_new_hci(vlan);
+}
+}
+
+fprintf(stderr, qemu: Unknown bluetooth HCI `%s'.\n, str);
+
+return 0;
+}
+
 static void bt_hci_done(struct HCIInfo *info)
 {
 struct bt_hci_s *hci = hci_from_info(info);
diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index f9695e7..a3eac3e 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -18,9 +18,6 @@ common-obj-$(CONFIG_USB_STORAGE_UAS)  += dev-uas.o
 common-obj-$(CONFIG_USB_AUDIO)+= dev-audio.o
 common-obj-$(CONFIG_USB_SERIAL)   += dev-serial.o
 common-obj-$(CONFIG_USB_NETWORK)  += dev-network.o
-
-# FIXME: make configurable too
-CONFIG_USB_BLUETOOTH := y
 common-obj-$(CONFIG_USB_BLUETOOTH)+= dev-bluetooth.o
 
 ifeq ($(CONFIG_USB_SMARTCARD),y)
diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index f2fc2a8..7f292b1 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -511,10 +511,17 @@ static int usb_bt_initfn(USBDevice *dev)
 return 0;
 }
 
-USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci)
+static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
 {
 USBDevice *dev;
 struct USBBtState *s;
+HCIInfo *hci;
+
+if (*cmdline) {
+hci = hci_init(cmdline);
+} else {
+hci = bt_new_hci(qemu_find_bt_vlan(0));
+}
 
 if (!hci)
 return NULL;
@@ -566,6 +573,7 @@ static const TypeInfo bt_info = {
 static void usb_bt_register_types(void)
 {
 type_register_static(bt_info);
+usb_legacy_register(usb-bt-dongle, bt, usb_bt_init);
 }
 
 type_init(usb_bt_register_types)
diff --git a/include/hw/bt.h b/include/hw/bt.h
index 830af94..49a9d03 100644
--- a/include/hw/bt.h
+++ b/include/hw/bt.h
@@ -108,12 +108,15 @@ struct bt_device_s {
 uint16_t clkoff;   /* Note: Always little-endian */
 };
 
+extern struct HCIInfo null_hci;
 /* bt.c */
 void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net);
 void bt_device_done(struct bt_device_s *dev);
+struct bt_scatternet_s *qemu_find_bt_vlan(int 

[Qemu-devel] [RFC PATCH] spapr: support time base offset migration

2013-09-03 Thread Alexey Kardashevskiy
This allows guests to have a different timebase origin from the host.

This is needed for migration, where a guest can migrate from one host
to another and the two hosts might have a different timebase origin.
However, the timebase seen by the guest must not go backwards, and
should go forwards only by a small amount corresponding to the time
taken for the migration.

This is only supported for recent POWER hardware which has the TBU40
(timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
970.

This adds kvm_access_one_reg() to access a special register which is not
in env-spr.

The feature must be present in the host kernel.

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

This is an RFC but not a final patch. Can break something but I just do not see 
what.

---
 hw/ppc/ppc.c | 49 +
 include/hw/ppc/ppc.h |  4 
 target-ppc/kvm.c | 23 +++
 target-ppc/machine.c | 44 
 trace-events |  3 +++
 5 files changed, 123 insertions(+)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 1e3cab3..7d08c9a 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -31,6 +31,7 @@
 #include hw/loader.h
 #include sysemu/kvm.h
 #include kvm_ppc.h
+#include trace.h
 
 //#define PPC_DEBUG_IRQ
 #define PPC_DEBUG_TB
@@ -796,6 +797,54 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t 
freq)
 cpu_ppc_store_purr(cpu, 0xULL);
 }
 
+/*
+ * Calculate timebase on the destination side of migration
+ *
+ * We calculate new timebase offset as shown below:
+ * 1) Gtb2 = Gtb1 + max(tod2 - tod1, 0)
+ *Gtb2 = tb2 + off2
+ *Gtb1 = tb1 + off1
+ * 2) tb2 + off2 = tb1 + off1 + max(tod2 - tod1, 0)
+ * 3) off2 = tb1 - tb2 + off1 + max(tod2 - tod1, 0)
+ *
+ * where:
+ * Gtb2 - destination guest timebase
+ * tb2 - destination host timebase
+ * off2 - destination timebase offset
+ * tod2 - destination time of the day
+ * Gtb1 - source guest timebase
+ * tb1 - source host timebase
+ * off1 - source timebase offset
+ * tod1 - source time of the day
+ *
+ * The result we want is in @off2
+ *
+ * Two conditions must be met for @off2:
+ * 1) off2 must be multiple of 2^24 ticks as it will be set via TBU40 SPR
+ * 2) Gtb2 = Gtb1
+ */
+void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env)
+{
+uint64_t tb2, tod2, off2;
+int ratio = tb_env-tb_freq / 100;
+struct timeval tv;
+
+tb2 = cpu_get_real_ticks();
+gettimeofday(tv, NULL);
+tod2 = tv.tv_sec * 100 + tv.tv_usec;
+
+off2 = tb_env-timebase - tb2 + tb_env-tb_offset;
+if (tod2  tb_env-time_of_the_day) {
+off2 += (tod2 - tb_env-time_of_the_day) * ratio;
+}
+off2 = ROUND_UP(off2, 1  24);
+
+trace_ppc_tb_adjust(tb_env-tb_offset, off2,
+(int64_t)off2 - tb_env-tb_offset);
+
+tb_env-tb_offset = off2;
+}
+
 /* Set up (once) timebase frequency (in Hz) */
 clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
 {
diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h
index 132ab97..235871c 100644
--- a/include/hw/ppc/ppc.h
+++ b/include/hw/ppc/ppc.h
@@ -32,6 +32,9 @@ struct ppc_tb_t {
 uint64_t purr_start;
 void *opaque;
 uint32_t flags;
+/* Cached values for live migration purposes */
+uint64_t timebase;
+uint64_t time_of_the_day;
 };
 
 /* PPC Timers flags */
@@ -46,6 +49,7 @@ struct ppc_tb_t {
*/
 
 uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset);
+void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env);
 clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq);
 /* Embedded PowerPC DCR management */
 typedef uint32_t (*dcr_read_cb)(void *opaque, int dcrn);
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 7af9e3d..93df955 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -35,6 +35,7 @@
 #include hw/sysbus.h
 #include hw/ppc/spapr.h
 #include hw/ppc/spapr_vio.h
+#include hw/ppc/ppc.h
 #include sysemu/watchdog.h
 
 //#define DEBUG_KVM
@@ -761,6 +762,22 @@ static int kvm_put_vpa(CPUState *cs)
 }
 #endif /* TARGET_PPC64 */
 
+static int kvm_access_one_reg(CPUState *cs, bool set, __u64 id, void *addr)
+{
+struct kvm_one_reg reg = {
+.id = id,
+.addr = (uintptr_t)addr,
+};
+int ret = kvm_vcpu_ioctl(cs, set ? KVM_SET_ONE_REG : KVM_GET_ONE_REG, 
reg);
+
+if (ret) {
+DPRINTF(Unable to %s time base offset to KVM: %s\n,
+set ? set : get, strerror(errno));
+}
+
+return ret;
+}
+
 int kvm_arch_put_registers(CPUState *cs, int level)
 {
 PowerPCCPU *cpu = POWERPC_CPU(cs);
@@ -873,6 +890,9 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 DPRINTF(Warning: Unable to set VPA information to KVM\n);
 }
 }
+
+kvm_access_one_reg(cs, 1, KVM_REG_PPC_TB_OFFSET,
+   env-tb_env-tb_offset);
 #endif /* TARGET_PPC64 */
 }
 

Re: [Qemu-devel] [PATCH v3 00/29] tcg-aarch64 improvements

2013-09-03 Thread Richard W.M. Jones
On Mon, Sep 02, 2013 at 10:54:34AM -0700, Richard Henderson wrote:
 I'm not sure if I posted v2 or not, but my branch is named -3,
 therefore this is v3.  ;-)
 
 The jumbo fixme patch from v1 has been split up.  This has been
 updated for the changes in the tlb helpers over the past few weeks.
 For the benefit of trivial conflict resolution, it's relative to a
 tree that contains basically all of my patches.
 
 See git://github.com/rth7680/qemu.git tcg-aarch-3 for the tree, if
 you find yourself missing any of the dependencies.

Is there a way yet to compile and run a 'qemu-system-aarch64'? [on a
regular x86-64 host]

I tried your git branch above and Peter's v5 patch posted a while back
(which doesn't cleanly apply), but I don't seem to have the right
combination of bits to make a working binary.

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/



Re: [Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable

2013-09-03 Thread Gerd Hoffmann
 diff --git a/hw/bt/core.c b/hw/bt/core.c
 index 49012e0..ef27b15 100644
 --- a/hw/bt/core.c
 +++ b/hw/bt/core.c
 @@ -119,3 +119,28 @@ void bt_device_done(struct bt_device_s *dev)
  
  *p = dev-next;
  }
 +
 +static struct bt_vlan_s {
 +struct bt_scatternet_s net;
 +int id;
 +struct bt_vlan_s *next;
 +} *first_bt_vlan;
 +
 +/* find or alloc a new bluetooth VLAN */
 +struct bt_scatternet_s *qemu_find_bt_vlan(int id)
 +{
 +struct bt_vlan_s **pvlan, *vlan;
 +for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) {
 +if (vlan-id == id) {
 +return vlan-net;
 +}
 +}
 +vlan = g_malloc0(sizeof(struct bt_vlan_s));
 +vlan-id = id;
 +pvlan = first_bt_vlan;
 +while (*pvlan != NULL) {
 +pvlan = (*pvlan)-next;
 +}
 +*pvlan = vlan;
 +return vlan-net;
 +}

This (and some other bits) are pure code motion from vl.c, correct?
Can you split this into a separate patch please?  That'll simplify the
review o the actual code changes.

It also doesn't make much sense to compile hw/bt/ with
CONFIG_USB_BLUETOOTH=n.  It's basically dead code then.

cheers,
  Gerd





Re: [Qemu-devel] [PATCHv2] spice-core: Use g_strdup_printf instead of snprintf

2013-09-03 Thread Gerd Hoffmann
On Mo, 2013-09-02 at 15:41 +0200, Christophe Fergeau wrote:
 Several places in spice-core.c were using either g_malloc+snprintf
 or snprintf+g_strdup to achieve the same result as g_strdup_printf.

Added to spice patch queue.

thanks,
  Gerd





Re: [Qemu-devel] [PATCH v3 00/29] tcg-aarch64 improvements

2013-09-03 Thread Laurent Desnogues
On Tue, Sep 3, 2013 at 9:37 AM, Richard W.M. Jones rjo...@redhat.com wrote:
 On Mon, Sep 02, 2013 at 10:54:34AM -0700, Richard Henderson wrote:
 I'm not sure if I posted v2 or not, but my branch is named -3,
 therefore this is v3.  ;-)

 The jumbo fixme patch from v1 has been split up.  This has been
 updated for the changes in the tlb helpers over the past few weeks.
 For the benefit of trivial conflict resolution, it's relative to a
 tree that contains basically all of my patches.

 See git://github.com/rth7680/qemu.git tcg-aarch-3 for the tree, if
 you find yourself missing any of the dependencies.

 Is there a way yet to compile and run a 'qemu-system-aarch64'? [on a
 regular x86-64 host]

The current public work is only to run QEMU on Aarch64 host, not
Aarch64 on other hosts ;-)

 I tried your git branch above and Peter's v5 patch posted a while back
 (which doesn't cleanly apply), but I don't seem to have the right
 combination of bits to make a working binary.

You'll need a cross-compiler or ARM foundation model.


Laurent



Re: [Qemu-devel] [libvirt] [PATCH 3/5] qemu: add usb-bot support from disks points of view

2013-09-03 Thread Gerd Hoffmann
On Mo, 2013-09-02 at 13:57 +0100, Daniel P. Berrange wrote:
 On Mon, Sep 02, 2013 at 05:38:42PM +0800, Guannan Ren wrote:
  usb-bot only supports 16 luns(0~15) and they must be contiguous,
  (using lun 0 and 2 without 1 doesn't work). In this case qemu
  doesn't throw an error, we can not find the lun 2 in guests. So
  Adding a checking function in libvirt to prevent from this case.
 
 Hmm, this seems like a problematic restriction.

It's how the hardware works.

 How does this work if we start off a guest with 3 disks
 attached to the usb-bot SCSI controller. Then hot-unplug
 the 2nd disk.

You can't hotplug individual luns anyway.

cheers,
  Gerd





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

2013-09-03 Thread Stefan Hajnoczi
On Mon, Sep 02, 2013 at 02:57:23PM +0200, Benoît Canet wrote:
 
 I don't see the point of using hashes.
 Using hashes means that at least one extra read will be done on the target to
 compute the candidate target hash.
 It's bad for a cloud provider where IOs count is a huge cost.
 
 Another structure to replace a bitmap (smaller on the canonical case) would be
 a block table as described in the Hystor paper:
 www.cse.ohio-state.edu/~fchen/paper/papers/ics11.pdf

This is similar to syncing image formats that use a revision number for
each cluster instead of a hash.

The problem with counters is overflow.  In the case of Hystor it is not
necessary to preserve exact counts.  A dirty bitmap must mark a block
dirty if it has been modified, otherwise there is a risk of data loss.

A bit more than just counters are necessary to implement a persistent
dirty bitmap, but maybe it's possible with some additional state.

Stefan



[Qemu-devel] [PULL 2/6] s390/dump: zero out padding bytes in notes sections

2013-09-03 Thread Christian Borntraeger
The prstatus of an s390x dump contains several padding areas. Zero out
these bytes to make reading the notes section easier with a hexdump.

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 target-s390x/arch_dump.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target-s390x/arch_dump.c b/target-s390x/arch_dump.c
index 9d36116..5cbb53c 100644
--- a/target-s390x/arch_dump.c
+++ b/target-s390x/arch_dump.c
@@ -151,6 +151,7 @@ static int s390x_write_all_elf64_notes(const char 
*note_name,
 int ret = -1;
 
 for (nf = note_func; nf-note_contents_func; nf++) {
+memset(note, 0, sizeof(note));
 note.hdr.n_namesz = cpu_to_be32(sizeof(note.name));
 note.hdr.n_descsz = cpu_to_be32(nf-contents_size);
 strncpy(note.name, note_name, sizeof(note.name));
-- 
1.8.3.1




[Qemu-devel] [PULL 3/6] s390/ipl: Fix waiting for virtio processing

2013-09-03 Thread Christian Borntraeger
From: Cornelia Huck cornelia.h...@de.ibm.com

The guest side must not manipulate the index for the used buffers. Instead,
remember the state of the used buffer locally and wait until it has moved.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
Acked-by: Alexander Graf ag...@suse.de
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 pc-bios/s390-ccw/virtio.c | 7 ---
 pc-bios/s390-ccw/virtio.h | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
index 49f2d29..4d6e48f 100644
--- a/pc-bios/s390-ccw/virtio.c
+++ b/pc-bios/s390-ccw/virtio.c
@@ -123,6 +123,7 @@ static void vring_init(struct vring *vr, unsigned int num, 
void *p,
 /* We're running with interrupts off anyways, so don't bother */
 vr-used-flags = VRING_USED_F_NO_NOTIFY;
 vr-used-idx = 0;
+vr-used_idx = 0;
 
 debug_print_addr(init vr, vr);
 }
@@ -150,8 +151,6 @@ static void vring_send_buf(struct vring *vr, void *p, int 
len, int flags)
 if (!(flags  VRING_DESC_F_NEXT)) {
 vr-avail-idx++;
 }
-
-vr-used-idx = vr-next_idx;
 }
 
 static u64 get_clock(void)
@@ -180,7 +179,8 @@ static int vring_wait_reply(struct vring *vr, int timeout)
 struct subchannel_id schid = vr-schid;
 int r = 0;
 
-while (vr-used-idx == vr-next_idx) {
+/* Wait until the used index has moved. */
+while (vr-used-idx == vr-used_idx) {
 vring_notify(schid);
 if (timeout  (get_second() = target_second)) {
 r = 1;
@@ -189,6 +189,7 @@ static int vring_wait_reply(struct vring *vr, int timeout)
 yield();
 }
 
+vr-used_idx = vr-used-idx;
 vr-next_idx = 0;
 vr-desc[0].len = 0;
 vr-desc[0].flags = 0;
diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h
index 86fdd57..772a63f 100644
--- a/pc-bios/s390-ccw/virtio.h
+++ b/pc-bios/s390-ccw/virtio.h
@@ -115,6 +115,7 @@ struct vring_used {
 struct vring {
 unsigned int num;
 int next_idx;
+int used_idx;
 struct vring_desc *desc;
 struct vring_avail *avail;
 struct vring_used *used;
-- 
1.8.3.1




[Qemu-devel] [PULL 4/6] s390/ipl: Update the s390-ccw.img rom

2013-09-03 Thread Christian Borntraeger
Rebuild of the virtio-ccw rom containing these patches:
1. s390/ipl: Fix waiting for virtio processing

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 pc-bios/s390-ccw.img | Bin 9432 - 9336 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/pc-bios/s390-ccw.img b/pc-bios/s390-ccw.img
index 
05fc7c2fae97caf222d9ccce88631d8a20ccd565..6727f0ca39d6bf6d114974d1535cb7ad9e56355f
 100644
GIT binary patch
literal 9336
zcmeHNe{dA_6@R;TxjXK{v4jW*q_V;21c7)2s{HDA$SH$af?BNb%tDW7jk3Bnad@O
zPJhsv*3e=bsVMfxc%z969j!Mhb)fCjt?L_|Z}Z+p#0!qm$xJ%OG274gySMqF
zGo5zEe!vDncesOzVCbQ``+ih?{_zs{rW8%BcdqKcoS(h`kdiC#xl76`L+x$*Dps
z$wLZFBOk_0w#c5BIPspfM-C+lp0qg*#J5VWAkNByrw;Js6Ar$tYY`a_1yNjyr0pX
zBut@TRoL?m$6r#f7By)EPY;`(3_uScD-iQz%%yjF09}ruRjRy`1~s-x!{SRzRSD
zKmmaQ0tEyL2ow+~AW%S{fItC(0s;jDK6M0gNi$3p`bqo=zg2G}-(6#dX;oSs`g#0e
z|6+sGNV*K}yMyycP%$#XGX9FzZni9~m)dgIkVM6Uv#k$9o%Qlb+9lJ*(FR)lgOi`
zDXQ%wK|4fLlQ9RhKFbHCK^0W0#=iGdKsM8;L@dvu81_p%ob#T1axAOl4XXxv8p
zM+EZ#XrSZ?+)E6}{3$$cMkf++Am@IRqIW7NbVf-m{v8@EAS!x{`%juVv~IynnPo
zmN?h-EiQEya|7h#dN1-w@8vo_(ng519lf}bi^9u+%KgxV4{fjlJB4+w0A}Yu-l{
zz^gHjR~?t{VODZanssdMBh1x=%?z7yDe#8e2Tr@pj6{gQ_FzCiZ}uxdkF}oX-iGN
zsT)%N9O~DuCJ~%=L+*!~9wx7~*vRW}Y`!lyLd1e;!Kfq@9geOM$!P3v_Xyw7L{
zXn_%yeBit3OWFqF7I{4D${PTEYKlHo*RzLialDC`p=TooDNfU1BSV=XmtTc=Yv*
zL#KHEZr(p;D3JEM5Sfrp1k-rRx722-jSOAez``zn5mKa-_GvuC2HJHYu)NoLS9
zXz6_Z{M?oXi87iq{V$G9hUA1zV1B}EwCmNqihKB!wulHhXs|jEu_TDyBW@|_ZlRL
zRLLCJD(T~ByZ*t^z7{dVXKvveTqniREN5tr^mq76B%-y;yQuT-jk$DKx{FWisw#T
z0JcD$SsFnOeZZYue`46U{aK89puHz15uiIPb48lncnBwg`xE8{QGF`8aCM@OpI
z`p2`$Csq%uW@FO}p5^@A#^EQN3t0{1^HOMLr$yAP=6YdLBnRm?VHBOqXHcqbR
z_L9uvUjtuCY9vVrEt_AxmtZq(UB+5I4~1$v$WeNsLdl!$#O+eX%DHQBB{PT^He|j
z0qqrq0L1FDda19w^op8ouH659~r#Sy4)b0WFB1Q|MUP+dIar7yV8P!LpA$%%)=x
zw($d^SGZbrrEy5m_B)wwW0-!*)!lWazVDb{a^15|x$A#BLtN9yx%T5AH2C_k%Jt
zkoyZg`I;MJH8^UdU?rg;I0nhc*qn`jBOXN(?eHR8gaw2hRk|{pS8qU}%NT)}lVb
z-tZ~#HVjPHRtJlI+d-1N2+2DD609?o}K2;;NjcaYU_|1HnWfIG@q+cU}eqFa)nvp
zStwZ!4?Vnc_JpdD@dobYHMy5ADCG8zz_(vB-?SQm7*1PmfqclRaAzNMG4Gi{u+`l
z(j$i-qQGJNE}N6^YwPqnQay^GyCLhQQbSTve}gl|tWtMw7{72%HqCMD^L||Czga
z){fxphAiYEnVZRE)U}e2(zwgp2dN@^Fw_^VP{xP`jQ4R9sN2VY`%qtRCwxq1xeJ
zog|B6+rzQ6SgO-o##1_+C7PdV57%h0|mMEQAn?Y#yQt?8t15Y-Yh}M*kp3=PZ%
zyTUXL8cVeef(w2x=ll*xYOo=ID{@ZjP?5QxRbl;ehNQ^kZcvpLy~~fR!Q+O41v@Z
z)T#^Cu7xf=SW!d|60Nu8C~6|5Tv^K5$^Qq{@mLJ1WmX^u-ObQpwgG%d#^N*eVyo
zTvou#p?E1hsZSQx92AFo%+kwQkaV24H0=?60_iLL(wlk+elV#5bCgv^?sLB
z#q7KgPO)bkUw_`3q)9L33NXP`gxAV2CbYd#OXdwb45qqQ%%#f8^S~U@}*p$M_=4
z0Y9U{@acI|wa*6O1n^nTo($SnTt0r1)$2)rK(R__|G@mgH(`W}Fco8?i#nabzt
z`I-4(9huLtbT?F;ENuG%gu_0rHZOl_aXj4;pa%$(M5xjwK!eqDmesStUO#+
zj@Vq0=i4+81$NCkR)Swz$b-t{}AJgc~CfJz%e78DFCO2z(~3W~552;#0FG{%v3$
z9K712;H_alRn$r5Gw}Td=KDwQ^L#SoakA!~XD7LLWRKf?n)|;D{yz=Irbm1_k~{T
z9ggX9MhtydVI#kX8tt_wC@MTZ#n0$P!9agXG%HRAYDIAiePGRo^@MDN$SkfSy
znZfJGx(jbnxwkID8|`|_XT^!uduN^4f9!abggS;`!wZlxuS(LRDO|hh)+gW3SAy
zu4o}Q@)RcIYZ5rit{||8QMnSNoQ)BX0XiptyrOsN#u0UbYYHHP~rt_wYI$+!6(
zy%G1n8}~Khe9=ZO19*5*GBSvlCTp4r$wTPws=fVC*^p1w5csF@96B5TcXX0wnX}V
zKheZ|TQVAxZ@)usNhNp4th9WjwL$p_0y)L+?`0J6Un7bZTHHtcz2XF1IAR+GFL=
zM{}{;0~^$hM2Yt9XjvC?}%sG*gScHZz=P-!6B?x9^Czr~M8;)z#k4_zxuRYl9_w
zk!`7XH0DS+noMG~%$AvGJ^BB2b=$OxHr#N#d`l{oOi^vJt1TwCC)4uwcv^01OE!=D
z-JEQ1No?;*MG;TCf0EvQ;Bq3?o3D1U7ZZA)?{ZoA0K%XEW5H=ckZo3MQY8uZxz
znPynl2)3!vfkSbngQJpYFgF@AVL`Q9B8X$jUuPQPS8JqLhi#b=xdEpre*``Nv3L
z2-TYfRdHsl1cmS^`QGurLZf$fm6^2*m3bz%I?Agn@Q*i3iFF+Wb!VSfn5gQur`%Z
za?g)7e#`2iaBiwI%_TKQXjNeQ{yhho)x?+Sd!|J`Z3eGhw?{N~{3g#22_x4|BK
z6YiwQR7qIh^GI@ngeBkGvkt2$6ueGdN=hmRdUfe~AC1+Hg-1;~4rHHe}ox#^c
zv72i`aATmy8=YfEg}}*Im!K4Z4mo@{PrJ1^f)?vlMyQD}K#?%uxcb0)8U?4_KUc
zQ-npIaltxw?l#9O!Wl@yddM|G?uQhah~eRbBVioNcj*T!LTGD4SD2@j@$C$tHVe6
z9J?V-;ZfxHE1)G4aYlk?Me%JXxJY30BxtxU^J5sb(11}NZJhAqHe~G{u6PuFj7JDu
z1jPR#@H}aYowY5=+4!zd)$Cg~;2WazHRCVx7F*yiyoeu(v`MV6;VhAXRt
z`k?M^Ws1+6o^b@mFGw7h5RVw+ie#L_W}a{_XxNV0rnWVZr!wnT+h~?8GGWYHNX08
zOZV{B)!%Hqy6y+J*4D0;D1uBUQu;ZRkd6lURJ$qS$LIPxf##gx@g+wFI~BasH(HI
zGo4CDo2V)s?@3ctQ)eet;UN{T+TPw()zp}i!DvWs4A6=MblBLinnfSNkwWx3$Jn
z6CiPVQij(N7OvcFg78H6`O_FV;Tyh(ZLXJ^vn~(~CZze8h%-;p@(wJ{@o;u%+
zIDE%0ALIR#obNOE(`IMI}#%MyAsUfET7U?Zkz^i$NlH}_+BRO@4P$}{*(X9KB;ei
zS3+ceXM*`XR$n;y#CFf)GuCX%a!G+xbI{74ql9nxBhYe!BwT59Y@lczK%UyQPg
U32@#56aKxd7D2r=jhYF0b?J4UH||9

literal 9432
zcmeHNeQX=$8Gp`kd~TAu*R*O)8?|pj1pPE_8(3SAxU?lrrKmM+QB%Qao!D(W(zrNI
z7Z4iJC?n;oZbc_1ZNpQEjsa7HSw%Zd;Hjw1Fg|S#n?J(xK%?k6=w*egf_R|``(?C
z!2V#;{@5SBh5{p=j(l*-}^q#*^M8(t*yo5k*IWeXb#4LA?K^I4qvrtL%X0VttKC-
zR7KM;=em`)ToFXh+cTFE9E6ID)hLWlWI2WYeCx)SmI@@M?Qpvh*W`V6N7Bu$}U
zHQI8Q3OjD|U)qs3mcAI7uZn3eu}46bjY@oR7;-0pVFWx@US5C6AUEo+t$C?ilt
zpo~BnfiePR1j-1M5hx2Mxcy98Gz)K;aW}KQ$VrwcEN^zewcq@n_{$ZIq~xG{e-W
zk6``?G!{W4L;f9?xP~;MD;OK?EJH}NHW6sj_r+Lrrl~;+Cl0s%p!$qhOV=|+^pJ
z@b`xlnmMOlXfX0=Y1*MZM^dm`J4H0Khp2hLd{*nXtf4=Vqz-31!RyV4CR^zDAz!2
zkWrl$q6DPbwo0M30htIJf01PVm?ntu9^zo%S1v^T5|b%vOylZD{I?5yD5m$V`
zpLD*qLEAtx`Ph4bXIYZp1Ia-vuZzCaeMC-k?LEF9`d`gj^G{vpja;zXS4TFeB{@
z@*cH*BFlxtrt08!tzljTvIgT0n{_jL+Do?xZz14^2+mcQS%nb0U-p2@VWXJ0XXd
zb4F+S0Lj)3dKS-RhLV{}8EpZ1Al+#oGx8e4nIL)fFywW@vxGR)wCbEZLId3M4tSQW

[Qemu-devel] [PULL 5/6] s390/cpu: Make setcc() function available to other files

2013-09-03 Thread Christian Borntraeger
From: Thomas Huth th...@linux.vnet.ibm.com

Moved the setcc() function to cpu.h so that it can be used by other
files, too. It now also does not modify the kvm state anymore since
this gets updated during kvm_arch_put_registers() anyway.

Signed-off-by: Thomas Huth th...@linux.vnet.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 target-s390x/cpu.h | 11 +--
 target-s390x/kvm.c | 12 
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 8be5648..a2c077b 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -148,6 +148,7 @@ typedef struct CPUS390XState {
 } CPUS390XState;
 
 #include cpu-qom.h
+#include sysemu/kvm.h
 
 /* distinguish between 24 bit and 31 bit addressing */
 #define HIGH_ORDER_BIT 0x8000
@@ -692,6 +693,14 @@ static inline const char *cc_name(int cc_op)
 return cc_names[cc_op];
 }
 
+static inline void setcc(S390CPU *cpu, uint64_t cc)
+{
+CPUS390XState *env = cpu-env;
+
+env-psw.mask = ~(3ull  44);
+env-psw.mask |= (cc  3)  44;
+}
+
 typedef struct LowCore
 {
 /* prefix area: defined by architecture */
@@ -1058,8 +1067,6 @@ void program_interrupt(CPUS390XState *env, uint32_t code, 
int ilen);
 void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp,
  uintptr_t retaddr);
 
-#include sysemu/kvm.h
-
 #ifdef CONFIG_KVM
 void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
uint16_t subchannel_nr, uint32_t io_int_parm,
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index dc1ed56..3dff6be 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -427,18 +427,6 @@ static void enter_pgmcheck(S390CPU *cpu, uint16_t code)
 kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code);
 }
 
-static inline void setcc(S390CPU *cpu, uint64_t cc)
-{
-CPUS390XState *env = cpu-env;
-CPUState *cs = CPU(cpu);
-
-cs-kvm_run-psw_mask = ~(3ull  44);
-cs-kvm_run-psw_mask |= (cc  3)  44;
-
-env-psw.mask = ~(3ul  44);
-env-psw.mask |= (cc  3)  44;
-}
-
 static int kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,
  uint16_t ipbh0)
 {
-- 
1.8.3.1




[Qemu-devel] [PULL 0/6] s390: cleanups and fixes

2013-09-03 Thread Christian Borntraeger
Alex,

the next bunch of patches for s390. If there are no complaints, I will
send out a pull request soon.

---snip---

The following changes since commit 4ff78e0dbcd5c795962567fdc1b31e9e03c55b07:

  Merge remote-tracking branch 'luiz/queue/qmp' into staging (2013-08-30 
12:26:04 -0500)

are available in the git repository at:


  git://github.com/borntraeger/qemu.git tags/s390-20130902

for you to fetch changes up to d66b1005d2ade6ce7854581aac6f3222f6dd7ea4:

  s390/ioinst: Moved the CC setting to the IO instruction handlers (2013-09-02 
16:55:14 +0200)


This is a bunch of cleanups and fixes for the s390 architecture.


Christian Borntraeger (2):
  s390/dump: zero out padding bytes in notes sections
  s390/ipl: Update the s390-ccw.img rom

Cornelia Huck (1):
  s390/ipl: Fix waiting for virtio processing

Thomas Huth (3):
  s390/kvm: Add check for priviledged SCLP handler
  s390/cpu: Make setcc() function available to other files
  s390/ioinst: Moved the CC setting to the IO instruction handlers

 pc-bios/s390-ccw.img  | Bin 9432 - 9336 bytes
 pc-bios/s390-ccw/virtio.c |   7 +--
 pc-bios/s390-ccw/virtio.h |   1 +
 target-s390x/arch_dump.c  |   1 +
 target-s390x/cpu.h|  11 -
 target-s390x/ioinst.c | 110 +-
 target-s390x/ioinst.h |  26 +--
 target-s390x/kvm.c|  54 ---
 8 files changed, 96 insertions(+), 114 deletions(-)




[Qemu-devel] [PULL 1/6] s390/kvm: Add check for priviledged SCLP handler

2013-09-03 Thread Christian Borntraeger
From: Thomas Huth th...@linux.vnet.ibm.com

The SCLP instruction is priviledged, so we should make sure that
we generate an exception when it is called from the problem state.

Signed-off-by: Thomas Huth th...@linux.vnet.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 target-s390x/kvm.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 185c8f5..dc1ed56 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -448,6 +448,10 @@ static int kvm_sclp_service_call(S390CPU *cpu, struct 
kvm_run *run,
 int r = 0;
 
 cpu_synchronize_state(CPU(cpu));
+if (env-psw.mask  PSW_MASK_PSTATE) {
+enter_pgmcheck(cpu, PGM_PRIVILEGED);
+return 0;
+}
 sccb = env-regs[ipbh0  0xf];
 code = env-regs[(ipbh0  0xf0)  4];
 
-- 
1.8.3.1




[Qemu-devel] [PULL 6/6] s390/ioinst: Moved the CC setting to the IO instruction handlers

2013-09-03 Thread Christian Borntraeger
From: Thomas Huth th...@linux.vnet.ibm.com

The IO instruction handlers now take care of setting the CC value on
their own, so that the confusing return code magic in kvm_handle_css_inst()
is not needed anymore.

Signed-off-by: Thomas Huth th...@linux.vnet.ibm.com
Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 target-s390x/ioinst.c | 110 +++---
 target-s390x/ioinst.h |  26 ++--
 target-s390x/kvm.c|  38 +++--
 3 files changed, 77 insertions(+), 97 deletions(-)

diff --git a/target-s390x/ioinst.c b/target-s390x/ioinst.c
index 85fd285..8d6363d 100644
--- a/target-s390x/ioinst.c
+++ b/target-s390x/ioinst.c
@@ -36,7 +36,7 @@ int ioinst_disassemble_sch_ident(uint32_t value, int *m, int 
*cssid, int *ssid,
 return 0;
 }
 
-int ioinst_handle_xsch(CPUS390XState *env, uint64_t reg1)
+void ioinst_handle_xsch(S390CPU *cpu, uint64_t reg1)
 {
 int cssid, ssid, schid, m;
 SubchDev *sch;
@@ -44,8 +44,8 @@ int ioinst_handle_xsch(CPUS390XState *env, uint64_t reg1)
 int cc;
 
 if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid)) {
-program_interrupt(env, PGM_OPERAND, 2);
-return -EIO;
+program_interrupt(cpu-env, PGM_OPERAND, 2);
+return;
 }
 trace_ioinst_sch_id(xsch, cssid, ssid, schid);
 sch = css_find_subch(m, cssid, ssid, schid);
@@ -66,11 +66,10 @@ int ioinst_handle_xsch(CPUS390XState *env, uint64_t reg1)
 cc = 1;
 break;
 }
-
-return cc;
+setcc(cpu, cc);
 }
 
-int ioinst_handle_csch(CPUS390XState *env, uint64_t reg1)
+void ioinst_handle_csch(S390CPU *cpu, uint64_t reg1)
 {
 int cssid, ssid, schid, m;
 SubchDev *sch;
@@ -78,8 +77,8 @@ int ioinst_handle_csch(CPUS390XState *env, uint64_t reg1)
 int cc;
 
 if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid)) {
-program_interrupt(env, PGM_OPERAND, 2);
-return -EIO;
+program_interrupt(cpu-env, PGM_OPERAND, 2);
+return;
 }
 trace_ioinst_sch_id(csch, cssid, ssid, schid);
 sch = css_find_subch(m, cssid, ssid, schid);
@@ -91,10 +90,10 @@ int ioinst_handle_csch(CPUS390XState *env, uint64_t reg1)
 } else {
 cc = 0;
 }
-return cc;
+setcc(cpu, cc);
 }
 
-int ioinst_handle_hsch(CPUS390XState *env, uint64_t reg1)
+void ioinst_handle_hsch(S390CPU *cpu, uint64_t reg1)
 {
 int cssid, ssid, schid, m;
 SubchDev *sch;
@@ -102,8 +101,8 @@ int ioinst_handle_hsch(CPUS390XState *env, uint64_t reg1)
 int cc;
 
 if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid)) {
-program_interrupt(env, PGM_OPERAND, 2);
-return -EIO;
+program_interrupt(cpu-env, PGM_OPERAND, 2);
+return;
 }
 trace_ioinst_sch_id(hsch, cssid, ssid, schid);
 sch = css_find_subch(m, cssid, ssid, schid);
@@ -124,8 +123,7 @@ int ioinst_handle_hsch(CPUS390XState *env, uint64_t reg1)
 cc = 1;
 break;
 }
-
-return cc;
+setcc(cpu, cc);
 }
 
 static int ioinst_schib_valid(SCHIB *schib)
@@ -141,7 +139,7 @@ static int ioinst_schib_valid(SCHIB *schib)
 return 1;
 }
 
-int ioinst_handle_msch(CPUS390XState *env, uint64_t reg1, uint32_t ipb)
+void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)
 {
 int cssid, ssid, schid, m;
 SubchDev *sch;
@@ -150,22 +148,21 @@ int ioinst_handle_msch(CPUS390XState *env, uint64_t reg1, 
uint32_t ipb)
 int ret = -ENODEV;
 int cc;
 hwaddr len = sizeof(*schib);
+CPUS390XState *env = cpu-env;
 
 addr = decode_basedisp_s(env, ipb);
 if (addr  3) {
 program_interrupt(env, PGM_SPECIFICATION, 2);
-return -EIO;
+return;
 }
 schib = s390_cpu_physical_memory_map(env, addr, len, 0);
 if (!schib || len != sizeof(*schib)) {
 program_interrupt(env, PGM_ADDRESSING, 2);
-cc = -EIO;
 goto out;
 }
 if (ioinst_disassemble_sch_ident(reg1, m, cssid, ssid, schid) ||
 !ioinst_schib_valid(schib)) {
 program_interrupt(env, PGM_OPERAND, 2);
-cc = -EIO;
 goto out;
 }
 trace_ioinst_sch_id(msch, cssid, ssid, schid);
@@ -187,9 +184,10 @@ int ioinst_handle_msch(CPUS390XState *env, uint64_t reg1, 
uint32_t ipb)
 cc = 1;
 break;
 }
+setcc(cpu, cc);
+
 out:
 s390_cpu_physical_memory_unmap(env, schib, len, 0);
-return cc;
 }
 
 static void copy_orb_from_guest(ORB *dest, const ORB *src)
@@ -213,7 +211,7 @@ static int ioinst_orb_valid(ORB *orb)
 return 1;
 }
 
-int ioinst_handle_ssch(CPUS390XState *env, uint64_t reg1, uint32_t ipb)
+void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)
 {
 int cssid, ssid, schid, m;
 SubchDev *sch;
@@ -222,23 +220,22 @@ int ioinst_handle_ssch(CPUS390XState *env, uint64_t reg1, 
uint32_t ipb)
 int ret = -ENODEV;
 int cc;
 hwaddr len = sizeof(*orig_orb);
+

Re: [Qemu-devel] [PATCH v3 00/29] tcg-aarch64 improvements

2013-09-03 Thread Peter Maydell
On 3 September 2013 08:37, Richard W.M. Jones rjo...@redhat.com wrote:
 Is there a way yet to compile and run a 'qemu-system-aarch64'? [on a
 regular x86-64 host]

The code for this has not yet been written :-)
The patchset I posted will build a qemu-system-aarch64 but
with no actual 64 bit CPUs (you can run all the 32 bit CPUs
if you like). It's foundational work for doing the system emulation
on and also for the linux-user 64 bit emulation which Alex is doing.

As Laurent says, don't confuse this with the tcg-aarch64 code
in tree, which is for emulating MIPS/x86/etc on aarch64 hosts.

 I tried your git branch above and Peter's v5 patch posted a while back
 (which doesn't cleanly apply)

Try the git branch I mention in the cover letter (or its followup),
which I've been rebasing. Or you could wait a day or two for v6.

thanks
-- PMM



[Qemu-devel] [PATCH v6] kvm irqfd: support direct msimessage to irq translation

2013-09-03 Thread Alexey Kardashevskiy
On PPC64 systems MSI Messages are translated to system IRQ in a PCI
host bridge. This is already supported for emulated MSI/MSIX but
not for irqfd where the current QEMU allocates IRQ numbers from
irqchip and maps MSIMessages to IRQ in the host kernel.

This adds a new direct mapping flag which tells
the kvm_irqchip_add_msi_route() function that a new VIRQ
should not be allocated, instead the value from MSIMessage::data
should be used. It is up to the platform code to make sure that
this contains a valid IRQ number as sPAPR does in spapr_pci.c.

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

---

The patch does not enable this mapping for any platform in this patch
as it is going be done for spapr only on a separate patch which is not
ready to go as it depends on the in-kernel XICS-KVM patchset which is not
in upstream yet.

---
Changes:
v6:
* simplified to a single global flag and putting an IRQ number
in MSIMessage::data

2013/08/07 v5:
* pci_bus_map_msi now has default behaviour which is to call
kvm_irqchip_add_msi_route
* kvm_irqchip_release_virq fixed not crash when there is no routes
---
 include/sysemu/kvm.h |  9 +
 kvm-all.c| 13 +
 kvm-stub.c   |  1 +
 3 files changed, 23 insertions(+)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 8e76685..0e9ef38 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -46,6 +46,7 @@ extern bool kvm_halt_in_kernel_allowed;
 extern bool kvm_irqfds_allowed;
 extern bool kvm_msi_via_irqfd_allowed;
 extern bool kvm_gsi_routing_allowed;
+extern bool kvm_gsi_direct_mapping;
 extern bool kvm_readonly_mem_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
@@ -108,6 +109,13 @@ extern bool kvm_readonly_mem_allowed;
 #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
 
 /**
+ * kvm_gsi_direct_mapping:
+ *
+ * Returns: true if GSI direct mapping is enabled.
+ */
+#define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping)
+
+/**
  * kvm_readonly_mem_enabled:
  *
  * Returns: true if KVM readonly memory is enabled (ie the kernel
@@ -123,6 +131,7 @@ extern bool kvm_readonly_mem_allowed;
 #define kvm_irqfds_enabled() (false)
 #define kvm_msi_via_irqfd_enabled() (false)
 #define kvm_gsi_routing_allowed() (false)
+#define kvm_gsi_direct_mapping() (false)
 #define kvm_readonly_mem_enabled() (false)
 #endif
 
diff --git a/kvm-all.c b/kvm-all.c
index 875e32e..17fb865 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -111,6 +111,7 @@ bool kvm_halt_in_kernel_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
+bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 
@@ -1069,6 +1070,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
 struct kvm_irq_routing_entry *e;
 int i;
 
+if (kvm_gsi_direct_mapping()) {
+return;
+}
+
 for (i = 0; i  s-irq_routes-nr; i++) {
 e = s-irq_routes-entries[i];
 if (e-gsi == virq) {
@@ -1190,6 +1195,10 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage 
msg)
 struct kvm_irq_routing_entry kroute = {};
 int virq;
 
+if (kvm_gsi_direct_mapping()) {
+return msg.data  0x;
+}
+
 if (!kvm_gsi_routing_enabled()) {
 return -ENOSYS;
 }
@@ -1216,6 +1225,10 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, 
MSIMessage msg)
 {
 struct kvm_irq_routing_entry kroute = {};
 
+if (kvm_gsi_direct_mapping()) {
+return 0;
+}
+
 if (!kvm_irqchip_in_kernel()) {
 return -ENOSYS;
 }
diff --git a/kvm-stub.c b/kvm-stub.c
index 548f471..e979f76 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -25,6 +25,7 @@ bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
+bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 
-- 
1.8.4.rc4




[Qemu-devel] [PATCH v5 1/6] block: Image file option amendment

2013-09-03 Thread Max Reitz
This patch adds the amend option to qemu-img which allows changing
image options on existing image files. It also adds the generic bdrv
implementation which is basically just a wrapper for the image format
specific function.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block.c   |  8 +
 include/block/block.h |  2 ++
 include/block/block_int.h |  3 ++
 qemu-img-cmds.hx  |  6 
 qemu-img.c| 84 +++
 qemu-img.texi |  5 +++
 6 files changed, 108 insertions(+)

diff --git a/block.c b/block.c
index a387c1a..9c40a15 100644
--- a/block.c
+++ b/block.c
@@ -4674,3 +4674,11 @@ void bdrv_add_before_write_notifier(BlockDriverState *bs,
 {
 notifier_with_return_list_add(bs-before_write_notifiers, notifier);
 }
+
+int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+{
+if (bs-drv-bdrv_amend_options == NULL) {
+return -ENOTSUP;
+}
+return bs-drv-bdrv_amend_options(bs, options);
+}
diff --git a/include/block/block.h b/include/block/block.h
index e6b391c..c284b4a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -223,6 +223,8 @@ typedef enum {
 
 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
+int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
  int sector_num);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 8012e25..3c93766 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -205,6 +205,9 @@ struct BlockDriver {
 int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
 BdrvCheckMode fix);
 
+int (*bdrv_amend_options)(BlockDriverState *bs,
+QEMUOptionParameter *options);
+
 void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
 
 /* TODO Better pass a option string/QDict/QemuOpts to add any rule? */
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 4ca7e95..5a066b5 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -61,5 +61,11 @@ DEF(resize, img_resize,
 resize [-q] filename [+ | -]size)
 STEXI
 @item resize [-q] @var{filename} [+ | -]@var{size}
+ETEXI
+
+DEF(amend, img_amend,
+amend [-q] [-f fmt] -o options filename)
+STEXI
+@item amend [-q] [-f @var{fmt}] -o @var{options} @var{filename}
 @end table
 ETEXI
diff --git a/qemu-img.c b/qemu-img.c
index b9a848d..7a8f064 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2308,6 +2308,90 @@ out:
 return 0;
 }
 
+static int img_amend(int argc, char **argv)
+{
+int c, ret = 0;
+char *options = NULL;
+QEMUOptionParameter *create_options = NULL, *options_param = NULL;
+const char *fmt = NULL, *filename;
+bool quiet = false;
+BlockDriverState *bs = NULL;
+
+for (;;) {
+c = getopt(argc, argv, hqf:o:);
+if (c == -1) {
+break;
+}
+
+switch (c) {
+case 'h':
+case '?':
+help();
+break;
+case 'o':
+options = optarg;
+break;
+case 'f':
+fmt = optarg;
+break;
+case 'q':
+quiet = true;
+break;
+}
+}
+
+if (optind != argc - 1) {
+help();
+}
+
+if (!options) {
+help();
+}
+
+filename = argv[argc - 1];
+
+bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
+if (!bs) {
+error_report(Could not open image '%s', filename);
+ret = -1;
+goto out;
+}
+
+fmt = bs-drv-format_name;
+
+if (is_help_option(options)) {
+ret = print_block_option_help(filename, fmt);
+goto out;
+}
+
+create_options = append_option_parameters(create_options,
+bs-drv-create_options);
+options_param = parse_option_parameters(options, create_options,
+options_param);
+if (options_param == NULL) {
+error_report(Invalid options for file format '%s', fmt);
+ret = -1;
+goto out;
+}
+
+ret = bdrv_amend_options(bs, options_param);
+if (ret  0) {
+error_report(Error while amending options: %s, strerror(-ret));
+goto out;
+}
+
+out:
+if (bs) {
+bdrv_delete(bs);
+}
+free_option_parameters(create_options);
+free_option_parameters(options_param);
+if (ret) {
+return 1;
+}
+return 0;
+}
+
 static const img_cmd_t img_cmds[] = {
 #define DEF(option, callback, arg_string)\
 { option, callback },
diff --git a/qemu-img.texi b/qemu-img.texi
index 69f1bda..8697f23 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -282,6 +282,11 @@ sizes accordingly.  Failure to do so will result in data 
loss!
 After using this command to grow a 

[Qemu-devel] [PATCH v5 0/6] block/qcow2: Image file option amendment

2013-09-03 Thread Max Reitz

This series adds support to qemu-img, block and qcow2 for amending image
options on existing image files.

Depends on:
 - option: Add assigned flag to QEMUOptionParameter
 - qcow2-refcount: Snapshot update for zero clusters (series, v3)
 - Add metadata overlap checks (series, v5)

v5:
 - added a new function for emptying a cache (patch 2)
 - fixed rounding for the bitmap size in qcow2_expand_zero_clusters
 - now empties the cache in qcow2_expand_zero_clusters instead of simply
   flushing it
 - factored out assignment check in qcow2_amend_options
 - fixed resizing by moving it to the end of qcow2_amend_options
 - fixed expected test result for resizing in addition to a version
   upgrade

v4:
 - rebased on the metadata overlap check series (and fit to it)
 - split patch 2 into three distinct patches (2, 3 and 4)
 - extended test for zero expansion on backed and inactive backed clusters
   (and fixed according to the metadata overlap check series (i.e.,
   adjusted header length))
 - fixed zero expansion with shared L2 tables

v3:
 - deallocate non-preallocated zero clusters on non-backed images instead
   of zero expanding them
 - qcow2 version downgrade: error out on refcount_order != 4
 - implemented Eric's comments regarding the qemu-img amend and img_amend
   itself

v2:
 - Generally implemented Kevin's comments, especially:
   - Zero cluster expansion for inactive L2 tables
   - Correct handling of preallocated zero clusters
   - More test cases

Max Reitz (6):
  block: Image file option amendment
  qcow2-cache: Empty cache
  qcow2-cluster: Expand zero clusters
  qcow2: Save refcount order in BDRVQcowState
  qcow2: Implement bdrv_amend_options
  qemu-iotest: qcow2 image option amendment

 block.c|   8 ++
 block/qcow2-cache.c|  18 +++
 block/qcow2-cluster.c  | 233 ++
 block/qcow2-refcount.c |  29 ++--
 block/qcow2.c  | 197 -
 block/qcow2.h  |   8 ++
 include/block/block.h  |   2 +
 include/block/block_int.h  |   3 +
 qemu-img-cmds.hx   |   6 +
 qemu-img.c |  84 +++
 qemu-img.texi  |   5 +
 tests/qemu-iotests/061 | 178 +++
 tests/qemu-iotests/061.out | 349 +
 tests/qemu-iotests/group   |   1 +
 14 files changed, 1106 insertions(+), 15 deletions(-)
 create mode 100755 tests/qemu-iotests/061
 create mode 100644 tests/qemu-iotests/061.out

-- 
1.8.3.1




[Qemu-devel] [PATCH v5 6/6] qemu-iotest: qcow2 image option amendment

2013-09-03 Thread Max Reitz
Add tests for qemu-img amend on qcow2 image files.

Signed-off-by: Max Reitz mre...@redhat.com
---
 tests/qemu-iotests/061 | 178 +++
 tests/qemu-iotests/061.out | 349 +
 tests/qemu-iotests/group   |   1 +
 3 files changed, 528 insertions(+)
 create mode 100755 tests/qemu-iotests/061
 create mode 100644 tests/qemu-iotests/061.out

diff --git a/tests/qemu-iotests/061 b/tests/qemu-iotests/061
new file mode 100755
index 000..86404e6
--- /dev/null
+++ b/tests/qemu-iotests/061
@@ -0,0 +1,178 @@
+#!/bin/bash
+#
+# Test case for image option amendment in qcow2.
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+# creator
+owner=mre...@redhat.com
+
+seq=`basename $0`
+echo QA output created by $seq
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+
+_cleanup()
+{
+   _cleanup_test_img
+}
+trap _cleanup; exit \$status 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# This tests qocw2-specific low-level functionality
+_supported_fmt qcow2
+_supported_proto generic
+_supported_os Linux
+
+echo
+echo === Testing version downgrade with zero expansion ===
+echo
+IMGOPTS=compat=1.1,lazy_refcounts=on _make_test_img 64M
+$QEMU_IO -c write -z 0 128k $TEST_IMG | _filter_qemu_io
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o compat=0.10 $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IO -c read -P 0 0 128k $TEST_IMG | _filter_qemu_io
+_check_test_img
+
+echo
+echo === Testing dirty version downgrade ===
+echo
+IMGOPTS=compat=1.1,lazy_refcounts=on _make_test_img 64M
+$QEMU_IO -c write -P 0x2a 0 128k -c flush -c abort $TEST_IMG | 
_filter_qemu_io
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o compat=0.10 $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IO -c read -P 0x2a 0 128k $TEST_IMG | _filter_qemu_io
+_check_test_img
+
+echo
+echo === Testing version downgrade with unknown compat/autoclear flags ===
+echo
+IMGOPTS=compat=1.1 _make_test_img 64M
+./qcow2.py $TEST_IMG set-feature-bit compatible 42
+./qcow2.py $TEST_IMG set-feature-bit autoclear 42
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o compat=0.10 $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+_check_test_img
+
+echo
+echo === Testing version upgrade and resize ===
+echo
+IMGOPTS=compat=0.10 _make_test_img 64M
+$QEMU_IO -c write -P 0x2a 42M 64k $TEST_IMG | _filter_qemu_io
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o compat=1.1,lazy_refcounts=on,size=128M $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IO -c read -P 0x2a 42M 64k $TEST_IMG | _filter_qemu_io
+_check_test_img
+
+echo
+echo === Testing dirty lazy_refcounts=off ===
+echo
+IMGOPTS=compat=1.1,lazy_refcounts=on _make_test_img 64M
+$QEMU_IO -c write -P 0x2a 0 128k -c flush -c abort $TEST_IMG | 
_filter_qemu_io
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IMG amend -o lazy_refcounts=off $TEST_IMG
+./qcow2.py $TEST_IMG dump-header
+$QEMU_IO -c read -P 0x2a 0 128k $TEST_IMG | _filter_qemu_io
+_check_test_img
+
+echo
+echo === Testing backing file ===
+echo
+IMGOPTS=compat=1.1 _make_test_img 64M
+IMGOPTS=compat=1.1 TEST_IMG=$TEST_IMG.base _make_test_img 64M
+$QEMU_IO -c write -P 0x2a 0 128k $TEST_IMG.base | _filter_qemu_io
+$QEMU_IO -c read -P 0 0 128k $TEST_IMG | _filter_qemu_io
+$QEMU_IMG amend -o backing_file=$TEST_IMG.base,backing_fmt=qcow2 $TEST_IMG
+$QEMU_IO -c read -P 0x2a 0 128k $TEST_IMG | _filter_qemu_io
+_check_test_img
+
+echo
+echo === Testing invalid configurations ===
+echo
+IMGOPTS=compat=0.10 _make_test_img 64M
+$QEMU_IMG amend -o lazy_refcounts=on $TEST_IMG
+$QEMU_IMG amend -o compat=1.1 $TEST_IMG # actually valid
+$QEMU_IMG amend -o compat=0.10,lazy_refcounts=on $TEST_IMG
+$QEMU_IMG amend -o compat=0.42 $TEST_IMG
+$QEMU_IMG amend -o foo=bar $TEST_IMG
+$QEMU_IMG amend -o cluster_size=1k $TEST_IMG
+$QEMU_IMG amend -o encryption=on $TEST_IMG
+$QEMU_IMG amend -o preallocation=on $TEST_IMG
+
+echo
+echo === Testing correct handling of unset value ===
+echo
+IMGOPTS=compat=1.1,cluster_size=1k _make_test_img 64M
+echo Should work:
+$QEMU_IMG amend -o lazy_refcounts=on $TEST_IMG
+echo Should not work: # Just to know which of these tests actually fails
+$QEMU_IMG amend -o cluster_size=64k $TEST_IMG
+
+echo
+echo === Testing zero expansion on inactive clusters ===
+echo
+IMGOPTS=compat=1.1 

[Qemu-devel] [PATCH v5 4/6] qcow2: Save refcount order in BDRVQcowState

2013-09-03 Thread Max Reitz
Save the image refcount order in BDRVQcowState. This will be relevant
for future code supporting different refcount orders than four and also
for code that needs to verify a certain refcount order for an opened
image.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2.c | 3 ++-
 block/qcow2.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index aeb2ebb..28b104e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -455,6 +455,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, 
int flags)
 ret = -ENOTSUP;
 goto fail;
 }
+s-refcount_order = header.refcount_order;
 
 if (header.cluster_bits  MIN_CLUSTER_BITS ||
 header.cluster_bits  MAX_CLUSTER_BITS) {
@@ -1133,7 +1134,7 @@ int qcow2_update_header(BlockDriverState *bs)
 .incompatible_features  = cpu_to_be64(s-incompatible_features),
 .compatible_features= cpu_to_be64(s-compatible_features),
 .autoclear_features = cpu_to_be64(s-autoclear_features),
-.refcount_order = cpu_to_be32(3 + REFCOUNT_SHIFT),
+.refcount_order = cpu_to_be32(s-refcount_order),
 .header_length  = cpu_to_be32(header_length),
 };
 
diff --git a/block/qcow2.h b/block/qcow2.h
index bb25213..1e28fc1 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -199,6 +199,7 @@ typedef struct BDRVQcowState {
 int flags;
 int qcow_version;
 bool use_lazy_refcounts;
+int refcount_order;
 
 bool discard_passthrough[QCOW2_DISCARD_MAX];
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 5/6] qcow2: Implement bdrv_amend_options

2013-09-03 Thread Max Reitz
Implement bdrv_amend_options for compat, size, backing_file, backing_fmt
and lazy_refcounts.

Downgrading images from compat=1.1 to compat=0.10 is achieved through
handling all incompatible flags accordingly, clearing all compatible and
autoclear flags and expanding all zero clusters.

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

diff --git a/block/qcow2.c b/block/qcow2.c
index 28b104e..d29547b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1813,6 +1813,199 @@ static int qcow2_load_vmstate(BlockDriverState *bs, 
uint8_t *buf,
 return ret;
 }
 
+/*
+ * Downgrades an image's version. To achieve this, any incompatible features
+ * have to be removed.
+ */
+static int qcow2_downgrade(BlockDriverState *bs, int target_version)
+{
+BDRVQcowState *s = bs-opaque;
+int current_version = s-qcow_version;
+int ret;
+
+if (target_version == current_version) {
+return 0;
+} else if (target_version  current_version) {
+return -EINVAL;
+} else if (target_version != 2) {
+return -EINVAL;
+}
+
+if (s-refcount_order != 4) {
+/* we would have to convert the image to a refcount_order == 4 image
+ * here; however, since qemu (at the time of writing this) does not
+ * support anything different than 4 anyway, there is no point in doing
+ * so right now; however, we should error out (if qemu supports this in
+ * the future and this code has not been adapted) */
+error_report(qcow2_downgrade: Image refcount orders other than 4 are
+ currently not supported.);
+return -ENOTSUP;
+}
+
+/* clear incompatible features */
+if (s-incompatible_features  QCOW2_INCOMPAT_DIRTY) {
+ret = qcow2_mark_clean(bs);
+if (ret  0) {
+return ret;
+}
+}
+
+/* with QCOW2_INCOMPAT_CORRUPT, it is pretty much impossible to get here in
+ * the first place; if that happens nonetheless, returning -ENOTSUP is the
+ * best thing to do anyway */
+
+if (s-incompatible_features) {
+return -ENOTSUP;
+}
+
+/* since we can ignore compatible features, we can set them to 0 as well */
+s-compatible_features = 0;
+/* if lazy refcounts have been used, they have already been fixed through
+ * clearing the dirty flag */
+
+/* clearing autoclear features is trivial */
+s-autoclear_features = 0;
+
+ret = qcow2_expand_zero_clusters(bs);
+if (ret  0) {
+return ret;
+}
+
+s-qcow_version = target_version;
+ret = qcow2_update_header(bs);
+if (ret  0) {
+s-qcow_version = current_version;
+return ret;
+}
+return 0;
+}
+
+static int qcow2_amend_options(BlockDriverState *bs,
+   QEMUOptionParameter *options)
+{
+BDRVQcowState *s = bs-opaque;
+int old_version = s-qcow_version, new_version = old_version;
+uint64_t new_size = 0;
+const char *backing_file = NULL, *backing_format = NULL;
+bool lazy_refcounts = s-use_lazy_refcounts;
+int ret;
+int i;
+
+for (i = 0; options[i].name; i++)
+{
+if (!options[i].assigned) {
+/* only change explicitly defined options */
+continue;
+}
+
+if (!strcmp(options[i].name, compat)) {
+if (!options[i].value.s) {
+/* preserve default */
+} else if (!strcmp(options[i].value.s, 0.10)) {
+new_version = 2;
+} else if (!strcmp(options[i].value.s, 1.1)) {
+new_version = 3;
+} else {
+fprintf(stderr, Unknown compatibility level %s.\n,
+options[i].value.s);
+return -EINVAL;
+}
+} else if (!strcmp(options[i].name, preallocation)) {
+fprintf(stderr, Cannot change preallocation mode.\n);
+return -ENOTSUP;
+} else if (!strcmp(options[i].name, size)) {
+new_size = options[i].value.n;
+} else if (!strcmp(options[i].name, backing_file)) {
+backing_file = options[i].value.s;
+} else if (!strcmp(options[i].name, backing_fmt)) {
+backing_format = options[i].value.s;
+} else if (!strcmp(options[i].name, encryption)) {
+if ((options[i].value.n != !!s-crypt_method)) {
+fprintf(stderr, Changing the encryption flag is not 
+supported.\n);
+return -ENOTSUP;
+}
+} else if (!strcmp(options[i].name, cluster_size)) {
+if (options[i].value.n != s-cluster_size) {
+fprintf(stderr, Changing the cluster size is not 
+supported.\n);
+return -ENOTSUP;
+}
+} else if (!strcmp(options[i].name, lazy_refcounts)) {
+lazy_refcounts = 

[Qemu-devel] [PATCH v5 2/6] qcow2-cache: Empty cache

2013-09-03 Thread Max Reitz
Add a function for emptying a cache, i.e., flushing it and marking all
elements invalid.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2-cache.c | 18 ++
 block/qcow2.h   |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 7bcae09..40a5a3f 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -202,6 +202,24 @@ void qcow2_cache_depends_on_flush(Qcow2Cache *c)
 c-depends_on_flush = true;
 }
 
+int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c)
+{
+int ret, i;
+
+ret = qcow2_cache_flush(bs, c);
+if (ret  0) {
+return ret;
+}
+
+for (i = 0; i  c-size; i++) {
+assert(c-entries[i].ref == 0);
+c-entries[i].offset = 0;
+c-entries[i].cache_hits = 0;
+}
+
+return 0;
+}
+
 static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c)
 {
 int i;
diff --git a/block/qcow2.h b/block/qcow2.h
index 10b7bf4..3db0877 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -473,6 +473,8 @@ int qcow2_cache_set_dependency(BlockDriverState *bs, 
Qcow2Cache *c,
 Qcow2Cache *dependency);
 void qcow2_cache_depends_on_flush(Qcow2Cache *c);
 
+int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
+
 int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
 void **table);
 int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 3/6] qcow2-cluster: Expand zero clusters

2013-09-03 Thread Max Reitz
Add functionality for expanding zero clusters. This is necessary for
downgrading the image version to one without zero cluster support.

For non-backed images, this function may also just discard zero clusters
instead of truly expanding them.

Signed-off-by: Max Reitz mre...@redhat.com
---
 block/qcow2-cluster.c  | 233 +
 block/qcow2-refcount.c |  29 +++---
 block/qcow2.h  |   5 ++
 3 files changed, 253 insertions(+), 14 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 2d5aa92..cc16312 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1497,3 +1497,236 @@ fail:
 
 return ret;
 }
+
+/*
+ * Expands all zero clusters in a specific L1 table (or deallocates them, for
+ * non-backed non-pre-allocated zero clusters).
+ *
+ * expanded_clusters is a bitmap where every bit corresponds to one cluster in
+ * the image file; a bit gets set if the corresponding cluster has been used 
for
+ * zero expansion (i.e., has been filled with zeroes and is referenced from an
+ * L2 table). nb_clusters contains the total cluster count of the image file,
+ * i.e., the number of bits in expanded_clusters.
+ */
+static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
+  int l1_size, uint8_t *expanded_clusters,
+  uint64_t nb_clusters)
+{
+BDRVQcowState *s = bs-opaque;
+bool is_active_l1 = (l1_table == s-l1_table);
+uint64_t *l2_table = NULL;
+int ret;
+int i, j;
+
+if (!is_active_l1) {
+/* inactive L2 tables require a buffer to be stored in when loading
+ * them from disk */
+l2_table = qemu_blockalign(bs, s-cluster_size);
+}
+
+for (i = 0; i  l1_size; i++) {
+uint64_t l2_offset = l1_table[i]  L1E_OFFSET_MASK;
+bool l2_dirty = false;
+
+if (!l2_offset) {
+/* unallocated */
+continue;
+}
+
+if (is_active_l1) {
+/* get active L2 tables from cache */
+ret = qcow2_cache_get(bs, s-l2_table_cache, l2_offset,
+(void **)l2_table);
+} else {
+/* load inactive L2 tables from disk */
+ret = bdrv_read(bs-file, l2_offset / BDRV_SECTOR_SIZE,
+(void *)l2_table, s-cluster_sectors);
+}
+if (ret  0) {
+goto fail;
+}
+
+for (j = 0; j  s-l2_size; j++) {
+uint64_t l2_entry = be64_to_cpu(l2_table[j]);
+int64_t offset = l2_entry  L2E_OFFSET_MASK, cluster_index;
+int cluster_type = qcow2_get_cluster_type(l2_entry);
+
+if (cluster_type == QCOW2_CLUSTER_NORMAL) {
+cluster_index = offset  s-cluster_bits;
+assert((cluster_index = 0)  (cluster_index  nb_clusters));
+if (expanded_clusters[cluster_index / 8] 
+(1  (cluster_index % 8))) {
+/* Probably a shared L2 table; this cluster was a zero
+ * cluster which has been expanded, its refcount
+ * therefore most likely requires an update. */
+ret = qcow2_update_cluster_refcount(bs, cluster_index, 1,
+QCOW2_DISCARD_NEVER);
+if (ret  0) {
+goto fail;
+}
+/* Since we just increased the refcount, the COPIED flag 
may
+ * no longer be set. */
+l2_table[j] = cpu_to_be64(l2_entry  ~QCOW_OFLAG_COPIED);
+l2_dirty = true;
+}
+continue;
+}
+else if (qcow2_get_cluster_type(l2_entry) != QCOW2_CLUSTER_ZERO) {
+continue;
+}
+
+if (!offset) {
+/* not preallocated */
+if (!bs-backing_hd) {
+/* not backed; therefore we can simply deallocate the
+ * cluster */
+l2_table[j] = 0;
+l2_dirty = true;
+continue;
+}
+
+offset = qcow2_alloc_clusters(bs, s-cluster_size);
+if (offset  0) {
+ret = offset;
+goto fail;
+}
+}
+
+ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
+offset, s-cluster_size);
+if (ret  0) {
+qcow2_free_clusters(bs, offset, s-cluster_size,
+QCOW2_DISCARD_ALWAYS);
+goto fail;
+}
+
+ret = bdrv_write_zeroes(bs-file, offset / BDRV_SECTOR_SIZE,
+s-cluster_sectors);
+if (ret  0) {
+qcow2_free_clusters(bs, offset, 

Re: [Qemu-devel] [PATCH v6] kvm irqfd: support direct msimessage to irq translation

2013-09-03 Thread Michael S. Tsirkin
On Tue, Sep 03, 2013 at 06:08:25PM +1000, Alexey Kardashevskiy wrote:
 On PPC64 systems MSI Messages are translated to system IRQ in a PCI
 host bridge. This is already supported for emulated MSI/MSIX but
 not for irqfd where the current QEMU allocates IRQ numbers from
 irqchip and maps MSIMessages to IRQ in the host kernel.
 
 This adds a new direct mapping flag which tells
 the kvm_irqchip_add_msi_route() function that a new VIRQ
 should not be allocated, instead the value from MSIMessage::data
 should be used. It is up to the platform code to make sure that
 this contains a valid IRQ number as sPAPR does in spapr_pci.c.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

Fine with me

Acked-by: Michael S. Tsirkin m...@redhat.com

 ---
 
 The patch does not enable this mapping for any platform in this patch
 as it is going be done for spapr only on a separate patch which is not
 ready to go as it depends on the in-kernel XICS-KVM patchset which is not
 in upstream yet.
 
 ---
 Changes:
 v6:
 * simplified to a single global flag and putting an IRQ number
 in MSIMessage::data
 
 2013/08/07 v5:
 * pci_bus_map_msi now has default behaviour which is to call
 kvm_irqchip_add_msi_route
 * kvm_irqchip_release_virq fixed not crash when there is no routes
 ---
  include/sysemu/kvm.h |  9 +
  kvm-all.c| 13 +
  kvm-stub.c   |  1 +
  3 files changed, 23 insertions(+)
 
 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index 8e76685..0e9ef38 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -46,6 +46,7 @@ extern bool kvm_halt_in_kernel_allowed;
  extern bool kvm_irqfds_allowed;
  extern bool kvm_msi_via_irqfd_allowed;
  extern bool kvm_gsi_routing_allowed;
 +extern bool kvm_gsi_direct_mapping;
  extern bool kvm_readonly_mem_allowed;
  
  #if defined CONFIG_KVM || !defined NEED_CPU_H
 @@ -108,6 +109,13 @@ extern bool kvm_readonly_mem_allowed;
  #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
  
  /**
 + * kvm_gsi_direct_mapping:
 + *
 + * Returns: true if GSI direct mapping is enabled.
 + */
 +#define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping)
 +
 +/**
   * kvm_readonly_mem_enabled:
   *
   * Returns: true if KVM readonly memory is enabled (ie the kernel
 @@ -123,6 +131,7 @@ extern bool kvm_readonly_mem_allowed;
  #define kvm_irqfds_enabled() (false)
  #define kvm_msi_via_irqfd_enabled() (false)
  #define kvm_gsi_routing_allowed() (false)
 +#define kvm_gsi_direct_mapping() (false)
  #define kvm_readonly_mem_enabled() (false)
  #endif
  
 diff --git a/kvm-all.c b/kvm-all.c
 index 875e32e..17fb865 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -111,6 +111,7 @@ bool kvm_halt_in_kernel_allowed;
  bool kvm_irqfds_allowed;
  bool kvm_msi_via_irqfd_allowed;
  bool kvm_gsi_routing_allowed;
 +bool kvm_gsi_direct_mapping;
  bool kvm_allowed;
  bool kvm_readonly_mem_allowed;
  
 @@ -1069,6 +1070,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
  struct kvm_irq_routing_entry *e;
  int i;
  
 +if (kvm_gsi_direct_mapping()) {
 +return;
 +}
 +
  for (i = 0; i  s-irq_routes-nr; i++) {
  e = s-irq_routes-entries[i];
  if (e-gsi == virq) {
 @@ -1190,6 +1195,10 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage 
 msg)
  struct kvm_irq_routing_entry kroute = {};
  int virq;
  
 +if (kvm_gsi_direct_mapping()) {
 +return msg.data  0x;
 +}
 +
  if (!kvm_gsi_routing_enabled()) {
  return -ENOSYS;
  }
 @@ -1216,6 +1225,10 @@ int kvm_irqchip_update_msi_route(KVMState *s, int 
 virq, MSIMessage msg)
  {
  struct kvm_irq_routing_entry kroute = {};
  
 +if (kvm_gsi_direct_mapping()) {
 +return 0;
 +}
 +
  if (!kvm_irqchip_in_kernel()) {
  return -ENOSYS;
  }
 diff --git a/kvm-stub.c b/kvm-stub.c
 index 548f471..e979f76 100644
 --- a/kvm-stub.c
 +++ b/kvm-stub.c
 @@ -25,6 +25,7 @@ bool kvm_async_interrupts_allowed;
  bool kvm_irqfds_allowed;
  bool kvm_msi_via_irqfd_allowed;
  bool kvm_gsi_routing_allowed;
 +bool kvm_gsi_direct_mapping;
  bool kvm_allowed;
  bool kvm_readonly_mem_allowed;
  
 -- 
 1.8.4.rc4



Re: [Qemu-devel] [PATCH v4 5/5] qemu-iotest: qcow2 image option amendment

2013-09-03 Thread Kevin Wolf
Am 02.09.2013 um 12:04 hat Max Reitz geschrieben:
 Add tests for qemu-img amend on qcow2 image files.
 
 Signed-off-by: Max Reitz mre...@redhat.com
 ---
  tests/qemu-iotests/061 | 178 +++
  tests/qemu-iotests/061.out | 349 
 +
  tests/qemu-iotests/group   |   1 +
  3 files changed, 528 insertions(+)
  create mode 100755 tests/qemu-iotests/061
  create mode 100644 tests/qemu-iotests/061.out

It might be worth adding test cases for...

* Leaving an encrypted image encrypted, implicitly or explicitly
* Zero cluster expansion with an (active/inactive) L2 table with
  refcount  1
* State after a failed amend operation (or do we even promise anything?
  I guess if you pass multiple options, some may be applied and some not)

What's there looks good (except for the one bug I mentioned)

Kevin



[Qemu-devel] [PATCH] linux-headers: update to 3.11

2013-09-03 Thread Alexey Kardashevskiy
Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
---

I need this update as VFIO on PPC64/pseries got in upstream kernel
and this is required by VFIO-SPAPR bits in QEMU. Others may find this
update useful too :)

---
 linux-headers/asm-arm64/kvm.h   | 168 
 linux-headers/asm-arm64/kvm_para.h  |   1 +
 linux-headers/asm-mips/kvm.h|  81 +
 linux-headers/linux/kvm.h   |   3 +
 linux-headers/linux/vfio.h  |  42 -
 linux-headers/linux/virtio_config.h |   3 +
 6 files changed, 254 insertions(+), 44 deletions(-)
 create mode 100644 linux-headers/asm-arm64/kvm.h
 create mode 100644 linux-headers/asm-arm64/kvm_para.h

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

Re: [Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable

2013-09-03 Thread Paolo Bonzini
Il 03/09/2013 09:26, mreza...@redhat.com ha scritto:
 From: Miroslav Rezanina mreza...@redhat.com
 
 Use usb_legacy_register handling to create bt-dongle device. This allows
 to disable usb-bt-dongle device using CONFIG_BLUETOOTH option.
 
 Signed-off-by: Miroslav Rezanina mreza...@redhat.com
 ---

Looks good to me, just one small improvement I can suggest:

  static int bt_hci_parse(const char *str)
  {
  struct HCIInfo *hci;
 @@ -1526,8 +1457,10 @@ static void configure_msg(QemuOpts *opts)
  
  static int usb_device_add(const char *devname)
  {
 -const char *p;
  USBDevice *dev = NULL;
 +#ifndef CONFIG_LINUX
 +const char *p;
 +#endif
  
  if (!usb_enabled(false)) {
  return -1;
 @@ -1545,13 +1478,7 @@ static int usb_device_add(const char *devname)
  dev = usb_host_device_open(usb_bus_find(-1), p);
  } else
  #endif
 -if (!strcmp(devname, bt) || strstart(devname, bt:, p)) {
 -dev = usb_bt_init(usb_bus_find(-1),
 -  devname[2] ? hci_init(p)
 - : bt_new_hci(qemu_find_bt_vlan(0)));
 -} else {
  return -1;

You can remove this return too.

Paolo

 -}
  if (!dev)
  return -1;
  
 




Re: [Qemu-devel] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread Andreas Färber
Am 03.09.2013 09:22, schrieb Paolo Bonzini:
 Il 03/09/2013 09:05, liguang ha scritto:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  cputlb.c |   15 ---
  1 files changed, 0 insertions(+), 15 deletions(-)

 diff --git a/cputlb.c b/cputlb.c
 index 977c0ca..08e50e0 100644
 --- a/cputlb.c
 +++ b/cputlb.c
 @@ -169,21 +169,6 @@ static inline ram_addr_t 
 qemu_ram_addr_from_host_nofail(void *ptr)
  return ram_addr;
  }
  
 -static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
 -{
 -ram_addr_t ram_addr;
 -void *p;
 -
 -if (tlb_is_dirty_ram(tlb_entry)) {
 -p = (void *)(uintptr_t)((tlb_entry-addr_write  TARGET_PAGE_MASK)
 -+ tlb_entry-addend);
 -ram_addr = qemu_ram_addr_from_host_nofail(p);
 -if (!cpu_physical_memory_is_dirty(ram_addr)) {
 -tlb_entry-addr_write |= TLB_NOTDIRTY;
 -}
 -}
 -}
 -
  void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length)
  {
  CPUState *cpu;

 
 Reviewed-by: Paolo Bonzini pbonz...@redhat.com
 
 and CCing qemu-trivial.

Negative, please keep qemu-trivial out of this. My qom-cpu pull was
already blocked by the s390 and ppc pulls, so let's not add yet another
potentially interfering one to the mix.

IF rth agrees as TCG maintainer that this is not needed in any of his
upcoming refactorings then I'll queue it on qom-cpu. My upcoming
qom-cpu-13 series touches upon pretty much every core CPU file
perceivable, including this cputlb.c.

I also don't understand why qemu-trivial is suddenly picking up Stefan's
arm translation patch, it used to be for unmaintained areas only. But
arm is not my problem.

Thanks,
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] exec: avoid tcg_commit when kvm_enabled

2013-09-03 Thread Andreas Färber
Am 03.09.2013 08:59, schrieb liguang:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  exec.c |4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
 
 diff --git a/exec.c b/exec.c
 index 3ca9381..4509daa 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -1824,7 +1824,9 @@ static void memory_map_init(void)
  address_space_init(address_space_io, system_io, I/O);
  
  memory_listener_register(core_memory_listener, address_space_memory);
 -memory_listener_register(tcg_memory_listener, address_space_memory);
 +if (!kvm_enabled()) {

if (tcg_enabled())? I'm guessing Xen and QTest don't need it either?

Andreas

 +memory_listener_register(tcg_memory_listener, 
 address_space_memory);
 +}
  }
  
  MemoryRegion *get_system_memory(void)

-- 
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 v5 0/6] block/qcow2: Image file option amendment

2013-09-03 Thread Kevin Wolf
Am 03.09.2013 um 10:09 hat Max Reitz geschrieben:
 
 This series adds support to qemu-img, block and qcow2 for amending image
 options on existing image files.
 
 Depends on:
  - option: Add assigned flag to QEMUOptionParameter
  - qcow2-refcount: Snapshot update for zero clusters (series, v3)
  - Add metadata overlap checks (series, v5)
 
 v5:
  - added a new function for emptying a cache (patch 2)
  - fixed rounding for the bitmap size in qcow2_expand_zero_clusters
  - now empties the cache in qcow2_expand_zero_clusters instead of simply
flushing it
  - factored out assignment check in qcow2_amend_options
  - fixed resizing by moving it to the end of qcow2_amend_options
  - fixed expected test result for resizing in addition to a version
upgrade

There's still room for improvements on top, in particular the additional
test cases I suggested in the v4 thread and the real qcow2_truncate()
fix that is just worked around here by moving its call (it needs to
update bs-total_sectors), but this looks good enough to be merged now.

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



Re: [Qemu-devel] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread Paolo Bonzini
Il 03/09/2013 10:35, Andreas Färber ha scritto:
 Am 03.09.2013 09:22, schrieb Paolo Bonzini:
 Il 03/09/2013 09:05, liguang ha scritto:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  cputlb.c |   15 ---
  1 files changed, 0 insertions(+), 15 deletions(-)

 diff --git a/cputlb.c b/cputlb.c
 index 977c0ca..08e50e0 100644
 --- a/cputlb.c
 +++ b/cputlb.c
 @@ -169,21 +169,6 @@ static inline ram_addr_t 
 qemu_ram_addr_from_host_nofail(void *ptr)
  return ram_addr;
  }
  
 -static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
 -{
 -ram_addr_t ram_addr;
 -void *p;
 -
 -if (tlb_is_dirty_ram(tlb_entry)) {
 -p = (void *)(uintptr_t)((tlb_entry-addr_write  TARGET_PAGE_MASK)
 -+ tlb_entry-addend);
 -ram_addr = qemu_ram_addr_from_host_nofail(p);
 -if (!cpu_physical_memory_is_dirty(ram_addr)) {
 -tlb_entry-addr_write |= TLB_NOTDIRTY;
 -}
 -}
 -}
 -
  void cpu_tlb_reset_dirty_all(ram_addr_t start1, ram_addr_t length)
  {
  CPUState *cpu;


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

 and CCing qemu-trivial.
 
 Negative, please keep qemu-trivial out of this. My qom-cpu pull was
 already blocked by the s390 and ppc pulls, so let's not add yet another
 potentially interfering one to the mix.
 
 IF rth agrees as TCG maintainer that this is not needed in any of his
 upcoming refactorings then I'll queue it on qom-cpu. My upcoming
 qom-cpu-13 series touches upon pretty much every core CPU file
 perceivable, including this cputlb.c.

Sure.

 I also don't understand why qemu-trivial is suddenly picking up Stefan's
 arm translation patch, it used to be for unmaintained areas only. But
 arm is not my problem.

That patch is also not trivial, too.

Paolo




Re: [Qemu-devel] [RFC PATCH] spapr: support time base offset migration

2013-09-03 Thread Andreas Färber
Am 03.09.2013 09:31, schrieb Alexey Kardashevskiy:
 This allows guests to have a different timebase origin from the host.
 
 This is needed for migration, where a guest can migrate from one host
 to another and the two hosts might have a different timebase origin.
 However, the timebase seen by the guest must not go backwards, and
 should go forwards only by a small amount corresponding to the time
 taken for the migration.
 
 This is only supported for recent POWER hardware which has the TBU40
 (timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
 970.
 
 This adds kvm_access_one_reg() to access a special register which is not
 in env-spr.
 
 The feature must be present in the host kernel.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
 
 This is an RFC but not a final patch. Can break something but I just do not 
 see what.
 
 ---
  hw/ppc/ppc.c | 49 +
  include/hw/ppc/ppc.h |  4 
  target-ppc/kvm.c | 23 +++
  target-ppc/machine.c | 44 
  trace-events |  3 +++
  5 files changed, 123 insertions(+)
 
 diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
 index 1e3cab3..7d08c9a 100644
 --- a/hw/ppc/ppc.c
 +++ b/hw/ppc/ppc.c
 @@ -31,6 +31,7 @@
  #include hw/loader.h
  #include sysemu/kvm.h
  #include kvm_ppc.h
 +#include trace.h
  
  //#define PPC_DEBUG_IRQ
  #define PPC_DEBUG_TB
 @@ -796,6 +797,54 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t 
 freq)
  cpu_ppc_store_purr(cpu, 0xULL);
  }
  
 +/*
 + * Calculate timebase on the destination side of migration
 + *
 + * We calculate new timebase offset as shown below:
 + * 1) Gtb2 = Gtb1 + max(tod2 - tod1, 0)
 + *Gtb2 = tb2 + off2
 + *Gtb1 = tb1 + off1
 + * 2) tb2 + off2 = tb1 + off1 + max(tod2 - tod1, 0)
 + * 3) off2 = tb1 - tb2 + off1 + max(tod2 - tod1, 0)
 + *
 + * where:
 + * Gtb2 - destination guest timebase
 + * tb2 - destination host timebase
 + * off2 - destination timebase offset
 + * tod2 - destination time of the day
 + * Gtb1 - source guest timebase
 + * tb1 - source host timebase
 + * off1 - source timebase offset
 + * tod1 - source time of the day
 + *
 + * The result we want is in @off2
 + *
 + * Two conditions must be met for @off2:
 + * 1) off2 must be multiple of 2^24 ticks as it will be set via TBU40 SPR
 + * 2) Gtb2 = Gtb1
 + */
 +void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env)
 +{
 +uint64_t tb2, tod2, off2;
 +int ratio = tb_env-tb_freq / 100;
 +struct timeval tv;
 +
 +tb2 = cpu_get_real_ticks();
 +gettimeofday(tv, NULL);
 +tod2 = tv.tv_sec * 100 + tv.tv_usec;
 +
 +off2 = tb_env-timebase - tb2 + tb_env-tb_offset;
 +if (tod2  tb_env-time_of_the_day) {
 +off2 += (tod2 - tb_env-time_of_the_day) * ratio;
 +}
 +off2 = ROUND_UP(off2, 1  24);
 +
 +trace_ppc_tb_adjust(tb_env-tb_offset, off2,
 +(int64_t)off2 - tb_env-tb_offset);
 +
 +tb_env-tb_offset = off2;
 +}
 +
  /* Set up (once) timebase frequency (in Hz) */
  clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
  {
 diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h
 index 132ab97..235871c 100644
 --- a/include/hw/ppc/ppc.h
 +++ b/include/hw/ppc/ppc.h
 @@ -32,6 +32,9 @@ struct ppc_tb_t {
  uint64_t purr_start;
  void *opaque;
  uint32_t flags;
 +/* Cached values for live migration purposes */
 +uint64_t timebase;
 +uint64_t time_of_the_day;
  };
  
  /* PPC Timers flags */
 @@ -46,6 +49,7 @@ struct ppc_tb_t {
 */
  
  uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offset);
 +void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env);
  clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq);
  /* Embedded PowerPC DCR management */
  typedef uint32_t (*dcr_read_cb)(void *opaque, int dcrn);
 diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
 index 7af9e3d..93df955 100644
 --- a/target-ppc/kvm.c
 +++ b/target-ppc/kvm.c
 @@ -35,6 +35,7 @@
  #include hw/sysbus.h
  #include hw/ppc/spapr.h
  #include hw/ppc/spapr_vio.h
 +#include hw/ppc/ppc.h
  #include sysemu/watchdog.h
  
  //#define DEBUG_KVM
 @@ -761,6 +762,22 @@ static int kvm_put_vpa(CPUState *cs)
  }
  #endif /* TARGET_PPC64 */
  
 +static int kvm_access_one_reg(CPUState *cs, bool set, __u64 id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +int ret = kvm_vcpu_ioctl(cs, set ? KVM_SET_ONE_REG : KVM_GET_ONE_REG, 
 reg);
 +
 +if (ret) {
 +DPRINTF(Unable to %s time base offset to KVM: %s\n,
 +set ? set : get, strerror(errno));
 +}
 +
 +return ret;
 +}
 +
  int kvm_arch_put_registers(CPUState *cs, int level)
  {
  PowerPCCPU *cpu = POWERPC_CPU(cs);
 @@ -873,6 +890,9 @@ int kvm_arch_put_registers(CPUState *cs, int level)
  DPRINTF(Warning: 

Re: [Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable

2013-09-03 Thread Miroslav Rezanina


- Original Message -
 From: Gerd Hoffmann kra...@redhat.com
 To: mreza...@redhat.com
 Cc: qemu-devel@nongnu.org
 Sent: Tuesday, September 3, 2013 9:41:11 AM
 Subject: Re: [Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable
 
  diff --git a/hw/bt/core.c b/hw/bt/core.c
  index 49012e0..ef27b15 100644
  --- a/hw/bt/core.c
  +++ b/hw/bt/core.c
  @@ -119,3 +119,28 @@ void bt_device_done(struct bt_device_s *dev)
   
   *p = dev-next;
   }
  +
  +static struct bt_vlan_s {
  +struct bt_scatternet_s net;
  +int id;
  +struct bt_vlan_s *next;
  +} *first_bt_vlan;
  +
  +/* find or alloc a new bluetooth VLAN */
  +struct bt_scatternet_s *qemu_find_bt_vlan(int id)
  +{
  +struct bt_vlan_s **pvlan, *vlan;
  +for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) {
  +if (vlan-id == id) {
  +return vlan-net;
  +}
  +}
  +vlan = g_malloc0(sizeof(struct bt_vlan_s));
  +vlan-id = id;
  +pvlan = first_bt_vlan;
  +while (*pvlan != NULL) {
  +pvlan = (*pvlan)-next;
  +}
  +*pvlan = vlan;
  +return vlan-net;
  +}
 
 This (and some other bits) are pure code motion from vl.c, correct?
 Can you split this into a separate patch please?  That'll simplify the
 review o the actual code changes.

Yes, this is pure code motion. I'll split the code to separate patches.
 
 It also doesn't make much sense to compile hw/bt/ with
 CONFIG_USB_BLUETOOTH=n.  It's basically dead code then.
 

Is this true? So -bt option is not useable without usb-bt-dongle? 

 cheers,
   Gerd
 
 
 

-- 
Miroslav Rezanina
Software Engineer - Virtualization Team




Re: [Qemu-devel] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread Peter Maydell
On 3 September 2013 09:35, Andreas Färber afaer...@suse.de wrote:
 I also don't understand why qemu-trivial is suddenly picking up Stefan's
 arm translation patch, it used to be for unmaintained areas only. But
 arm is not my problem.

Yeah, I wasn't expecting that either. But I'd reviewed it and it
wasn't a big change that was likely to conflict with anything else
in my queue, so I didn't feel like making a fuss about it.

-- PMM



Re: [Qemu-devel] [PATCH] w32: Fix access to host devices (regression)

2013-09-03 Thread Kevin Wolf
Am 01.09.2013 um 22:59 hat Stefan Weil geschrieben:
 QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk)
 since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?).
 
 Those devices use hdev_open which did not use the latest API for options.
 This resulted in a fatal runtime error:
 
   Block protocol 'host_device' doesn't support the option 'filename'
 
 Duplicate code from raw_open to fix this.
 
 Signed-off-by: Stefan Weil s...@weilnetz.de

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

 ---
 
 This bug was reported by David Brenner.
 It should be fixed in QEMU 1.6 as well.

Cc: qemu-sta...@nongnu.org

(Ideally you'd also put this Cc line in your commit message.)

Kevin



Re: [Qemu-devel] [PATCH v2] kvm: warn if num cpus is greater than num recommended

2013-09-03 Thread Gleb Natapov
On Fri, Aug 23, 2013 at 03:24:37PM +0200, Andrew Jones wrote:
 The comment in kvm_max_vcpus() states that it's using the recommended
 procedure from the kernel API documentation to get the max number
 of vcpus that kvm supports. It is, but by always returning the
 maximum number supported. The maximum number should only be used
 for development purposes. qemu should check KVM_CAP_NR_VCPUS for
 the recommended number of vcpus. This patch adds a warning if a user
 specifies a number of cpus between the recommended and max.
 
 v2:
 Incorporate tests for max_cpus, which specifies the maximum number
 of hotpluggable cpus. An additional note is that the message for
 the fail case was slightly changed, 'exceeds max cpus' to
 'exceeds the maximum cpus'. If this is unacceptable change for
 users like libvirt, then I'll need to spin a v3.
 
 Signed-off-by: Andrew Jones drjo...@redhat.com
Applied, thanks.

 ---
  kvm-all.c | 69 
 ---
  1 file changed, 40 insertions(+), 29 deletions(-)
 
 diff --git a/kvm-all.c b/kvm-all.c
 index a2d49786365e3..021f5f47e53da 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -1322,24 +1322,20 @@ static int kvm_irqchip_create(KVMState *s)
  return 0;
  }
  
 -static int kvm_max_vcpus(KVMState *s)
 +/* Find number of supported CPUs using the recommended
 + * procedure from the kernel API documentation to cope with
 + * older kernels that may be missing capabilities.
 + */
 +static int kvm_recommended_vcpus(KVMState *s)
  {
 -int ret;
 -
 -/* Find number of supported CPUs using the recommended
 - * procedure from the kernel API documentation to cope with
 - * older kernels that may be missing capabilities.
 - */
 -ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
 -if (ret) {
 -return ret;
 -}
 -ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
 -if (ret) {
 -return ret;
 -}
 +int ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
 +return (ret) ? ret : 4;
 +}
  
 -return 4;
 +static int kvm_max_vcpus(KVMState *s)
 +{
 +int ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
 +return (ret) ? ret : kvm_recommended_vcpus(s);
  }
  
  int kvm_init(void)
 @@ -1347,11 +1343,19 @@ int kvm_init(void)
  static const char upgrade_note[] =
  Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n
  (see http://sourceforge.net/projects/kvm).\n;
 +struct {
 +const char *name;
 +int num;
 +} num_cpus[] = {
 +{ SMP,  smp_cpus },
 +{ hotpluggable, max_cpus },
 +{ NULL, }
 +}, *nc = num_cpus;
 +int soft_vcpus_limit, hard_vcpus_limit;
  KVMState *s;
  const KVMCapabilityInfo *missing_cap;
  int ret;
  int i;
 -int max_vcpus;
  
  s = g_malloc0(sizeof(KVMState));
  
 @@ -1392,19 +1396,26 @@ int kvm_init(void)
  goto err;
  }
  
 -max_vcpus = kvm_max_vcpus(s);
 -if (smp_cpus  max_vcpus) {
 -ret = -EINVAL;
 -fprintf(stderr, Number of SMP cpus requested (%d) exceeds max cpus 
 -supported by KVM (%d)\n, smp_cpus, max_vcpus);
 -goto err;
 -}
 +/* check the vcpu limits */
 +soft_vcpus_limit = kvm_recommended_vcpus(s);
 +hard_vcpus_limit = kvm_max_vcpus(s);
  
 -if (max_cpus  max_vcpus) {
 -ret = -EINVAL;
 -fprintf(stderr, Number of hotpluggable cpus requested (%d) exceeds 
 max cpus 
 -supported by KVM (%d)\n, max_cpus, max_vcpus);
 -goto err;
 +while (nc-name) {
 +if (nc-num  soft_vcpus_limit) {
 +fprintf(stderr,
 +Warning: Number of %s cpus requested (%d) exceeds 
 +the recommended cpus supported by KVM (%d)\n,
 +nc-name, nc-num, soft_vcpus_limit);
 +
 +if (nc-num  hard_vcpus_limit) {
 +ret = -EINVAL;
 +fprintf(stderr, Number of %s cpus requested (%d) exceeds 
 +the maximum cpus supported by KVM (%d)\n,
 +nc-name, nc-num, hard_vcpus_limit);
 +goto err;
 +}
 +}
 +nc++;
  }
  
  s-vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
 -- 
 1.8.1.4

--
Gleb.



Re: [Qemu-devel] [RFC PATCH] spapr: support time base offset migration

2013-09-03 Thread Alexey Kardashevskiy
On 09/03/2013 06:42 PM, Andreas Färber wrote:
 Am 03.09.2013 09:31, schrieb Alexey Kardashevskiy:
 This allows guests to have a different timebase origin from the host.

 This is needed for migration, where a guest can migrate from one host
 to another and the two hosts might have a different timebase origin.
 However, the timebase seen by the guest must not go backwards, and
 should go forwards only by a small amount corresponding to the time
 taken for the migration.

 This is only supported for recent POWER hardware which has the TBU40
 (timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
 970.

 This adds kvm_access_one_reg() to access a special register which is not
 in env-spr.

 The feature must be present in the host kernel.

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

 This is an RFC but not a final patch. Can break something but I just do not 
 see what.

 ---
  hw/ppc/ppc.c | 49 +
  include/hw/ppc/ppc.h |  4 
  target-ppc/kvm.c | 23 +++
  target-ppc/machine.c | 44 
  trace-events |  3 +++
  5 files changed, 123 insertions(+)

 diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
 index 1e3cab3..7d08c9a 100644
 --- a/hw/ppc/ppc.c
 +++ b/hw/ppc/ppc.c
 @@ -31,6 +31,7 @@
  #include hw/loader.h
  #include sysemu/kvm.h
  #include kvm_ppc.h
 +#include trace.h
  
  //#define PPC_DEBUG_IRQ
  #define PPC_DEBUG_TB
 @@ -796,6 +797,54 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t 
 freq)
  cpu_ppc_store_purr(cpu, 0xULL);
  }
  
 +/*
 + * Calculate timebase on the destination side of migration
 + *
 + * We calculate new timebase offset as shown below:
 + * 1) Gtb2 = Gtb1 + max(tod2 - tod1, 0)
 + *Gtb2 = tb2 + off2
 + *Gtb1 = tb1 + off1
 + * 2) tb2 + off2 = tb1 + off1 + max(tod2 - tod1, 0)
 + * 3) off2 = tb1 - tb2 + off1 + max(tod2 - tod1, 0)
 + *
 + * where:
 + * Gtb2 - destination guest timebase
 + * tb2 - destination host timebase
 + * off2 - destination timebase offset
 + * tod2 - destination time of the day
 + * Gtb1 - source guest timebase
 + * tb1 - source host timebase
 + * off1 - source timebase offset
 + * tod1 - source time of the day
 + *
 + * The result we want is in @off2
 + *
 + * Two conditions must be met for @off2:
 + * 1) off2 must be multiple of 2^24 ticks as it will be set via TBU40 SPR
 + * 2) Gtb2 = Gtb1
 + */
 +void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env)
 +{
 +uint64_t tb2, tod2, off2;
 +int ratio = tb_env-tb_freq / 100;
 +struct timeval tv;
 +
 +tb2 = cpu_get_real_ticks();
 +gettimeofday(tv, NULL);
 +tod2 = tv.tv_sec * 100 + tv.tv_usec;
 +
 +off2 = tb_env-timebase - tb2 + tb_env-tb_offset;
 +if (tod2  tb_env-time_of_the_day) {
 +off2 += (tod2 - tb_env-time_of_the_day) * ratio;
 +}
 +off2 = ROUND_UP(off2, 1  24);
 +
 +trace_ppc_tb_adjust(tb_env-tb_offset, off2,
 +(int64_t)off2 - tb_env-tb_offset);
 +
 +tb_env-tb_offset = off2;
 +}
 +
  /* Set up (once) timebase frequency (in Hz) */
  clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
  {
 diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h
 index 132ab97..235871c 100644
 --- a/include/hw/ppc/ppc.h
 +++ b/include/hw/ppc/ppc.h
 @@ -32,6 +32,9 @@ struct ppc_tb_t {
  uint64_t purr_start;
  void *opaque;
  uint32_t flags;
 +/* Cached values for live migration purposes */
 +uint64_t timebase;
 +uint64_t time_of_the_day;
  };
  
  /* PPC Timers flags */
 @@ -46,6 +49,7 @@ struct ppc_tb_t {
 */
  
  uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t 
 tb_offset);
 +void cpu_ppc_adjust_tb_offset(ppc_tb_t *tb_env);
  clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq);
  /* Embedded PowerPC DCR management */
  typedef uint32_t (*dcr_read_cb)(void *opaque, int dcrn);
 diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
 index 7af9e3d..93df955 100644
 --- a/target-ppc/kvm.c
 +++ b/target-ppc/kvm.c
 @@ -35,6 +35,7 @@
  #include hw/sysbus.h
  #include hw/ppc/spapr.h
  #include hw/ppc/spapr_vio.h
 +#include hw/ppc/ppc.h
  #include sysemu/watchdog.h
  
  //#define DEBUG_KVM
 @@ -761,6 +762,22 @@ static int kvm_put_vpa(CPUState *cs)
  }
  #endif /* TARGET_PPC64 */
  
 +static int kvm_access_one_reg(CPUState *cs, bool set, __u64 id, void *addr)
 +{
 +struct kvm_one_reg reg = {
 +.id = id,
 +.addr = (uintptr_t)addr,
 +};
 +int ret = kvm_vcpu_ioctl(cs, set ? KVM_SET_ONE_REG : KVM_GET_ONE_REG, 
 reg);
 +
 +if (ret) {
 +DPRINTF(Unable to %s time base offset to KVM: %s\n,
 +set ? set : get, strerror(errno));
 +}
 +
 +return ret;
 +}
 +
  int kvm_arch_put_registers(CPUState *cs, int level)
  {
  PowerPCCPU *cpu = POWERPC_CPU(cs);
 @@ -873,6 +890,9 @@ int kvm_arch_put_registers(CPUState *cs, int level)

Re: [Qemu-devel] [RFC PATCH] spapr: support time base offset migration

2013-09-03 Thread Andreas Färber
Am 03.09.2013 11:07, schrieb Alexey Kardashevskiy:
 On 09/03/2013 06:42 PM, Andreas Färber wrote:
 Am 03.09.2013 09:31, schrieb Alexey Kardashevskiy:
 diff --git a/target-ppc/machine.c b/target-ppc/machine.c
 index 12e1512..d1ffc7f 100644
 --- a/target-ppc/machine.c
 +++ b/target-ppc/machine.c
[...]
 +static const VMStateDescription vmstate_timebase = {
 +.name = cpu/timebase,
 +.version_id = 1,
 +.minimum_version_id = 1,
 +.minimum_version_id_old = 1,
 +.pre_save = timebase_pre_save,
 +.post_load = timebase_post_load,
 +.fields  = (VMStateField []) {
 +VMSTATE_UINT64(timebase, ppc_tb_t),
 +VMSTATE_INT64(tb_offset, ppc_tb_t),
 +VMSTATE_UINT64(time_of_the_day, ppc_tb_t),
 +VMSTATE_UINT32_EQUAL(tb_freq, ppc_tb_t),
 +VMSTATE_END_OF_LIST()
 +},
 +};
 +
  const VMStateDescription vmstate_ppc_cpu = {
  .name = cpu,
  .version_id = 5,
 @@ -498,6 +538,10 @@ const VMStateDescription vmstate_ppc_cpu = {
  VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
  VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
 +
 +/* Time offset */
 +VMSTATE_STRUCT_POINTER(env.tb_env, PowerPCCPU,
 +   vmstate_timebase, ppc_tb_t *),
  VMSTATE_END_OF_LIST()
  },
  .subsections = (VMStateSubsection []) {

 Breaks the migration format. ;) You need to bump version_id and use a
 macro that accepts the version the field was added in as argument.
 
 Risking of being called ignorant, I'll still ask - is the patch below what
 you mean? I could not find VMSTATE_STRUCT_POINTER_V and I do not believe it
 is not there already.

Usually the way we do it is to have VMSTATE_STRUCT_POINTER() call
VMSTATE_STRUCT_POINTER_V() and thus VMSTATE_STRUCT_POINTER_TEST() call a
new VMSTATE_STRUCT_POINTER_TEST_V(), to avoid code duplication of the
core array entry. CC'ing Juan. Please do the VMState preparation in a
separate patch.

ppc usage looks fine.

 btw why would it break? Just asking. Is it because the source may send what
 the destination cannot handle? Named fields should stop the migration the
 same way as version mismatch would have done.

Nope, field names do not get transmitted, only the section names.
(Otherwise random code refactorings could break the migration format.)

 Or the source won't sent what the destination expects and we do not want
 this destination guest to continue?

There's an incoming stream of data from either live migration or a file,
and QEMU must decide whether it can read and how to interpret the raw
bytestream. It shouldn't just read random bytes into a new field when
they were written from a different field.

 Once I was told that migration between different versions of QEMU is not
 supported - so what is the point of .version_id field at all?

Not sure who told such a thing and in what context. On x86 we try to
avoid version_id bumps by adding subsections to allow migration in both
ways (including from newer to older) but for ppc, arm and all others we
do require that new fields are marked as such. Whether migration is
officially supported is a different matter from the VMState wire format.

Regards,
Andreas


 alexey@ka1:~/pcipassthru/qemu$ git diff
 diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
 index 1c31b5d..7b624bf 100644
 --- a/include/migration/vmstate.h
 +++ b/include/migration/vmstate.h
 @@ -499,6 +499,15 @@ extern const VMStateInfo vmstate_info_bitmap;
  #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)  \
  VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
 
 +#define VMSTATE_STRUCT_POINTER_V(_field, _state,  _vmsd, _type, _version) { \
 +.name = (stringify(_field)), \
 +.version_id = (_version),\
 +.vmsd = (_vmsd),\
 +.size = sizeof(_type),   \
 +.flags= VMS_STRUCT|VMS_POINTER,  \
 +.offset   = vmstate_offset_value(_state, _field, _type), \
 +}
 +
  #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
  VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
  _vmsd, _type)
 diff --git a/target-ppc/machine.c b/target-ppc/machine.c
 index b4f447c..f79f38e 100644
 --- a/target-ppc/machine.c
 +++ b/target-ppc/machine.c
 @@ -501,7 +501,7 @@ static const VMStateDescription vmstate_timebase = {
 
  const VMStateDescription vmstate_ppc_cpu = {
  .name = cpu,
 -.version_id = 5,
 +.version_id = 6,
  .minimum_version_id = 5,
  .minimum_version_id_old = 4,
  .load_state_old = cpu_load_old,
 @@ -540,8 +540,8 @@ const VMStateDescription vmstate_ppc_cpu = {
  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
 
  /* Time offset */
 -

[Qemu-devel] [PATCHv3 0/2] Make usb-bt-dongle configurable

2013-09-03 Thread mrezanin
From: Miroslav Rezanina mreza...@redhat.com

There's group of options allowing enable/disable usb devices.
However, CONFIG_USB_BLUETOOTH can't be removed as there's dependency in vl.c
file. 

This serie allow CONFIG_USB_BLUETOOTH to be disabled.

v3:
 - split patch to two parts

v2:
 - patch rewritten to use usb_legacy_register

Miroslav Rezanina (2):
  Preparation for usb-bt-dongle conditional build
  Make usb-bt-dongle configurable

 hw/bt/core.c   | 23 ++
 hw/bt/hci.c| 48 +
 hw/usb/Makefile.objs   |  3 --
 hw/usb/dev-bluetooth.c | 10 +-
 include/hw/bt.h|  3 ++
 include/hw/usb.h   |  3 --
 vl.c   | 82 +++---
 7 files changed, 87 insertions(+), 85 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCHv3 1/2] Preparation for usb-bt-dongle conditional build

2013-09-03 Thread mrezanin
From: Miroslav Rezanina mreza...@redhat.com

To allow disable usb-bt-dongle device using CONFIG_BLUETOOTH option, some of
functions in vl.c file has to be made accessible in dev-bluetooth.c. This is
pure code moving.

Signed-off-by: Miroslav Rezanina mreza...@redhat.com
---
 hw/bt/core.c| 23 +++
 hw/bt/hci.c | 48 +++
 include/hw/bt.h |  3 +++
 vl.c| 69 -
 4 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/hw/bt/core.c b/hw/bt/core.c
index 49012e0..0ffc948 100644
--- a/hw/bt/core.c
+++ b/hw/bt/core.c
@@ -119,3 +119,26 @@ void bt_device_done(struct bt_device_s *dev)
 
 *p = dev-next;
 }
+
+static struct bt_vlan_s {
+struct bt_scatternet_s net;
+int id;
+struct bt_vlan_s *next;
+} *first_bt_vlan;
+
+/* find or alloc a new bluetooth VLAN */
+struct bt_scatternet_s *qemu_find_bt_vlan(int id)
+{
+struct bt_vlan_s **pvlan, *vlan;
+for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) {
+if (vlan-id == id)
+return vlan-net;
+}
+vlan = g_malloc0(sizeof(struct bt_vlan_s));
+vlan-id = id;
+pvlan = first_bt_vlan;
+while (*pvlan != NULL)
+pvlan = (*pvlan)-next;
+*pvlan = vlan;
+return vlan-net;
+}
diff --git a/hw/bt/hci.c b/hw/bt/hci.c
index d1c0604..7ea3dc6 100644
--- a/hw/bt/hci.c
+++ b/hw/bt/hci.c
@@ -429,6 +429,24 @@ static const uint8_t bt_event_reserved_mask[8] = {
 0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00,
 };
 
+
+static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
+{
+}
+
+static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
+{
+return -ENOTSUP;
+}
+
+struct HCIInfo null_hci = {
+.cmd_send = null_hci_send,
+.sco_send = null_hci_send,
+.acl_send = null_hci_send,
+.bdaddr_set = null_hci_addr_set,
+};
+
+
 static inline uint8_t *bt_hci_event_start(struct bt_hci_s *hci,
 int evt, int len)
 {
@@ -2176,6 +2194,36 @@ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
 return s-info;
 }
 
+struct HCIInfo *hci_init(const char *str)
+{
+char *endp;
+struct bt_scatternet_s *vlan = 0;
+
+if (!strcmp(str, null))
+/* null */
+return null_hci;
+else if (!strncmp(str, host, 4)  (str[4] == '\0' || str[4] == ':'))
+/* host[:hciN] */
+return bt_host_hci(str[4] ? str + 5 : hci0);
+else if (!strncmp(str, hci, 3)) {
+/* hci[,vlan=n] */
+if (str[3]) {
+if (!strncmp(str + 3, ,vlan=, 6)) {
+vlan = qemu_find_bt_vlan(strtol(str + 9, endp, 0));
+if (*endp)
+vlan = 0;
+}
+} else
+vlan = qemu_find_bt_vlan(0);
+if (vlan)
+   return bt_new_hci(vlan);
+}
+
+fprintf(stderr, qemu: Unknown bluetooth HCI `%s'.\n, str);
+
+return 0;
+}
+
 static void bt_hci_done(struct HCIInfo *info)
 {
 struct bt_hci_s *hci = hci_from_info(info);
diff --git a/include/hw/bt.h b/include/hw/bt.h
index 830af94..49a9d03 100644
--- a/include/hw/bt.h
+++ b/include/hw/bt.h
@@ -108,12 +108,15 @@ struct bt_device_s {
 uint16_t clkoff;   /* Note: Always little-endian */
 };
 
+extern struct HCIInfo null_hci;
 /* bt.c */
 void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net);
 void bt_device_done(struct bt_device_s *dev);
+struct bt_scatternet_s *qemu_find_bt_vlan(int id);
 
 /* bt-hci.c */
 struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net);
+struct HCIInfo *hci_init(const char *str);
 
 /* bt-vhci.c */
 void bt_vhci_init(struct HCIInfo *info);
diff --git a/vl.c b/vl.c
index dfbc071..2721a62 100644
--- a/vl.c
+++ b/vl.c
@@ -843,45 +843,6 @@ static int nb_hcis;
 static int cur_hci;
 static struct HCIInfo *hci_table[MAX_NICS];
 
-static struct bt_vlan_s {
-struct bt_scatternet_s net;
-int id;
-struct bt_vlan_s *next;
-} *first_bt_vlan;
-
-/* find or alloc a new bluetooth VLAN */
-static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
-{
-struct bt_vlan_s **pvlan, *vlan;
-for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) {
-if (vlan-id == id)
-return vlan-net;
-}
-vlan = g_malloc0(sizeof(struct bt_vlan_s));
-vlan-id = id;
-pvlan = first_bt_vlan;
-while (*pvlan != NULL)
-pvlan = (*pvlan)-next;
-*pvlan = vlan;
-return vlan-net;
-}
-
-static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
-{
-}
-
-static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
-{
-return -ENOTSUP;
-}
-
-static struct HCIInfo null_hci = {
-.cmd_send = null_hci_send,
-.sco_send = null_hci_send,
-.acl_send = null_hci_send,
-.bdaddr_set = null_hci_addr_set,
-};
-
 struct HCIInfo *qemu_next_hci(void)
 {
 if (cur_hci == nb_hcis)
@@ -890,36 +851,6 @@ struct HCIInfo *qemu_next_hci(void)
 return hci_table[cur_hci++];
 

[Qemu-devel] [PATCHv3 2/2] Remove dev-bluetooth.c dependency from vl.c

2013-09-03 Thread mrezanin
From: Miroslav Rezanina mreza...@redhat.com

Use usb_legacy_register handling to create bt-dongle device and remove code
dependency from vl.c so CONFIG_USB_BLUETOOTH can be disabled.

Signed-off-by: Miroslav Rezanina mreza...@redhat.com
---
 hw/usb/Makefile.objs   |  3 ---
 hw/usb/dev-bluetooth.c | 10 +-
 include/hw/usb.h   |  3 ---
 vl.c   | 13 -
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index f9695e7..a3eac3e 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -18,9 +18,6 @@ common-obj-$(CONFIG_USB_STORAGE_UAS)  += dev-uas.o
 common-obj-$(CONFIG_USB_AUDIO)+= dev-audio.o
 common-obj-$(CONFIG_USB_SERIAL)   += dev-serial.o
 common-obj-$(CONFIG_USB_NETWORK)  += dev-network.o
-
-# FIXME: make configurable too
-CONFIG_USB_BLUETOOTH := y
 common-obj-$(CONFIG_USB_BLUETOOTH)+= dev-bluetooth.o
 
 ifeq ($(CONFIG_USB_SMARTCARD),y)
diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index f2fc2a8..7f292b1 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -511,10 +511,17 @@ static int usb_bt_initfn(USBDevice *dev)
 return 0;
 }
 
-USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci)
+static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
 {
 USBDevice *dev;
 struct USBBtState *s;
+HCIInfo *hci;
+
+if (*cmdline) {
+hci = hci_init(cmdline);
+} else {
+hci = bt_new_hci(qemu_find_bt_vlan(0));
+}
 
 if (!hci)
 return NULL;
@@ -566,6 +573,7 @@ static const TypeInfo bt_info = {
 static void usb_bt_register_types(void)
 {
 type_register_static(bt_info);
+usb_legacy_register(usb-bt-dongle, bt, usb_bt_init);
 }
 
 type_init(usb_bt_register_types)
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 901b0da..695d853 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -442,9 +442,6 @@ int set_usb_string(uint8_t *buf, const char *str);
 USBDevice *usb_host_device_open(USBBus *bus, const char *devname);
 void usb_host_info(Monitor *mon, const QDict *qdict);
 
-/* usb-bt.c */
-USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci);
-
 /* usb ports of the VM */
 
 #define VM_USB_HUB_SIZE 8
diff --git a/vl.c b/vl.c
index 2721a62..794e6b3 100644
--- a/vl.c
+++ b/vl.c
@@ -1457,8 +1457,10 @@ static void configure_msg(QemuOpts *opts)
 
 static int usb_device_add(const char *devname)
 {
-const char *p;
 USBDevice *dev = NULL;
+#ifndef CONFIG_LINUX
+const char *p;
+#endif
 
 if (!usb_enabled(false)) {
 return -1;
@@ -1474,15 +1476,8 @@ static int usb_device_add(const char *devname)
 /* only the linux version is qdev-ified, usb-bsd still needs this */
 if (strstart(devname, host:, p)) {
 dev = usb_host_device_open(usb_bus_find(-1), p);
-} else
-#endif
-if (!strcmp(devname, bt) || strstart(devname, bt:, p)) {
-dev = usb_bt_init(usb_bus_find(-1),
-  devname[2] ? hci_init(p)
- : bt_new_hci(qemu_find_bt_vlan(0)));
-} else {
-return -1;
 }
+#endif
 if (!dev)
 return -1;
 
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH] qemu-iotests: Adjust test result 039

2013-09-03 Thread Stefan Hajnoczi
On Mon, Sep 02, 2013 at 04:36:15PM +0200, Max Reitz wrote:
 The moved OFLAG_COPIED check in qcow2_check_refcounts results in a
 different output from test 039 (mismatches are now found after the
 general refcount check (as far as any remain)). This patch adjusts the
 expected test result accordingly.
 
 Signed-off-by: Max Reitz mre...@redhat.com
 ---
 Follow-up to:
  - Add metadata overlap checks (series, v5); particularly patch 4
(qcow2-refcount: Move OFLAG_COPIED checks)
 ---
  tests/qemu-iotests/039.out | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCH] linux-headers: update to 3.11

2013-09-03 Thread Peter Maydell
On 3 September 2013 09:27, Alexey Kardashevskiy a...@ozlabs.ru wrote:
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---

 I need this update as VFIO on PPC64/pseries got in upstream kernel
 and this is required by VFIO-SPAPR bits in QEMU. Others may find this
 update useful too :)
 ---
  linux-headers/asm-arm64/kvm.h   | 168 
 
  linux-headers/asm-arm64/kvm_para.h  |   1 +
  linux-headers/asm-mips/kvm.h|  81 +
  linux-headers/linux/kvm.h   |   3 +
  linux-headers/linux/vfio.h  |  42 -
  linux-headers/linux/virtio_config.h |   3 +
  6 files changed, 254 insertions(+), 44 deletions(-)
  create mode 100644 linux-headers/asm-arm64/kvm.h
  create mode 100644 linux-headers/asm-arm64/kvm_para.h

I think this should go in via the KVM tree, not trivial.

thanks
-- PMM



Re: [Qemu-devel] [PATCH] linux-headers: update to 3.11

2013-09-03 Thread Alexey Kardashevskiy
On 09/03/2013 07:29 PM, Peter Maydell wrote:
 On 3 September 2013 09:27, Alexey Kardashevskiy a...@ozlabs.ru wrote:
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---

 I need this update as VFIO on PPC64/pseries got in upstream kernel
 and this is required by VFIO-SPAPR bits in QEMU. Others may find this
 update useful too :)
 ---
  linux-headers/asm-arm64/kvm.h   | 168 
 
  linux-headers/asm-arm64/kvm_para.h  |   1 +
  linux-headers/asm-mips/kvm.h|  81 +
  linux-headers/linux/kvm.h   |   3 +
  linux-headers/linux/vfio.h  |  42 -
  linux-headers/linux/virtio_config.h |   3 +
  6 files changed, 254 insertions(+), 44 deletions(-)
  create mode 100644 linux-headers/asm-arm64/kvm.h
  create mode 100644 linux-headers/asm-arm64/kvm_para.h
 
 I think this should go in via the KVM tree, not trivial.

I do not mind, it just went through the trivial tree last time, that's it.


-- 
Alexey



Re: [Qemu-devel] [libvirt] [PATCH 3/5] qemu: add usb-bot support from disks points of view

2013-09-03 Thread Daniel P. Berrange
On Tue, Sep 03, 2013 at 09:51:52AM +0200, Gerd Hoffmann wrote:
 On Mo, 2013-09-02 at 13:57 +0100, Daniel P. Berrange wrote:
  On Mon, Sep 02, 2013 at 05:38:42PM +0800, Guannan Ren wrote:
   usb-bot only supports 16 luns(0~15) and they must be contiguous,
   (using lun 0 and 2 without 1 doesn't work). In this case qemu
   doesn't throw an error, we can not find the lun 2 in guests. So
   Adding a checking function in libvirt to prevent from this case.
  
  Hmm, this seems like a problematic restriction.
 
 It's how the hardware works.
 
  How does this work if we start off a guest with 3 disks
  attached to the usb-bot SCSI controller. Then hot-unplug
  the 2nd disk.
 
 You can't hotplug individual luns anyway.

How does hotplug/unplug work in the context of usb-bot ?

AFAIK we need to be able to run

  device_add usb_bot
  drive_add file...
  device_add scsi-hd

And the reverse, to unplug it, if we're to have feature parity with
usb-storage.


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



Re: [Qemu-devel] [PATCHv7] add qemu-img convert -n option (skip target volume creation)

2013-09-03 Thread Stefan Hajnoczi
On Mon, Sep 02, 2013 at 07:07:24PM +0100, Alex Bligh wrote:
 From: Alexandre Derumier aderum...@odiso.com
 
 Add a -n option to skip volume creation on qemu-img convert.
 This is useful for targets such as rbd / ceph, where the
 target volume may already exist; we cannot always rely on
 qemu-img convert to create the image, as dependent on the
 output format, there may be parameters which are not possible
 to specify through the qemu-img convert command line.
 
 Reviewed-by: Eric Blake ebl...@redhat.com
 Signed-off-by: Alexandre Derumier aderum...@odiso.com
 Signed-off-by: Alex Bligh a...@alex.org.uk
 ---
 
 Changes since v6:
 * Check for outut file too short using bdrv_getlength (Stefan H)
 * Remove spurious comment re compression from test (Stefan H)
 * Remove unused variables from test (Stefan H)
 
 Changes since v5:
 * Change order of case statement for -n to be after -q
 * Add my own copyright string (per Eric Blake)
 
  qemu-img-cmds.hx   |4 +-
  qemu-img.c |   53 +---
  qemu-img.texi  |   15 ++-
  tests/qemu-iotests/060 |   97 
 
  tests/qemu-iotests/060.out |   10 +
  tests/qemu-iotests/group   |1 +
  6 files changed, 162 insertions(+), 18 deletions(-)

Due to the collision with Max's 060 I changed your test case number to
063.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCH] kvm: fix traces to use %x instead of %d

2013-09-03 Thread Andreas Färber
Am 03.09.2013 08:43, schrieb Alexey Kardashevskiy:
 KVM request types are normally defined using hex constants but QEMU traces
 print decimal values instead what is not very convinient.

which is, convenient -- pointing it out early since the KVM guys
don't fix patches once in their queue.

Patch itself:

Reviewed-by: Andreas Färber afaer...@suse.de

Andreas

 
 This changes the request type format from %d to %x.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
  trace-events | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/trace-events b/trace-events
 index 4574f29..24cf4d2 100644
 --- a/trace-events
 +++ b/trace-events
 @@ -1171,9 +1171,9 @@ virtio_ccw_new_device(int cssid, int ssid, int schid, 
 int devno, const char *dev
  migrate_set_state(int new_state) new state %d
  
  # kvm-all.c
 -kvm_ioctl(int type, void *arg) type %d, arg %p
 -kvm_vm_ioctl(int type, void *arg) type %d, arg %p
 -kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %d, 
 arg %p
 +kvm_ioctl(int type, void *arg) type %x, arg %p
 +kvm_vm_ioctl(int type, void *arg) type %x, arg %p
 +kvm_vcpu_ioctl(int cpu_index, int type, void *arg) cpu_index %d, type %x, 
 arg %p
  kvm_run_exit(int cpu_index, uint32_t reason) cpu_index %d, reason %d
  
  # memory.c
 


-- 
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] w32: Fix access to host devices (regression)

2013-09-03 Thread Stefan Hajnoczi
On Sun, Sep 01, 2013 at 10:59:25PM +0200, Stefan Weil wrote:
 QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk)
 since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?).
 
 Those devices use hdev_open which did not use the latest API for options.
 This resulted in a fatal runtime error:
 
   Block protocol 'host_device' doesn't support the option 'filename'
 
 Duplicate code from raw_open to fix this.
 
 Signed-off-by: Stefan Weil s...@weilnetz.de
 ---
 
 This bug was reported by David Brenner.
 It should be fixed in QEMU 1.6 as well.
 
 Stefan
 
  block/raw-win32.c |   36 +---
  1 file changed, 29 insertions(+), 7 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCH 1/4] tcg/optimize: fix know-zero bits optimization

2013-09-03 Thread Andreas Färber
FWIW $subject has a typo. While at it...

Am 03.09.2013 08:27, schrieb Aurelien Jarno:
 Known-zero bits optimization is a great idea that helps to generate more
 optimized code. However the current implementation is basically useless
 as the computed mask is not saved.
 
 Fix this to make it really working.
 
 Cc: Richard Henderson r...@twiddle.net
 Cc: Paolo Bonzini pbonz...@redhat.com
 Signed-off-by: Aurelien Jarno aurel...@aurel32.net
 ---
  tcg/optimize.c |8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)
 
 diff --git a/tcg/optimize.c b/tcg/optimize.c
 index b29bf25..41f2906 100644
 --- a/tcg/optimize.c
 +++ b/tcg/optimize.c
 @@ -695,7 +695,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
 uint16_t *tcg_opc_ptr,
  break;
  }
  
 -/* Simplify using known-zero bits */
 +/* Simplify using known-zero bits. Currently only ops with a single
 +   output argument is supported. */

ops ... are?

Cheers,
Andreas

  mask = -1;
  affected = -1;
  switch (op) {
 @@ -1144,6 +1145,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
 uint16_t *tcg_opc_ptr,
  } else {
  for (i = 0; i  def-nb_oargs; i++) {
  reset_temp(args[i]);
 +/* Save the corresponding known-zero bits mask for the
 +   first output argument (only one supported so far). */
 +if (i == 0) {
 +temps[args[i]].mask = mask;
 +}
  }
  }
  for (i = 0; i  def-nb_args; i++) {
 


-- 
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] w32: Fix access to host devices (regression)

2013-09-03 Thread Andreas Färber
Am 03.09.2013 10:51, schrieb Kevin Wolf:
 Am 01.09.2013 um 22:59 hat Stefan Weil geschrieben:
 QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk)
 since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?).

 Those devices use hdev_open which did not use the latest API for options.
 This resulted in a fatal runtime error:

   Block protocol 'host_device' doesn't support the option 'filename'

 Duplicate code from raw_open to fix this.

 Signed-off-by: Stefan Weil s...@weilnetz.de
 
 Reviewed-by: Kevin Wolf kw...@redhat.com
 
 ---

 This bug was reported by David Brenner.
 It should be fixed in QEMU 1.6 as well.
 
 Cc: qemu-sta...@nongnu.org
 
 (Ideally you'd also put this Cc line in your commit message.)

...and put the attribution as:

Reported-by: David Brenner david.brenn...@gmail.com

Maybe Stefan H. can still add that along with the Cc.

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] aio / timers: fix build of test/test-aio.c on non-linux platforms

2013-09-03 Thread Stefan Hajnoczi
On Thu, Aug 29, 2013 at 05:48:16PM +0100, Alex Bligh wrote:
 tests/test-aio.c used pipe2 which is Linux only. Use qemu_pipe
 and qemu_set_nonblock for portabillity. Addition of O_CLOEXEC
 is a harmless bonus.
 
 Signed-off-by: Alex Bligh a...@alex.org.uk
 ---
  tests/test-aio.c |   11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCHv2] aio / timers: use g_usleep() not sleep()

2013-09-03 Thread Stefan Hajnoczi
On Thu, Aug 29, 2013 at 11:32:14PM +0100, Alex Bligh wrote:
 sleep() apparently doesn't exist under mingw. Use g_usleep for
 portability.
 
 Signed-off-by: Alex Bligh a...@alex.org.uk
 ---
  tests/test-aio.c |6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCH v3 0/2] Fix unassigned memory and I/O access handling

2013-09-03 Thread Andreas Färber
Am 02.09.2013 18:43, schrieb Jan Kiszka:
 Repost of what missed the 1.6 release.
 
 Jan Kiszka (2):
   memory: Provide separate handling of unassigned io ports accesses
   Revert memory: Return -1 again on reads from unsigned regions

These were:

Tested-by: Andreas Färber andreas.faer...@web.de

and they're also missing

Cc: qemu-sta...@nongnu.org

in the commit messages to get them into 1.6.1 now.

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 v5 00/21] AArch64 preparation patchset

2013-09-03 Thread Andreas Färber
Am 01.07.2013 19:34, schrieb Peter Maydell:
 I've left the 'global cpu_env variable' patch alone since
 there wasn't any consensus about what the best approach was;
 it's a pretty minor (and textually localized) thing anyway so
 easy to fix in future if it becomes an actual problem.

Ack.

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] linux-headers: update to 3.11

2013-09-03 Thread Jan Kiszka
On 2013-09-03 11:32, Alexey Kardashevskiy wrote:
 On 09/03/2013 07:29 PM, Peter Maydell wrote:
 On 3 September 2013 09:27, Alexey Kardashevskiy a...@ozlabs.ru wrote:
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---

 I need this update as VFIO on PPC64/pseries got in upstream kernel
 and this is required by VFIO-SPAPR bits in QEMU. Others may find this
 update useful too :)
 ---
  linux-headers/asm-arm64/kvm.h   | 168 
 
  linux-headers/asm-arm64/kvm_para.h  |   1 +
  linux-headers/asm-mips/kvm.h|  81 +
  linux-headers/linux/kvm.h   |   3 +
  linux-headers/linux/vfio.h  |  42 -
  linux-headers/linux/virtio_config.h |   3 +
  6 files changed, 254 insertions(+), 44 deletions(-)
  create mode 100644 linux-headers/asm-arm64/kvm.h
  create mode 100644 linux-headers/asm-arm64/kvm_para.h

 I think this should go in via the KVM tree, not trivial.
 
 I do not mind, it just went through the trivial tree last time, that's it.

This shouldn't be routed through trivial in general as things broke too
often in this area.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [PATCH] exec: check offset_within_address_space for register subpage

2013-09-03 Thread Paolo Bonzini
Il 29/08/2013 12:21, Hu Tao ha scritto:
 If offset_within_address_space falls in a page, then we register a
 subpage. So check offset_within_address_space rather than
 offset_within_region.
 
 Cc: Paolo Bonzini pbonz...@redhat.com
 Cc: Richard Henderson r...@twiddle.net
 Cc: Andreas Färber afaer...@suse.de
 Cc: Peter Maydell peter.mayd...@linaro.org
 Cc: Blue Swirl blauwir...@gmail.com
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  exec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/exec.c b/exec.c
 index 3ca9381..f1f9151 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -869,7 +869,7 @@ static void mem_add(MemoryListener *listener, 
 MemoryRegionSection *section)
  now = remain;
  if (int128_lt(remain.size, page_size)) {
  register_subpage(d, now);
 -} else if (remain.offset_within_region  ~TARGET_PAGE_MASK) {
 +} else if (remain.offset_within_address_space  ~TARGET_PAGE_MASK) {
  now.size = page_size;
  register_subpage(d, now);
  } else {
 

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



Re: [Qemu-devel] [PATCH 1/2] qem-xen: add later wakeup logic when qemu wakeup

2013-09-03 Thread Anthony PERARD
On 01/09/13 10:51, Liu, Jinsong wrote:
 From 86ad3bb83a984ad7bbc00b81d6a0bfc1abc543ca Mon Sep 17 00:00:00 2001
 From: Liu Jinsong jinsong@intel.com
 Date: Sun, 1 Sep 2013 23:39:14 +0800
 Subject: [PATCH 1/2] qemu-xen: add later wakeup logic when qemu wakeup
 
 Currently HVM S3 has a bug coming from the difference between
 qemu-traditioanl and qemu-xen. For qemu-traditional, the way
 to resume from hvm s3 is via 'xl trigger' command. However,
 for qemu-xen, the way to resume from hvm s3 inherited from
 standard qemu, i.e. via QMP, and it doesn't work under Xen.
 
 The root cause is, for qemu-xen, 'xl trigger' command didn't reset
 devices, while QMP didn't unpause hvm domain though they did qemu
 system reset.
 
 We have two qemu-xen patches and one xl patch to fix the HVM S3 bug.
 This patch is the qemu-xen patch 1. It provides a later wakeup notifier
 and a register function, and notifies the later wakeup list when
 qemu wakup by 'xl trigger' command.
 
 Signed-off-by: Liu Jinsong jinsong@intel.com
 ---
  sysemu.h |1 +
  vl.c |8 
  2 files changed, 9 insertions(+), 0 deletions(-)
 
 diff --git a/sysemu.h b/sysemu.h
 index b71f244..4dbcab7 100644
 --- a/sysemu.h
 +++ b/sysemu.h
 @@ -49,6 +49,7 @@ void qemu_register_suspend_notifier(Notifier *notifier);
  void qemu_system_wakeup_request(WakeupReason reason);
  void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
  void qemu_register_wakeup_notifier(Notifier *notifier);
 +void qemu_register_later_wakeup_notifier(Notifier *notifier);
  void qemu_system_shutdown_request(void);
  void qemu_system_powerdown_request(void);
  void qemu_register_powerdown_notifier(Notifier *notifier);
 diff --git a/vl.c b/vl.c
 index 5314f55..1c4842d 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -1478,6 +1478,8 @@ static NotifierList suspend_notifiers =
  NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
  static NotifierList wakeup_notifiers =
  NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
 +static NotifierList later_wakeup_notifiers =
 +NOTIFIER_LIST_INITIALIZER(later_wakeup_notifiers);
  static uint32_t wakeup_reason_mask = ~0;
  static RunState vmstop_requested = RUN_STATE_MAX;
  
 @@ -1668,6 +1670,11 @@ void qemu_register_wakeup_notifier(Notifier *notifier)
  notifier_list_add(wakeup_notifiers, notifier);
  }
  
 +void qemu_register_later_wakeup_notifier(Notifier *notifier)
 +{
 +notifier_list_add(later_wakeup_notifiers, notifier);
 +}
 +
  void qemu_system_killed(int signal, pid_t pid)
  {
  shutdown_signal = signal;
 @@ -1744,6 +1751,7 @@ static bool main_loop_should_exit(void)
  cpu_synchronize_all_states();
  qemu_system_reset(VMRESET_SILENT);
  resume_all_vcpus();
 +notifier_list_notify(later_wakeup_notifiers, NULL);
  monitor_protocol_event(QEVENT_WAKEUP, NULL);
  }
  if (qemu_powerdown_requested()) {
 

The patch those not apply properly to QEMU (upstream) but it just
because the file sysemu.h have been moved to include/sysemu/sysemu.h

Once this is fix:
Acked-by: Anthony PERARD anthony.per...@citrix.com

-- 
Anthony PERARD



Re: [Qemu-devel] [PATCH 2/2] qemu-xen: add qemu xen logic for HVM S3 resume

2013-09-03 Thread Anthony PERARD
On 01/09/13 10:54, Liu, Jinsong wrote:
 From e7d4bd70eae8da131dc3ff2cec70cb2c7b6575a9 Mon Sep 17 00:00:00 2001
 From: Liu Jinsong jinsong@intel.com
 Date: Mon, 2 Sep 2013 00:39:20 +0800
 Subject: [PATCH 2/2] qemu-xen: add qemu xen logic for HVM S3 resume
 
 This patch is qemu-xen patch 2 to fix HVM S3 bug, adding qemu
 xen logic. When qemu wakeup, qemu xen logic is notified and
 hypercall to xen hypervisor to unpause domain.
 
 Signed-off-by: Liu Jinsong jinsong@intel.com
 ---
  xen-all.c |9 +
  1 files changed, 9 insertions(+), 0 deletions(-)
 
 diff --git a/xen-all.c b/xen-all.c
 index 15be8ed..bef946b 100644
 --- a/xen-all.c
 +++ b/xen-all.c
 @@ -97,6 +97,7 @@ typedef struct XenIOState {
  
  Notifier exit;
  Notifier suspend;
 +Notifier later_wakeup;
  } XenIOState;
  
  /* Xen specific function for piix pci */
 @@ -139,6 +140,11 @@ static void xen_suspend_notifier(Notifier *notifier, 
 void *data)
  xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 3);
  }
  
 +static void xen_later_wakeup_notifier(Notifier *notifier, void *data)
 +{
 +xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
 +}
 +
  /* Xen Interrupt Controller */
  
  static void xen_set_irq(void *opaque, int irq, int level)
 @@ -1106,6 +1112,9 @@ int xen_hvm_init(void)
  state-suspend.notify = xen_suspend_notifier;
  qemu_register_suspend_notifier(state-suspend);
  
 +state-later_wakeup.notify = xen_later_wakeup_notifier;
 +qemu_register_later_wakeup_notifier(state-later_wakeup);
 +
  xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IOREQ_PFN, ioreq_pfn);
  DPRINTF(shared page at pfn %lx\n, ioreq_pfn);
  state-shared_page = xc_map_foreign_range(xen_xc, xen_domid, 
 XC_PAGE_SIZE,
 

Acked-by: Anthony PERARD anthony.per...@citrix.com

-- 
Anthony PERARD



Re: [Qemu-devel] [PATCH 1/2] qem-xen: add later wakeup logic when qemu wakeup

2013-09-03 Thread Liu, Jinsong
Anthony PERARD wrote:
 On 01/09/13 10:51, Liu, Jinsong wrote:
 From 86ad3bb83a984ad7bbc00b81d6a0bfc1abc543ca Mon Sep 17 00:00:00
 2001 
 From: Liu Jinsong jinsong@intel.com
 Date: Sun, 1 Sep 2013 23:39:14 +0800
 Subject: [PATCH 1/2] qemu-xen: add later wakeup logic when qemu
 wakeup 
 
 Currently HVM S3 has a bug coming from the difference between
 qemu-traditioanl and qemu-xen. For qemu-traditional, the way
 to resume from hvm s3 is via 'xl trigger' command. However,
 for qemu-xen, the way to resume from hvm s3 inherited from
 standard qemu, i.e. via QMP, and it doesn't work under Xen.
 
 The root cause is, for qemu-xen, 'xl trigger' command didn't reset
 devices, while QMP didn't unpause hvm domain though they did qemu
 system reset.
 
 We have two qemu-xen patches and one xl patch to fix the HVM S3 bug.
 This patch is the qemu-xen patch 1. It provides a later wakeup
 notifier 
 and a register function, and notifies the later wakeup list when
 qemu wakup by 'xl trigger' command.
 
 Signed-off-by: Liu Jinsong jinsong@intel.com
 ---
  sysemu.h |1 +
  vl.c |8 
  2 files changed, 9 insertions(+), 0 deletions(-)
 
 diff --git a/sysemu.h b/sysemu.h
 index b71f244..4dbcab7 100644
 --- a/sysemu.h
 +++ b/sysemu.h
 @@ -49,6 +49,7 @@ void qemu_register_suspend_notifier(Notifier
  *notifier); void qemu_system_wakeup_request(WakeupReason reason);
  void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
  void qemu_register_wakeup_notifier(Notifier *notifier);
 +void qemu_register_later_wakeup_notifier(Notifier *notifier);
  void qemu_system_shutdown_request(void);
  void qemu_system_powerdown_request(void);
  void qemu_register_powerdown_notifier(Notifier *notifier);
 diff --git a/vl.c b/vl.c
 index 5314f55..1c4842d 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -1478,6 +1478,8 @@ static NotifierList suspend_notifiers =
  NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
  static NotifierList wakeup_notifiers =
  NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
 +static NotifierList later_wakeup_notifiers =
 +NOTIFIER_LIST_INITIALIZER(later_wakeup_notifiers);
  static uint32_t wakeup_reason_mask = ~0;
  static RunState vmstop_requested = RUN_STATE_MAX;
 
 @@ -1668,6 +1670,11 @@ void qemu_register_wakeup_notifier(Notifier
  *notifier) notifier_list_add(wakeup_notifiers, notifier);  }
 
 +void qemu_register_later_wakeup_notifier(Notifier *notifier) +{
 +notifier_list_add(later_wakeup_notifiers, notifier); +}
 +
  void qemu_system_killed(int signal, pid_t pid)
  {
  shutdown_signal = signal;
 @@ -1744,6 +1751,7 @@ static bool main_loop_should_exit(void)
  cpu_synchronize_all_states();
  qemu_system_reset(VMRESET_SILENT);
  resume_all_vcpus();
 +notifier_list_notify(later_wakeup_notifiers, NULL);
  monitor_protocol_event(QEVENT_WAKEUP, NULL);  }
  if (qemu_powerdown_requested()) {
 
 
 The patch those not apply properly to QEMU (upstream) but it just
 because the file sysemu.h have been moved to include/sysemu/sysemu.h
 
 Once this is fix:
 Acked-by: Anthony PERARD anthony.per...@citrix.com

Yes. The patches are for qemu-xen tree, to fix xen hvm s3 issue.

Where should the 2 patches be checked in? qemu upstream (then backport to 
qemu-xen tree), or, qemu-xen tree?

Thanks,
Jinsong



Re: [Qemu-devel] [qemu-devel]question on virtqueue_get_avail_bytes

2013-09-03 Thread Amit Shah
On (Mon) 19 Aug 2013 [16:30:54], Stefan Hajnoczi wrote:
 On Mon, Aug 19, 2013 at 05:28:44PM +0800, yinyin wrote:
  Hi,all:
  in func virtqueue_get_avail_bytes, when found a indirect desc, we need 
  loop over it.
  /* loop over the indirect descriptor table */
  indirect = 1;
  max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
  num_bufs = i = 0;
  desc_pa = vring_desc_addr(desc_pa, i);
  But, It init i to 0, then use i to update desc_pa. so we will always 
  get  :
  desc_pa = vring_desc_addr(desc_pa, 0);
  is it right?or should we update desc_pa first, then init i to 0?
 
 Is there a way to trigger a crash or erorr from a normal running guest?
 
 Affected devices: serial, rng, and net - they call
 virtqueue_get_avail_bytes() directly or indirectly.
 
  diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
  index 09f62c6..554ae6f 100644
  --- a/hw/virtio/virtio.c
  +++ b/hw/virtio/virtio.c
  @@ -377,8 +377,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned 
  int *in_bytes,
   /* loop over the indirect descriptor table */
   indirect = 1;
   max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
  -num_bufs = i = 0;
   desc_pa = vring_desc_addr(desc_pa, i);
  +   num_bufs = i = 0;
 
 I agree, this looks wrong.  git-blame(1) doesn't reveal anything
 interesting.  Looks like this bug has been around since 2009!

Hm, why hasn't this bitten anyone yet?

Amit



Re: [Qemu-devel] [qemu-devel]question on virtqueue_get_avail_bytes

2013-09-03 Thread Michael S. Tsirkin
On Tue, Sep 03, 2013 at 04:40:21PM +0530, Amit Shah wrote:
 On (Mon) 19 Aug 2013 [16:30:54], Stefan Hajnoczi wrote:
  On Mon, Aug 19, 2013 at 05:28:44PM +0800, yinyin wrote:
   Hi,all:
 in func virtqueue_get_avail_bytes, when found a indirect desc, we need 
   loop over it.
   /* loop over the indirect descriptor table */
   indirect = 1;
   max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
   num_bufs = i = 0;
   desc_pa = vring_desc_addr(desc_pa, i);
 But, It init i to 0, then use i to update desc_pa. so we will always 
   get  :
 desc_pa = vring_desc_addr(desc_pa, 0);
 is it right?or should we update desc_pa first, then init i to 0?
  
  Is there a way to trigger a crash or erorr from a normal running guest?
  
  Affected devices: serial, rng, and net - they call
  virtqueue_get_avail_bytes() directly or indirectly.
  
   diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
   index 09f62c6..554ae6f 100644
   --- a/hw/virtio/virtio.c
   +++ b/hw/virtio/virtio.c
   @@ -377,8 +377,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, 
   unsigned int *in_bytes,
/* loop over the indirect descriptor table */
indirect = 1;
max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
   -num_bufs = i = 0;
desc_pa = vring_desc_addr(desc_pa, i);
   +   num_bufs = i = 0;
  
  I agree, this looks wrong.  git-blame(1) doesn't reveal anything
  interesting.  Looks like this bug has been around since 2009!
 
 Hm, why hasn't this bitten anyone yet?
 
   Amit


net uses virtqueue_get_avail_bytes for RX only, and drivers
only post single buffers there.

Same seems to be true for other devices?



Re: [Qemu-devel] [PATCH v4 0/3] bugs fix for hpet

2013-09-03 Thread Paolo Bonzini
Il 02/09/2013 09:06, Liu Ping Fan ha scritto:
 note: I rebase it onto Stefan's net-next tree, since pc-1.7 has already been 
 defined there.
 
 v4:
   use standard compat property to set hpet's interrupt compatibility
 
 v3:
   change hpet interrupt capablity on board's demand
 
 
 Liu Ping Fan (3):
   hpet: inverse polarity when pin above ISA_NUM_IRQS
   hpet: entitle more irq pins for hpet
   pc-1.6: add compatibility for hpet intcap on pc-*-1.6
 
  hw/timer/hpet.c  | 27 +++
  include/hw/i386/pc.h |  5 +
  2 files changed, 28 insertions(+), 4 deletions(-)
 

Looks good.  But I have one question; should this be changed for PIIX
too, or should the 1.7 PIIX machine keep the old behavior?  (I have no
idea).

Paolo



Re: [Qemu-devel] [Qemu-trivial] [PATCH] cputlb: remove dead function tlb_update_dirty

2013-09-03 Thread Michael Tokarev
03.09.2013 12:35, Andreas Färber wrote:
 I also don't understand why qemu-trivial is suddenly picking up Stefan's
 arm translation patch, it used to be for unmaintained areas only. But
 arm is not my problem.

Which patch you're talking about?  Is it target-arm: Report unimplemented
opcodes (LOG_UNIMP) ?  If yes, that one appears to be trivial as it just
adds some logging before failing an instruction and should not conflict
with other work being done in this area.  Perhaps I was too aggressive
while picking up the backlog.  We should just draw the line *somewhere*, --
eg, it sure is possible to reject spelling fixes for maintained areas
from -trivial (like this arm tree), - will this be productive?

This change (cputlb: remove dead function) appears to be trivial enough
for me (after looking at the usage history of this function), and I'd
pick it up without this Andreas's request, too.

As for the suddenly - it's not really suddenly, it's because it
has been Cc'd to -trivial (by someone who submitted lots of good
trivial patches before) and actually looks trivial, too.  And also
because subsystem maintainer added his Reviewed-by, apparently (or
hopefully) after noticing it's submitted to -trivial.  I also Cc'd
both maintainers in my notice that it's been applied to -trivial.

Speaking of linux headers sync, I did that once indeed, but don't think
it was a good idea.  It is trivial in a sense that it just makes
headers in qemu to be the same as in current kernel (this is easy to
verify), and the tree - at least in some configuration - compiles.
But indeed, the side effects might be quite a bit unexpected and
non-trivial - in other words, it is a trivial change with
non-trivial possible consequences.

HTH.

/mjt



Re: [Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable

2013-09-03 Thread Gerd Hoffmann
  This (and some other bits) are pure code motion from vl.c, correct?
  Can you split this into a separate patch please?  That'll simplify the
  review o the actual code changes.
 
 Yes, this is pure code motion. I'll split the code to separate patches.
  
  It also doesn't make much sense to compile hw/bt/ with
  CONFIG_USB_BLUETOOTH=n.  It's basically dead code then.
  
 
 Is this true? So -bt option is not useable without usb-bt-dongle? 

Ahem, well, double-checked:  No.

n800+n810 emulation (qemu-system-arm) has a bluetooth hci too.

So we need a separate CONFIG_BLUETOOTH for hw/bt/, so we can enable it
for both arm emulation and for CONFIG_USB_BLUETOOTH=y.  Maybe it makes
sense to wait until we have kconfig.

cheers,
  Gerd





Re: [Qemu-devel] [libvirt] [PATCH 3/5] qemu: add usb-bot support from disks points of view

2013-09-03 Thread Gerd Hoffmann
  Hi,

   How does this work if we start off a guest with 3 disks
   attached to the usb-bot SCSI controller. Then hot-unplug
   the 2nd disk.
  
  You can't hotplug individual luns anyway.
 
 How does hotplug/unplug work in the context of usb-bot ?
 
 AFAIK we need to be able to run
 
   device_add usb_bot
   drive_add file...
   device_add scsi-hd
 
 And the reverse, to unplug it, if we're to have feature parity with
 usb-storage.

Hot-unplug is easy.  You can remove the usb-bot device which will also
remove all child devices.

Hot-plug doesn't work at the moment, and I don't see any obvious way to
fix that properly :-(

We need some way to hotplug a *group* of devices (usb-bot + all
children) as usb-bot itself is hotpluggable but the individual scsi
devices connected to it are not.

I could allow hotplug on usb-bot as workaround, then you can do

  stop
  device_add usb_bot
  device_add scsi-{hd,cd,whatever}
  cont

but that would be more a gross hack than a solution ...

cheers,
  Gerd






[Qemu-devel] [KVM] segmentation fault happened when reboot VM after hot-uplug virtio NIC

2013-09-03 Thread Zhanghaoyu (A)
Hi, all

Segmentation fault happened when reboot VM after hot-unplug virtio NIC, which 
can be reproduced 100%.
See similar bug report to https://bugzilla.redhat.com/show_bug.cgi?id=988256

test environment:
host: SLES11SP2 (kenrel version: 3.0.58)
qemu: 1.5.1, upstream-qemu (commit 545825d4cda03ea292b7788b3401b99860efe8bc)
libvirt: 1.1.0
guest os: win2k8 R2 x64bit or sles11sp2 x64 or win2k3 32bit

You can reproduce this problem by following steps:
1. start a VM with virtio NIC(s)
2. hot-unplug a virtio NIC from the VM
3. reboot the VM, then segmentation fault happened during starting period

the qemu backtrace shown as below:
#0  0x7ff4be3288d0 in __memcmp_sse4_1 () from /lib64/libc.so.6
#1  0x7ff4c07f82c0 in patch_hypercalls (s=0x7ff4c15dd610) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:549
#2  0x7ff4c07f84f0 in vapic_prepare (s=0x7ff4c15dd610) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:614
#3  0x7ff4c07f85e7 in vapic_write (opaque=0x7ff4c15dd610, addr=0, data=32, 
size=2)
at /mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:651
#4  0x7ff4c082a917 in memory_region_write_accessor (opaque=0x7ff4c15df938, 
addr=0, value=0x7ff4bbfe3d00, size=2, 
shift=0, mask=65535) at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:334
#5  0x7ff4c082a9ee in access_with_adjusted_size (addr=0, 
value=0x7ff4bbfe3d00, size=2, access_size_min=1, 
access_size_max=4, access=0x7ff4c082a89a memory_region_write_accessor, 
opaque=0x7ff4c15df938)
at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:364
#6  0x7ff4c082ae49 in memory_region_iorange_write (iorange=0x7ff4c15dfca0, 
offset=0, width=2, data=32)
at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:439
#7  0x7ff4c08236f7 in ioport_writew_thunk (opaque=0x7ff4c15dfca0, addr=126, 
data=32)
at /mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:219
#8  0x7ff4c0823078 in ioport_write (index=1, address=126, data=32) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:83
#9  0x7ff4c0823ca9 in cpu_outw (addr=126, val=32) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:296
#10 0x7ff4c0827485 in kvm_handle_io (port=126, data=0x7ff4c051, 
direction=1, size=2, count=1)
at /mnt/zhanghaoyu/qemu/qemu-1.5.1/kvm-all.c:1485
#11 0x7ff4c0827e14 in kvm_cpu_exec (env=0x7ff4c15bf270) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/kvm-all.c:1634
#12 0x7ff4c07b6f27 in qemu_kvm_cpu_thread_fn (arg=0x7ff4c15bf270) at 
/mnt/zhanghaoyu/qemu/qemu-1.5.1/cpus.c:759
#13 0x7ff4be58af05 in start_thread () from /lib64/libpthread.so.0
#14 0x7ff4be2cd53d in clone () from /lib64/libc.so.6

If I apply below patch to the upstream qemu, this problem will disappear,
---
 hw/i386/kvmvapic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 15beb80..6fff299 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -652,11 +652,11 @@ static void vapic_write(void *opaque, hwaddr addr, 
uint64_t data,
 switch (size) {
 case 2:
 if (s-state == VAPIC_INACTIVE) {
-rom_paddr = (env-segs[R_CS].base + env-eip)  ROM_BLOCK_MASK;
-s-rom_state_paddr = rom_paddr + data;
-
 s-state = VAPIC_STANDBY;
 }
+rom_paddr = (env-segs[R_CS].base + env-eip)  ROM_BLOCK_MASK;
+s-rom_state_paddr = rom_paddr + data;
+
 if (vapic_prepare(s)  0) {
 s-state = VAPIC_INACTIVE;
 break;
--
1.8.1.4

Thanks,
Daniel






Re: [Qemu-devel] [KVM] segmentation fault happened when reboot VM after hot-uplug virtio NIC

2013-09-03 Thread Gleb Natapov
On Tue, Sep 03, 2013 at 12:06:33PM +, Zhanghaoyu (A) wrote:
 Hi, all
 
 Segmentation fault happened when reboot VM after hot-unplug virtio NIC, which 
 can be reproduced 100%.
 See similar bug report to https://bugzilla.redhat.com/show_bug.cgi?id=988256
 
 test environment:
 host: SLES11SP2 (kenrel version: 3.0.58)
 qemu: 1.5.1, upstream-qemu (commit 545825d4cda03ea292b7788b3401b99860efe8bc)
 libvirt: 1.1.0
 guest os: win2k8 R2 x64bit or sles11sp2 x64 or win2k3 32bit
 
 You can reproduce this problem by following steps:
 1. start a VM with virtio NIC(s)
 2. hot-unplug a virtio NIC from the VM
 3. reboot the VM, then segmentation fault happened during starting period
 
 the qemu backtrace shown as below:
 #0  0x7ff4be3288d0 in __memcmp_sse4_1 () from /lib64/libc.so.6
 #1  0x7ff4c07f82c0 in patch_hypercalls (s=0x7ff4c15dd610) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:549
 #2  0x7ff4c07f84f0 in vapic_prepare (s=0x7ff4c15dd610) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:614
 #3  0x7ff4c07f85e7 in vapic_write (opaque=0x7ff4c15dd610, addr=0, 
 data=32, size=2)
 at /mnt/zhanghaoyu/qemu/qemu-1.5.1/hw/i386/kvmvapic.c:651
 #4  0x7ff4c082a917 in memory_region_write_accessor 
 (opaque=0x7ff4c15df938, addr=0, value=0x7ff4bbfe3d00, size=2, 
 shift=0, mask=65535) at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:334
 #5  0x7ff4c082a9ee in access_with_adjusted_size (addr=0, 
 value=0x7ff4bbfe3d00, size=2, access_size_min=1, 
 access_size_max=4, access=0x7ff4c082a89a memory_region_write_accessor, 
 opaque=0x7ff4c15df938)
 at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:364
 #6  0x7ff4c082ae49 in memory_region_iorange_write 
 (iorange=0x7ff4c15dfca0, offset=0, width=2, data=32)
 at /mnt/zhanghaoyu/qemu/qemu-1.5.1/memory.c:439
 #7  0x7ff4c08236f7 in ioport_writew_thunk (opaque=0x7ff4c15dfca0, 
 addr=126, data=32)
 at /mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:219
 #8  0x7ff4c0823078 in ioport_write (index=1, address=126, data=32) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:83
 #9  0x7ff4c0823ca9 in cpu_outw (addr=126, val=32) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/ioport.c:296
 #10 0x7ff4c0827485 in kvm_handle_io (port=126, data=0x7ff4c051, 
 direction=1, size=2, count=1)
 at /mnt/zhanghaoyu/qemu/qemu-1.5.1/kvm-all.c:1485
 #11 0x7ff4c0827e14 in kvm_cpu_exec (env=0x7ff4c15bf270) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/kvm-all.c:1634
 #12 0x7ff4c07b6f27 in qemu_kvm_cpu_thread_fn (arg=0x7ff4c15bf270) at 
 /mnt/zhanghaoyu/qemu/qemu-1.5.1/cpus.c:759
 #13 0x7ff4be58af05 in start_thread () from /lib64/libpthread.so.0
 #14 0x7ff4be2cd53d in clone () from /lib64/libc.so.6
 
 If I apply below patch to the upstream qemu, this problem will disappear,
 ---
  hw/i386/kvmvapic.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
 index 15beb80..6fff299 100644
 --- a/hw/i386/kvmvapic.c
 +++ b/hw/i386/kvmvapic.c
 @@ -652,11 +652,11 @@ static void vapic_write(void *opaque, hwaddr addr, 
 uint64_t data,
  switch (size) {
  case 2:
  if (s-state == VAPIC_INACTIVE) {
 -rom_paddr = (env-segs[R_CS].base + env-eip)  ROM_BLOCK_MASK;
 -s-rom_state_paddr = rom_paddr + data;
 -
  s-state = VAPIC_STANDBY;
  }
 +rom_paddr = (env-segs[R_CS].base + env-eip)  ROM_BLOCK_MASK;
 +s-rom_state_paddr = rom_paddr + data;
 +
Jan, does this mean that vapic state dies not move to inactive during
reset?

  if (vapic_prepare(s)  0) {
  s-state = VAPIC_INACTIVE;
  break;
 --
 1.8.1.4
 
 Thanks,
 Daniel
 
 

--
Gleb.



[Qemu-devel] [PATCH 01/38] qdev: document assumption that unrealize is followed by finalize

2013-09-03 Thread Paolo Bonzini
This becomes important when undoing realize's initializations is split
in two places (unrealize and exit).

The way to fix this could be to split realize further into alloc (done
once) and realize (can be undone).

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 include/hw/qdev-core.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 46972f4..d840f06 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -86,6 +86,10 @@ struct VMStateDescription;
  * object_initialize() in their own #TypeInfo.instance_init and forward the
  * realization events appropriately.
  *
+ * Note that for now it is not possible to unrealize a device and then
+ * re-realize it.  While this may change in the future, it is a valid
+ * assumption for now.
+ *
  * The @init callback is considered private to a particular bus implementation
  * (immediate abstract child types of TYPE_DEVICE). Derived leaf types set an
  * init callback on their parent class instead.
-- 
1.8.3.1





[Qemu-devel] [PATCH 07/38] tpci200: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/char/tpci200.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/char/tpci200.c b/hw/char/tpci200.c
index d9e17b2..948a188 100644
--- a/hw/char/tpci200.c
+++ b/hw/char/tpci200.c
@@ -613,8 +613,9 @@ static int tpci200_initfn(PCIDevice *pci_dev)
 return 0;
 }
 
-static void tpci200_exitfn(PCIDevice *pci_dev)
+static void tpci200_instance_finalize(Object *obj)
 {
+PCIDevice *pci_dev = PCI_DEVICE(obj);
 TPCI200State *s = TPCI200(pci_dev);
 
 memory_region_destroy(s-mmio);
@@ -646,7 +647,6 @@ static void tpci200_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = tpci200_initfn;
-k-exit = tpci200_exitfn;
 k-vendor_id = PCI_VENDOR_ID_TEWS;
 k-device_id = PCI_DEVICE_ID_TEWS_TPCI200;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
@@ -662,6 +662,7 @@ static const TypeInfo tpci200_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(TPCI200State),
 .class_init= tpci200_class_init,
+.instance_finalize = tpci200_instance_finalize,
 };
 
 static void tpci200_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 03/38] ac97: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/audio/ac97.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 01b4dfb..04ae601 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1390,8 +1390,9 @@ static int ac97_initfn (PCIDevice *dev)
 return 0;
 }
 
-static void ac97_exitfn (PCIDevice *dev)
+static void ac97_instance_finalize (Object *obj)
 {
+PCIDevice *dev = PCI_DEVICE(obj);
 AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev);
 
 memory_region_destroy (s-io_nam);
@@ -1415,7 +1416,6 @@ static void ac97_class_init (ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
 k-init = ac97_initfn;
-k-exit = ac97_exitfn;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
 k-revision = 0x01;
@@ -1431,6 +1431,7 @@ static const TypeInfo ac97_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof (AC97LinkState),
 .class_init= ac97_class_init,
+.instance_finalize = ac97_instance_finalize,
 };
 
 static void ac97_register_types (void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 06/38] serial: reclaim memory in instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/char/serial-pci.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c
index aec6705..6dd34d3 100644
--- a/hw/char/serial-pci.c
+++ b/hw/char/serial-pci.c
@@ -131,6 +131,14 @@ static void serial_pci_exit(PCIDevice *dev)
 SerialState *s = pci-state;
 
 serial_exit_core(s);
+}
+
+static void serial_pci_instance_finalize(Object *obj)
+{
+PCIDevice *dev = PCI_DEVICE(obj);
+PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev);
+SerialState *s = pci-state;
+
 memory_region_destroy(s-io);
 }
 
@@ -143,9 +151,22 @@ static void multi_serial_pci_exit(PCIDevice *dev)
 for (i = 0; i  pci-ports; i++) {
 s = pci-state + i;
 serial_exit_core(s);
+}
+}
+
+static void multi_serial_pci_instance_finalize(Object *obj)
+{
+PCIDevice *dev = PCI_DEVICE(obj);
+PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
+SerialState *s;
+int i;
+
+for (i = 0; i  pci-ports; i++) {
+s = pci-state + i;
 memory_region_destroy(s-io);
 g_free(pci-name[i]);
 }
+
 memory_region_destroy(pci-iobar);
 qemu_free_irqs(pci-irqs);
 }
@@ -243,6 +264,7 @@ static const TypeInfo serial_pci_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCISerialState),
 .class_init= serial_pci_class_initfn,
+.instance_finalize = serial_pci_instance_finalize,
 };
 
 static const TypeInfo multi_2x_serial_pci_info = {
@@ -250,6 +272,7 @@ static const TypeInfo multi_2x_serial_pci_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIMultiSerialState),
 .class_init= multi_2x_serial_pci_class_initfn,
+.instance_finalize = multi_serial_pci_instance_finalize,
 };
 
 static const TypeInfo multi_4x_serial_pci_info = {
@@ -257,6 +280,7 @@ static const TypeInfo multi_4x_serial_pci_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIMultiSerialState),
 .class_init= multi_4x_serial_pci_class_initfn,
+.instance_finalize = multi_serial_pci_instance_finalize,
 };
 
 static void serial_pci_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 12/38] ide/piix: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/ide/piix.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index e6e6c0b..ddd72c1 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -200,9 +200,9 @@ PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo 
**hd_table, int devfn)
 return dev;
 }
 
-static void pci_piix_ide_exitfn(PCIDevice *dev)
+static void pci_piix_ide_instance_finalize(Object *obj)
 {
-PCIIDEState *d = PCI_IDE(dev);
+PCIIDEState *d = PCI_IDE(obj);
 unsigned i;
 
 for (i = 0; i  2; ++i) {
@@ -243,7 +243,6 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
*data)
 
 k-no_hotplug = 1;
 k-init = pci_piix_ide_initfn;
-k-exit = pci_piix_ide_exitfn;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
@@ -255,6 +254,7 @@ static const TypeInfo piix3_ide_info = {
 .name  = piix3-ide,
 .parent= TYPE_PCI_IDE,
 .class_init= piix3_ide_class_init,
+.instance_finalize = pci_piix_ide_instance_finalize,
 };
 
 static void piix3_ide_xen_class_init(ObjectClass *klass, void *data)
@@ -275,6 +275,7 @@ static const TypeInfo piix3_ide_xen_info = {
 .name  = piix3-ide-xen,
 .parent= TYPE_PCI_IDE,
 .class_init= piix3_ide_xen_class_init,
+.instance_finalize = pci_piix_ide_instance_finalize,
 };
 
 static void piix4_ide_class_init(ObjectClass *klass, void *data)
@@ -284,7 +285,6 @@ static void piix4_ide_class_init(ObjectClass *klass, void 
*data)
 
 k-no_hotplug = 1;
 k-init = pci_piix_ide_initfn;
-k-exit = pci_piix_ide_exitfn;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB;
 k-class_id = PCI_CLASS_STORAGE_IDE;
@@ -296,6 +296,7 @@ static const TypeInfo piix4_ide_info = {
 .name  = piix4-ide,
 .parent= TYPE_PCI_IDE,
 .class_init= piix4_ide_class_init,
+.instance_finalize = pci_piix_ide_instance_finalize,
 };
 
 static void piix_ide_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 04/38] es1370: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/audio/es1370.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index adb66ce..b68fb84 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -1044,8 +1044,9 @@ static int es1370_initfn (PCIDevice *dev)
 return 0;
 }
 
-static void es1370_exitfn (PCIDevice *dev)
+static void es1370_instance_finalize (Object *obj)
 {
+PCIDevice *dev = PCI_DEVICE(obj);
 ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
 
 memory_region_destroy (s-io);
@@ -1063,7 +1064,6 @@ static void es1370_class_init (ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
 k-init = es1370_initfn;
-k-exit = es1370_exitfn;
 k-vendor_id = PCI_VENDOR_ID_ENSONIQ;
 k-device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
 k-class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
@@ -1079,6 +1079,7 @@ static const TypeInfo es1370_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof (ES1370State),
 .class_init= es1370_class_init,
+.instance_finalize = es1370_instance_finalize,
 };
 
 static void es1370_register_types (void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 13/38] ide/via: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/ide/via.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index e5fb297..0b63bee 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -191,9 +191,9 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
 return 0;
 }
 
-static void vt82c686b_ide_exitfn(PCIDevice *dev)
+static void vt82c686b_ide_instance_finalize(Object *obj)
 {
-PCIIDEState *d = PCI_IDE(dev);
+PCIIDEState *d = PCI_IDE(obj);
 unsigned i;
 
 for (i = 0; i  2; ++i) {
@@ -219,7 +219,6 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = vt82c686b_ide_initfn;
-k-exit = vt82c686b_ide_exitfn;
 k-vendor_id = PCI_VENDOR_ID_VIA;
 k-device_id = PCI_DEVICE_ID_VIA_IDE;
 k-revision = 0x06;
@@ -232,6 +231,7 @@ static const TypeInfo via_ide_info = {
 .name  = via-ide,
 .parent= TYPE_PCI_IDE,
 .class_init= via_ide_class_init,
+.instance_finalize = vt82c686b_ide_instance_finalize,
 };
 
 static void via_ide_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 25/38] pcie_aer: pcie_aer_exit really frees stuff

2013-09-03 Thread Paolo Bonzini
Rename it to pcie_aer_free, and move it together with other
freeing functions.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/pci-bridge/ioh3420.c| 2 +-
 hw/pci-bridge/xio3130_downstream.c | 2 +-
 hw/pci-bridge/xio3130_upstream.c   | 2 +-
 hw/pci/pcie_aer.c  | 3 ++-
 include/hw/pci/pcie_aer.h  | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/pci-bridge/ioh3420.c b/hw/pci-bridge/ioh3420.c
index 16f0cf8..cadf103 100644
--- a/hw/pci-bridge/ioh3420.c
+++ b/hw/pci-bridge/ioh3420.c
@@ -150,11 +150,11 @@ static void ioh3420_exitfn(PCIDevice *d)
 {
 PCIESlot *s = PCIE_SLOT(d);
 
-pcie_aer_exit(d);
 pcie_chassis_del_slot(s);
 pcie_cap_exit(d);
 msi_uninit(d);
 pci_bridge_exitfn(d);
+pcie_aer_free(d);
 pci_bridge_free(d);
 }
 
diff --git a/hw/pci-bridge/xio3130_downstream.c 
b/hw/pci-bridge/xio3130_downstream.c
index a0ac179..75522c6 100644
--- a/hw/pci-bridge/xio3130_downstream.c
+++ b/hw/pci-bridge/xio3130_downstream.c
@@ -115,11 +115,11 @@ static void xio3130_downstream_exitfn(PCIDevice *d)
 {
 PCIESlot *s = PCIE_SLOT(d);
 
-pcie_aer_exit(d);
 pcie_chassis_del_slot(s);
 pcie_cap_exit(d);
 msi_uninit(d);
 pci_bridge_exitfn(d);
+pcie_aer_free(d);
 pci_bridge_free(d);
 }
 
diff --git a/hw/pci-bridge/xio3130_upstream.c b/hw/pci-bridge/xio3130_upstream.c
index 682a7e5..5cfdbc7 100644
--- a/hw/pci-bridge/xio3130_upstream.c
+++ b/hw/pci-bridge/xio3130_upstream.c
@@ -100,10 +100,10 @@ err_bridge:
 
 static void xio3130_upstream_exitfn(PCIDevice *d)
 {
-pcie_aer_exit(d);
 pcie_cap_exit(d);
 msi_uninit(d);
 pci_bridge_exitfn(d);
+pcie_aer_free(d);
 pci_bridge_free(d);
 }
 
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index ca762ab..509f77e 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -163,9 +163,10 @@ int pcie_aer_init(PCIDevice *dev, uint16_t offset)
 return 0;
 }
 
-void pcie_aer_exit(PCIDevice *dev)
+void pcie_aer_free(PCIDevice *dev)
 {
 g_free(dev-exp.aer_log.log);
+dev-exp.aer_log.log = NULL;
 }
 
 static void pcie_aer_update_uncor_status(PCIDevice *dev)
diff --git a/include/hw/pci/pcie_aer.h b/include/hw/pci/pcie_aer.h
index bcac80a..af1dec3 100644
--- a/include/hw/pci/pcie_aer.h
+++ b/include/hw/pci/pcie_aer.h
@@ -88,7 +88,7 @@ struct PCIEAERErr {
 extern const VMStateDescription vmstate_pcie_aer_log;
 
 int pcie_aer_init(PCIDevice *dev, uint16_t offset);
-void pcie_aer_exit(PCIDevice *dev);
+void pcie_aer_free(PCIDevice *dev);
 void pcie_aer_write_config(PCIDevice *dev,
uint32_t addr, uint32_t val, int len);
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 18/38] eepro100: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/net/eepro100.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index ffa60d5..9d45aa4 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -1840,8 +1840,9 @@ static void nic_cleanup(NetClientState *nc)
 s-nic = NULL;
 }
 
-static void pci_nic_uninit(PCIDevice *pci_dev)
+static void pci_nic_instance_finalize(Object *obj)
 {
+PCIDevice *pci_dev = PCI_DEVICE(obj);
 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
 memory_region_destroy(s-mmio_bar);
@@ -2090,7 +2091,6 @@ static void eepro100_class_init(ObjectClass *klass, void 
*data)
 k-class_id = PCI_CLASS_NETWORK_ETHERNET;
 k-romfile = pxe-eepro100.rom;
 k-init = e100_nic_init;
-k-exit = pci_nic_uninit;
 k-device_id = info-device_id;
 k-revision = info-revision;
 k-subsystem_vendor_id = info-subsystem_vendor_id;
@@ -2108,6 +2108,7 @@ static void eepro100_register_types(void)
 type_info.parent = TYPE_PCI_DEVICE;
 type_info.class_init = eepro100_class_init;
 type_info.instance_size = sizeof(EEPRO100State);
+type_info.instance_finalize = pci_nic_instance_finalize;
 
 type_register(type_info);
 }
-- 
1.8.3.1





[Qemu-devel] [PATCH 08/38] pci-assign: reclaim memory in instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/i386/kvm/pci-assign.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 011764f..9d0ff3f 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1829,6 +1829,13 @@ static void assigned_exitfn(struct PCIDevice *pci_dev)
 AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 
 deassign_device(dev);
+}
+
+static void assigned_instance_finalize(Object *obj)
+{
+PCIDevice *pci_dev = PCI_DEVICE(obj);
+AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
+
 free_assigned_device(dev);
 }
 
@@ -1864,6 +1871,7 @@ static const TypeInfo assign_info = {
 .parent = TYPE_PCI_DEVICE,
 .instance_size  = sizeof(AssignedDevice),
 .class_init = assign_class_init,
+.instance_finalize  = assigned_instance_finalize,
 };
 
 static void assign_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 15/38] pci-testdev: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/misc/pci-testdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index ca53b3f..10bf145 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -280,9 +280,9 @@ static int pci_testdev_init(PCIDevice *pci_dev)
 }
 
 static void
-pci_testdev_uninit(PCIDevice *dev)
+pci_testdev_instance_finalize(Object *obj)
 {
-PCITestDevState *d = PCI_TEST_DEV(dev);
+PCITestDevState *d = PCI_TEST_DEV(obj);
 int i;
 
 pci_testdev_reset(d);
@@ -309,7 +309,6 @@ static void pci_testdev_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = pci_testdev_init;
-k-exit = pci_testdev_uninit;
 k-vendor_id = PCI_VENDOR_ID_REDHAT;
 k-device_id = PCI_DEVICE_ID_REDHAT_TEST;
 k-revision = 0x00;
@@ -324,6 +323,7 @@ static const TypeInfo pci_testdev_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCITestDevState),
 .class_init= pci_testdev_class_init,
+.instance_finalize = pci_testdev_instance_finalize,
 };
 
 static void pci_testdev_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 31/38] esp: use instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/scsi/esp-pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c
index d7ec173..127868d 100644
--- a/hw/scsi/esp-pci.c
+++ b/hw/scsi/esp-pci.c
@@ -374,9 +374,9 @@ static int esp_pci_scsi_init(PCIDevice *dev)
 return 0;
 }
 
-static void esp_pci_scsi_uninit(PCIDevice *d)
+static void esp_pci_scsi_instance_finalize(Object *obj)
 {
-PCIESPState *pci = PCI_ESP(d);
+PCIESPState *pci = PCI_ESP(obj);
 
 memory_region_destroy(pci-io);
 }
@@ -387,7 +387,6 @@ static void esp_pci_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = esp_pci_scsi_init;
-k-exit = esp_pci_scsi_uninit;
 k-vendor_id = PCI_VENDOR_ID_AMD;
 k-device_id = PCI_DEVICE_ID_AMD_SCSI;
 k-revision = 0x10;
@@ -403,6 +402,7 @@ static const TypeInfo esp_pci_info = {
 .parent = TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIESPState),
 .class_init = esp_pci_class_init,
+.instance_finalize = esp_pci_scsi_instance_finalize,
 };
 
 typedef struct {
-- 
1.8.3.1





[Qemu-devel] [PATCH 14/38] ivshmem: reclaim memory in instance_finalize instead of exit

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/misc/ivshmem.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 2838866..46d8c27 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -784,17 +784,23 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
 {
 IVShmemState *s = IVSHMEM(dev);
 
+memory_region_del_subregion(s-bar, s-ivshmem);
+}
+
+static void pci_ivshmem_instance_finalize(Object *obj)
+{
+IVShmemState *s = IVSHMEM(obj);
+
 if (s-migration_blocker) {
 migrate_del_blocker(s-migration_blocker);
 error_free(s-migration_blocker);
 }
 
 memory_region_destroy(s-ivshmem_mmio);
-memory_region_del_subregion(s-bar, s-ivshmem);
-vmstate_unregister_ram(s-ivshmem, DEVICE(dev));
+vmstate_unregister_ram(s-ivshmem, DEVICE(s));
 memory_region_destroy(s-ivshmem);
 memory_region_destroy(s-bar);
-unregister_savevm(DEVICE(dev), ivshmem, s);
+unregister_savevm(DEVICE(s), ivshmem, s);
 }
 
 static Property ivshmem_properties[] = {
@@ -829,6 +835,7 @@ static const TypeInfo ivshmem_info = {
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(IVShmemState),
 .class_init= ivshmem_class_init,
+.instance_finalize = pci_ivshmem_instance_finalize,
 };
 
 static void ivshmem_register_types(void)
-- 
1.8.3.1





[Qemu-devel] [PATCH 23/38] shpc: split shpc_free from shpc_cleanup

2013-09-03 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/pci-bridge/pci_bridge_dev.c | 2 ++
 hw/pci/shpc.c  | 8 +++-
 include/hw/pci/shpc.h  | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index a9392c7..97dfc49 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -79,6 +79,7 @@ msi_error:
 slotid_cap_cleanup(dev);
 slotid_error:
 shpc_cleanup(dev, bridge_dev-bar);
+shpc_free(dev);
 shpc_error:
 memory_region_destroy(bridge_dev-bar);
 pci_bridge_exitfn(dev);
@@ -94,6 +95,7 @@ static void pci_bridge_dev_exitfn(PCIDevice *dev)
 }
 slotid_cap_cleanup(dev);
 shpc_cleanup(dev, bridge_dev-bar);
+shpc_free(dev);
 memory_region_destroy(bridge_dev-bar);
 pci_bridge_exitfn(dev);
 }
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index eb092fd..cefaf69 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -630,15 +630,21 @@ int shpc_bar_size(PCIDevice *d)
 void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
 {
 SHPCDevice *shpc = d-shpc;
+/* TODO: cleanup config space changes? */
 d-cap_present = ~QEMU_PCI_CAP_SHPC;
 memory_region_del_subregion(bar, shpc-mmio);
-/* TODO: cleanup config space changes? */
+}
+
+void shpc_free(PCIDevice *d)
+{
+SHPCDevice *shpc = d-shpc;
 g_free(shpc-config);
 g_free(shpc-cmask);
 g_free(shpc-wmask);
 g_free(shpc-w1cmask);
 memory_region_destroy(shpc-mmio);
 g_free(shpc);
+d-shpc = NULL;
 }
 
 void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h
index 467911a..5f27431 100644
--- a/include/hw/pci/shpc.h
+++ b/include/hw/pci/shpc.h
@@ -39,6 +39,7 @@ void shpc_reset(PCIDevice *d);
 int shpc_bar_size(PCIDevice *dev);
 int shpc_init(PCIDevice *dev, PCIBus *sec_bus, MemoryRegion *bar, unsigned 
off);
 void shpc_cleanup(PCIDevice *dev, MemoryRegion *bar);
+void shpc_free(PCIDevice *d);
 void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len);
 
 extern VMStateInfo shpc_vmstate_info;
-- 
1.8.3.1





  1   2   3   >