Re: [Qemu-devel] [RFC PATCH v5 1/6] make.rule: fix $(obj) to a real relative path

2013-09-11 Thread Fam Zheng
On Wed, 09/11 08:30, Paolo Bonzini wrote:
> Il 11/09/2013 07:38, Fam Zheng ha scritto:
> > Makefile.target includes rule.mak and unnested common-obj-y, then prefix
> > them with '../', this will ignore object specific QEMU_CFLAGS in subdir
> > Makefile.objs:
> > 
> > $(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)
> > 
> > Because $(obj) here is './block', instead of '../block'. This doesn't
> > hurt compiling because we basically build all .o from top Makefile,
> > before entering Makefile.target, but it will affact arriving per-object
> > libs support.
> > 
> > The starting point of $(obj) is passed in as argument of unnest-vars, as
> > well as nested variables, so that different Makefiles can pass in a
> > right value.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  Makefile| 16 +++-
> >  Makefile.objs   | 16 +---
> >  Makefile.target | 16 +---
> >  configure   |  1 +
> >  rules.mak   | 12 +++-
> >  tests/Makefile  |  2 ++
> >  6 files changed, 39 insertions(+), 24 deletions(-)
> 
> Just two questions...
> 
> > diff --git a/Makefile.target b/Makefile.target
> > index 9a49852..1d92523 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -143,13 +143,23 @@ endif # CONFIG_SOFTMMU
> >  # Workaround for http://gcc.gnu.org/PR55489, see configure.
> >  %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
> >  
> > -nested-vars += obj-y
> > +dummy := $(call unnest-vars,,obj-y)
> >  
> > -# This resolves all nested paths, so it must come last
> > +# we are making another call to unnest-vars with different vars, protect 
> > obj-y,
> > +# it can be overriden in subdir Makefile.objs
> > +obj-y-save := $(obj-y)
> > +
> > +block-obj-y :=
> > +common-obj-y :=
> >  include $(SRC_PATH)/Makefile.objs
> > +dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
> > +
> > +# Now restore obj-y
> > +obj-y := $(obj-y-save)
> >  
> >  all-obj-y = $(obj-y)
> > -all-obj-y += $(addprefix ../, $(common-obj-y))
> > +all-obj-y += $(addprefix ../, $(common-obj-y) $(block-obj-y))
> 
> Why is addprefix still needed?
> 
OK, should move to unnest-vars as well, it's here because I overlooked the line
in your next quesion, which makes that impossible.

> >  
> >  ifndef CONFIG_HAIKU
> >  LIBS+=-lm
> > diff --git a/configure b/configure
> > index e989609..cc3cd4d 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2251,6 +2251,7 @@ fi
> >  if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
> >  glib_cflags=`$pkg_config --cflags gthread-2.0`
> >  glib_libs=`$pkg_config --libs gthread-2.0`
> > +CFLAGS="$glib_cflags $CFLAGS"
> >  LIBS="$glib_libs $LIBS"
> >  libs_qga="$glib_libs $libs_qga"
> >  else
> > diff --git a/tests/Makefile b/tests/Makefile
> > index baba9e9..1b4048c 100644
> > --- a/tests/Makefile
> > +++ b/tests/Makefile
> > @@ -110,6 +110,8 @@ test-qapi-obj-y = tests/test-qapi-visit.o 
> > tests/test-qapi-types.o
> >  $(test-obj-y): QEMU_INCLUDES += -Itests
> >  QEMU_CFLAGS += -I$(SRC_PATH)/tests
> >  
> > +dummy := $(call unnest-vars,..,block-obj-y)
> > +
> 
> And why is this needed, since tests/Makefile is included from the top
> directory?
> 
Legacy. Seems OK to drop.

You are really suggesting towards the direction to clean code!

Thanks,

Fam
> 
> >  tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
> >  
> >  tests/check-qint$(EXESUF): tests/check-qint.o libqemuutil.a
> > 
> 



[Qemu-devel] qemu-img convert will increase the VM image

2013-09-11 Thread xuanmao_001
Hi, all:

I have question about qemu-img convert ...

I have a orignal image with following information:
# qemu-img info ori.qcow2   
image: ori.qcow2
file format: qcow2
virtual size: 2.0G (2097152000 bytes)
disk size: 308M
cluster_size: 65536

when I executed with "qemu-img convert -f qcow2 -O qcow2 ori.qcow2 new.qcow2"
the new.qcow2 like following:
# qemu-img info new.qcow2 
image: new.qcow2
file format: qcow2
virtual size: 2.0G (2097152000 bytes)
disk size: 748M
cluster_size: 65536

so, my question is why the image size increased after my operation?

thanks.




xuanmao_001

Re: [Qemu-devel] [PATCH v3 6/6] qemu-iotests: Additional info from qemu-img info

2013-09-11 Thread Max Reitz

On 2013-09-11 08:23, Fam Zheng wrote:

On Tue, 09/10 11:33, Max Reitz wrote:

Add a test for the additional information now provided by qemu-img info
when used on qcow2 images.

Signed-off-by: Max Reitz 
---
  tests/qemu-iotests/064 | 72 ++
  tests/qemu-iotests/064.out | 22 ++
  tests/qemu-iotests/group   |  1 +
  3 files changed, 95 insertions(+)
  create mode 100755 tests/qemu-iotests/064
  create mode 100644 tests/qemu-iotests/064.out

diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
new file mode 100755
index 000..4979db5
--- /dev/null
+++ b/tests/qemu-iotests/064
@@ -0,0 +1,72 @@
+#!/bin/bash
+#
+# Test for additional information emitted by qemu-img info on qcow2
+# images
+#
+# 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 .
+#
+
+# 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
+
+IMG_SIZE=64M
+
+echo
+echo "=== Testing qcow2 image with -o compat=0.10 ==="
+echo
+IMGOPTS="compat=0.10" _make_test_img $IMG_SIZE
+# don't use _img_info, since that function will filter out the
+# additional information we're about to test for
+$QEMU_IMG info "$TEST_IMG" | grep "Format specific information:" -A 42

For curiosity, where's 42 from?
I want to read all format specific information there, and because this 
is the last information emitted by qemu_img -info, I have to grep 
everything after the line "Format specific information:" until EOF – I 
didn't find an easy way to do this, so I just chose a number of lines 
which seemed enough to fetch all of that format specific info 
(currently, 2 would suffice).



Fam


+
+echo
+echo "=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=off ==="
+echo
+IMGOPTS="compat=1.1,lazy_refcounts=off" _make_test_img $IMG_SIZE
+$QEMU_IMG info "$TEST_IMG" | grep "Format specific information:" -A 42
+
+echo
+echo "=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=on ==="
+echo
+IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img $IMG_SIZE
+$QEMU_IMG info "$TEST_IMG" | grep "Format specific information:" -A 42
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
new file mode 100644
index 000..6ce5b43
--- /dev/null
+++ b/tests/qemu-iotests/064.out
@@ -0,0 +1,22 @@
+QA output created by 064
+
+=== Testing qcow2 image with -o compat=0.10 ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+Format specific information:
+compat: 0.10
+
+=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=off ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+Format specific information:
+compat: 1.1
+lazy refcounts: false
+
+=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=on ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+Format specific information:
+compat: 1.1
+lazy refcounts: true
+*** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index b696242..740cd84 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -66,3 +66,4 @@
  059 rw auto
  060 rw auto
  062 rw auto
+064 rw auto
--
1.8.3.1



Max



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 07:38, Fam Zheng ha scritto:
> The new option will enable support of shared object build. Otherwise
> objects are static linked to executables.
> 
> Signed-off-by: Fam Zheng 
> ---
>  Makefile.target | 6 +-
>  configure   | 8 
>  rules.mak   | 8 ++--
>  3 files changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 1d92523..beab0f9 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -152,7 +152,11 @@ obj-y-save := $(obj-y)
>  block-obj-y :=
>  common-obj-y :=
>  include $(SRC_PATH)/Makefile.objs
> -dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
> +dummy := $(call unnest-vars,.., \
> +   block-obj-y \
> +   block-obj-m \
> +   common-obj-y \
> +   common-obj-m)
>  
>  # Now restore obj-y
>  obj-y := $(obj-y-save)
> diff --git a/configure b/configure
> index a2858c2..f1d7fa7 100755
> --- a/configure
> +++ b/configure
> @@ -192,6 +192,7 @@ gcov_tool="gcov"
>  EXESUF=""
>  DSOSUF=".so"
>  LDFLAGS_SHARED="-shared"
> +modules="no"
>  prefix="/usr/local"
>  mandir="\${prefix}/share/man"
>  datadir="\${prefix}/share"
> @@ -650,6 +651,8 @@ for opt do
>;;
>--disable-debug-info)
>;;
> +  --enable-modules) modules="yes"
> +  ;;
>--cpu=*)
>;;
>--target-list=*) target_list="$optarg"
> @@ -1052,6 +1055,7 @@ echo "  --libdir=PATHinstall libraries in 
> PATH"
>  echo "  --sysconfdir=PATHinstall config in PATH$confsuffix"
>  echo "  --localstatedir=PATH install local state in PATH (set at runtime 
> on win32)"
>  echo "  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and 
> sysconfdir [$confsuffix]"
> +echo "  --enable-modules enable modules support"
>  echo "  --enable-debug-tcg   enable TCG debugging"
>  echo "  --disable-debug-tcg  disable TCG debugging (default)"
>  echo "  --enable-debug-info   enable debugging information (default)"
> @@ -3580,6 +3584,7 @@ echo "python$python"
>  if test "$slirp" = "yes" ; then
>  echo "smbd  $smbd"
>  fi
> +echo "module support$modules"
>  echo "host CPU  $cpu"
>  echo "host big endian   $bigendian"
>  echo "target list   $target_list"
> @@ -3697,6 +3702,9 @@ echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
>  
>  echo "ARCH=$ARCH" >> $config_host_mak
>  
> +if test "$modules" = "yes"; then
> +  echo "CONFIG_MODULES=y" >> $config_host_mak
> +fi
>  case "$cpu" in
>arm|i386|x86_64|x32|ppc|aarch64)
>  # The TCG interpreter currently does not support ld/st optimization.
> diff --git a/rules.mak b/rules.mak
> index ea97888..860b8ac 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -185,7 +185,11 @@ $(foreach var,$(nested-vars), $(eval \
>  $(foreach v,$(filter %-m,$(nested-vars)), \
>  $(call add-modules,$v))
>  
> -$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m)))
> -$(eval all: modules)
> +$(if $(CONFIG_MODULES), \
> +$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m))) \
> +$(eval all: modules), \

Since you'll have a v6, please move "all: modules" to Makefile, and in
rules.mak:

.PHONY: modules
modules:

There are a couple of things that can be improved still (I don't like
obj-save-y for example), but things are taking shape and all of this
looks like something that can be fixed on top.  If you look at
converting more parts to modules (e.g. rbd or spice), you can drop that
RFC! :)

Thanks,

Paolo

> +$(foreach v,$(filter %-m,$(nested-vars)), \
> +$(eval $(patsubst %-m,%-y,$v) += $($v)) \
> +$(eval $v := )))
>  
>  endef
> 




Re: [Qemu-devel] [RFC PATCH v5 6/6] block: build qed and curl as shared library

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 07:38, Fam Zheng ha scritto:
> Curl and qed block drivers are built as shared object module.  We have
> per object cflags and libs support now, move CURL_CFLAGS and CURL_LIBS
> from global option variables to a per object basis.
> 
> "make install" is not installing them yet, manually copy it to
> ${prefix}/qemu/block/ to make it loaded.
> 
> Signed-off-by: Fam Zheng 
> ---
>  block/Makefile.objs | 7 ---
>  configure   | 5 ++---
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/block/Makefile.objs b/block/Makefile.objs
> index 3bb85b5..741b92f 100644
> --- a/block/Makefile.objs
> +++ b/block/Makefile.objs
> @@ -1,7 +1,6 @@
>  block-obj-y += raw_bsd.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o 
> vpc.o vvfat.o
>  block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
> qcow2-cache.o
> -block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
> -block-obj-y += qed-check.o
> +block-obj-m += qed.mo

I suppose this is just an example of multifile module, as there's not
really any benefit in modularizing qed, right?

Paolo

>  block-obj-y += vhdx.o
>  block-obj-y += parallels.o blkdebug.o blkverify.o
>  block-obj-y += snapshot.o qapi.o
> @@ -23,4 +22,6 @@ common-obj-y += commit.o
>  common-obj-y += mirror.o
>  common-obj-y += backup.o
>  
> -$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS)
> +curl.o-cflags := $(CURL_CFLAGS)
> +curl.o-libs := $(CURL_LIBS)
> +qed.mo-objs := qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o 
> qed-check.o
> diff --git a/configure b/configure
> index f1d7fa7..f8be093 100755
> --- a/configure
> +++ b/configure
> @@ -2217,8 +2217,6 @@ EOF
>curl_libs=`$curlconfig --libs 2>/dev/null`
>if compile_prog "$curl_cflags" "$curl_libs" ; then
>  curl=yes
> -libs_tools="$curl_libs $libs_tools"
> -libs_softmmu="$curl_libs $libs_softmmu"
>else
>  if test "$curl" = "yes" ; then
>feature_not_found "curl"
> @@ -3901,8 +3899,9 @@ if test "$bswap_h" = "yes" ; then
>echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
>  fi
>  if test "$curl" = "yes" ; then
> -  echo "CONFIG_CURL=y" >> $config_host_mak
> +  echo "CONFIG_CURL=m" >> $config_host_mak
>echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
> +  echo "CURL_LIBS=$curl_libs" >> $config_host_mak
>  fi
>  if test "$brlapi" = "yes" ; then
>echo "CONFIG_BRLAPI=y" >> $config_host_mak
> 




Re: [Qemu-devel] [PATCH RFC 3/4] Curling: the sender

2013-09-11 Thread junqing . wang
hi,


>> +bool create = false;
> >This variable is never set.

It is set in the following 'if' block.
 +create = true;<<===

>> -migration_bitmap = bitmap_new(ram_pages);
>> -bitmap_set(migration_bitmap, 0, ram_pages);
>> -migration_dirty_pages = ram_pages;
>> +if (!ft_enabled() || !migration_bitmap)  {
>> +migration_bitmap = bitmap_new(ram_pages);
>> +bitmap_set(migration_bitmap, 0, ram_pages);
>> +migration_dirty_pages = ram_pages;
>> +create = true;   <==
>> +}

>Nothing in this patch sets the migration_bitmap to anything.

Let me explain all the odd 'if'  block:
1 >> +if (!ft_enabled() || !migration_bitmap)  {
2 >> +if (!ft_enabled() || create) {
3 >> +if (!ft_enabled()) {

As I mentioned in the commit log: 
>> We need to handle the variables related to live migration very
>> carefully. So the new migration does not restart from the very
>> begin of the migration, instead, it continues the previous
>> migration.

Some variables should not be reset after one migration, because
the next one need these variables to continue the migration.
This explains all the "if ft_enabled()"

Besides, some variables need to be initialized at the first migration of 
curling.
That explains the "if create" and "if  !migration_bitmap"

>> +if (ft_enabled()) {
>> +if (old_vm_running) {
>> +qemu_mutex_lock_iothread();
>> +vm_start();
>> +qemu_mutex_unlock_iothread();
>> +
>> +current_time = 
>> qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
>> +time_spent = current_time - migration_start_time;
>> +DPRINTF("this migration lasts for %" PRId64 "ms\n",
>> +time_spent);
>> +if (time_spent < time_window) {
>> +g_usleep((time_window - time_spent)*1000);
>
>Why are we waiting here?  If we are migration faster than allowed,  why
>we are waiting?

Looping fast is not good, that means we enter iothread lock and do vm stop more 
frequently. The performance will drop and vm user will experience input stall 
if we do not sleep.

How to deal with this is a difficult issue, any suggestion is welcomed.

THIS IS ONE OF THE TWO MAIN PROBLEMS.  The other one is related to the magic 
number 0xfeedcafe.




Re: [Qemu-devel] [PATCH V4 0/3] qemu-iotests: add test for fd passing via SCM rights

2013-09-11 Thread Kevin Wolf
Am 11.09.2013 um 04:38 hat Wenchao Xia geschrieben:
> 于 2013/9/10 19:47, Kevin Wolf 写道:
> >Am 09.09.2013 um 13:57 hat Stefan Hajnoczi geschrieben:
> >>On Fri, Sep 06, 2013 at 11:24:31AM +0800, Wenchao Xia wrote:
> >>>This series add test case for fd passing with unix socket at runtime. Since
> >>>getfd and closefd interface will interact with monitor's data, so it will
> >>>help to do regression test for monitor patches. Since python2 do not 
> >>>support
> >>>sendmsg(), so a C helper program is added to do the job.
> >>>
> >>>v2:
> >>>   1: add missing $ in the makefile rule.
> >>>
> >>>v3:
> >>>   Address Eric's comments:
> >>>   1: typo fix, remove "." in the end of error message, strick
> >>>check argc as "!=", use EXIT_SUCCESS and EXIT_FAILURE as exit
> >>>values, strict error check for strtol() call.
> >>>   Address Luiz's comments:
> >>>   1: change the helper program parameter as "bin<  socket-fd>  <  
> >>> file-path>",
> >>>the program open the file itself now, data parameter is removed and blank
> >>>is always used as iov data, better usage tip message, folder the string 
> >>>parsing
> >>>code into a function.
> >>>   2: related change for helper program parameter change.
> >>>   3: related change for helper program parameter change.
> >>>   Other:
> >>>   1: remove "LINK" rule in makefile, remove fd checking code inside 
> >>> send_fd()
> >>>since it is already checked before calling, add '' around %s for path and
> >>>number string in error message.
> >>>   2: renamed fd_bin to bin in send_fd_scm() to tip better, add '' around 
> >>> %s
> >>>for path in error message.
> >>>v4:
> >>>   Address Stefan's comments:
> >>>   2: add space after # for comments, refined the comment's grammar.
> >>>   3: add space after # for comments, refined the comment's grammar, add 
> >>> two
> >>>test cases for error path.
> >>>
> >>>Wenchao Xia (3):
> >>>   1 qemu-iotests: add unix socket help program
> >>>   2 qemu-iotests: add infrastructure of fd passing via SCM
> >>>   3 qemu-iotests: add tests for runtime fd passing via SCM rights
> >>>
> >>>  QMP/qmp.py |6 ++
> >>>  configure  |2 +-
> >>>  tests/Makefile |3 +-
> >>>  tests/qemu-iotests/045 |   51 -
> >>>  tests/qemu-iotests/045.out |4 +-
> >>>  tests/qemu-iotests/check   |1 +
> >>>  tests/qemu-iotests/iotests.py  |   23 ++
> >>>  tests/qemu-iotests/socket_scm_helper.c |  135 
> >>> 
> >>>  8 files changed, 220 insertions(+), 5 deletions(-)
> >>>  create mode 100644 tests/qemu-iotests/socket_scm_helper.c
> >>Reviewed-by: Stefan Hajnoczi
> >I'm not completely convinced that it's a good idea to introduce a helper
> >binary that isn't automatically rebuilt after an upgrade (I basically
> Indeed it will not be rebuilt when code for qemu change, but will be
> rebuilt when
> socket_scm_helper.c change. The help program have no connection with
> qemu's main code,
> so I think it is safe.
> The binaries built under tests/ will not be cleaned, so I think they
> all have a chance to
> stay as old version. If this is the issue you mean, I will send a
> patch clean them, which
> is what I planned to do sometimes ago . :)

The difference is that the binaries under tests/ will usually only ever
be called using 'make check', which does update them. In contrast, I
usually run qemu-iotests by directly executing check -T -nocache -qcow2,
which doesn't update anything.

Kevin

> >never run 'make check-block', which is the only way that would trigger
> >it), but given this Reviewed-by, I've applied this to the block branch.
> >
> >Kevin
> >
> 



Re: [Qemu-devel] [RFC PATCH v5 6/6] block: build qed and curl as shared library

2013-09-11 Thread Fam Zheng
On Wed, 09/11 09:28, Paolo Bonzini wrote:
> Il 11/09/2013 07:38, Fam Zheng ha scritto:
> > Curl and qed block drivers are built as shared object module.  We have
> > per object cflags and libs support now, move CURL_CFLAGS and CURL_LIBS
> > from global option variables to a per object basis.
> > 
> > "make install" is not installing them yet, manually copy it to
> > ${prefix}/qemu/block/ to make it loaded.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  block/Makefile.objs | 7 ---
> >  configure   | 5 ++---
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/block/Makefile.objs b/block/Makefile.objs
> > index 3bb85b5..741b92f 100644
> > --- a/block/Makefile.objs
> > +++ b/block/Makefile.objs
> > @@ -1,7 +1,6 @@
> >  block-obj-y += raw_bsd.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o 
> > vpc.o vvfat.o
> >  block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
> > qcow2-cache.o
> > -block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
> > -block-obj-y += qed-check.o
> > +block-obj-m += qed.mo
> 
> I suppose this is just an example of multifile module, as there's not
> really any benefit in modularizing qed, right?
> 

Right, the main reason for modules is the libs dependencies, curl, rbd, etc...
I'll try to convert such block drivers, but keep qed static, in v6.

Fam
> 
> >  block-obj-y += vhdx.o
> >  block-obj-y += parallels.o blkdebug.o blkverify.o
> >  block-obj-y += snapshot.o qapi.o
> > @@ -23,4 +22,6 @@ common-obj-y += commit.o
> >  common-obj-y += mirror.o
> >  common-obj-y += backup.o
> >  
> > -$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS)
> > +curl.o-cflags := $(CURL_CFLAGS)
> > +curl.o-libs := $(CURL_LIBS)
> > +qed.mo-objs := qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o 
> > qed-check.o
> > diff --git a/configure b/configure
> > index f1d7fa7..f8be093 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2217,8 +2217,6 @@ EOF
> >curl_libs=`$curlconfig --libs 2>/dev/null`
> >if compile_prog "$curl_cflags" "$curl_libs" ; then
> >  curl=yes
> > -libs_tools="$curl_libs $libs_tools"
> > -libs_softmmu="$curl_libs $libs_softmmu"
> >else
> >  if test "$curl" = "yes" ; then
> >feature_not_found "curl"
> > @@ -3901,8 +3899,9 @@ if test "$bswap_h" = "yes" ; then
> >echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
> >  fi
> >  if test "$curl" = "yes" ; then
> > -  echo "CONFIG_CURL=y" >> $config_host_mak
> > +  echo "CONFIG_CURL=m" >> $config_host_mak
> >echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
> > +  echo "CURL_LIBS=$curl_libs" >> $config_host_mak
> >  fi
> >  if test "$brlapi" = "yes" ; then
> >echo "CONFIG_BRLAPI=y" >> $config_host_mak
> > 
> 



Re: [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 07:38, Fam Zheng ha scritto:
> Added three types of modules:
> 
> typedef enum {
> MODULE_LOAD_BLOCK = 0,
> MODULE_LOAD_UI,
> MODULE_LOAD_NET,
> MODULE_LOAD_MAX,
> } module_load_type;

If you want to make spice into a module, you probably need also audio,
char and hw modules.

Paolo

> and their loading function:
> 
> void module_load(module_load_type).
> 
> which loads all ".so" files in a subdir under "${PREFIX}/qemu/", e.g.
> "/usr/lib/qemu/block". Modules of each type should be loaded before
> respective subsystem initialization code.
> 
> Requires gmodule-2.0 from glib.
> 
> Signed-off-by: Fam Zheng 
> ---
>  block.c   |  1 +
>  bsd-user/main.c   |  3 +++
>  configure | 22 -
>  include/qemu/module.h |  9 +
>  linux-user/main.c |  3 +++
>  scripts/create_config |  4 
>  util/module.c | 53 
> +++
>  vl.c  |  2 ++
>  8 files changed, 88 insertions(+), 9 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 26639e8..16ceaaf 100644
> --- a/block.c
> +++ b/block.c
> @@ -4008,6 +4008,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
>  
>  void bdrv_init(void)
>  {
> +module_load(MODULE_LOAD_BLOCK);
>  module_call_init(MODULE_INIT_BLOCK);
>  }
>  
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index f9246aa..6cb9e35 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -33,6 +33,7 @@
>  #include "tcg.h"
>  #include "qemu/timer.h"
>  #include "qemu/envlist.h"
> +#include "qemu/module.h"
>  
>  int singlestep;
>  #if defined(CONFIG_USE_GUEST_BASE)
> @@ -749,6 +750,8 @@ int main(int argc, char **argv)
>  if (argc <= 1)
>  usage();
>  
> +module_load(MODULE_LOAD_UI);
> +module_load(MODULE_LOAD_NET);
>  module_call_init(MODULE_INIT_QOM);
>  
>  if ((envlist = envlist_create()) == NULL) {
> diff --git a/configure b/configure
> index c6d4a62..a2858c2 100755
> --- a/configure
> +++ b/configure
> @@ -2252,15 +2252,19 @@ if test "$mingw32" = yes; then
>  else
>  glib_req_ver=2.12
>  fi
> -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
> -glib_cflags=`$pkg_config --cflags gthread-2.0`
> -glib_libs=`$pkg_config --libs gthread-2.0`
> -CFLAGS="$glib_cflags $CFLAGS"
> -LIBS="$glib_libs $LIBS"
> -libs_qga="$glib_libs $libs_qga"
> -else
> -error_exit "glib-$glib_req_ver required to compile QEMU"
> -fi
> +
> +for i in gthread-2.0 gmodule-2.0; do
> +if $pkg_config --atleast-version=$glib_req_ver $i; then
> +glib_cflags=`$pkg_config --cflags $i`
> +glib_libs=`$pkg_config --libs $i`
> +CFLAGS="$glib_cflags $CFLAGS"
> +LIBS="$glib_libs $LIBS"
> +libs_qga="$glib_libs $libs_qga"
> +else
> +error_exit "glib-$glib_req_ver required to compile QEMU"
> +fi
> +done
> +
>  
>  ##
>  # pixman support probe
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index c4ccd57..f00bc25 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -37,4 +37,13 @@ void register_module_init(void (*fn)(void), 
> module_init_type type);
>  
>  void module_call_init(module_init_type type);
>  
> +typedef enum {
> +MODULE_LOAD_BLOCK = 0,
> +MODULE_LOAD_UI,
> +MODULE_LOAD_NET,
> +MODULE_LOAD_MAX,
> +} module_load_type;
> +
> +void module_load(module_load_type type);
> +
>  #endif
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 5c2f7b2..db08c23 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -34,6 +34,7 @@
>  #include "qemu/timer.h"
>  #include "qemu/envlist.h"
>  #include "elf.h"
> +#include 
>  
>  char *exec_path;
>  
> @@ -3551,6 +3552,8 @@ int main(int argc, char **argv, char **envp)
>  int i;
>  int ret;
>  
> +module_load(MODULE_LOAD_UI);
> +module_load(MODULE_LOAD_NET);
>  module_call_init(MODULE_INIT_QOM);
>  
>  qemu_cache_utils_init(envp);
> diff --git a/scripts/create_config b/scripts/create_config
> index b1adbf5..7a54f2d 100755
> --- a/scripts/create_config
> +++ b/scripts/create_config
> @@ -25,6 +25,7 @@ case $line in
>   prefix=*)
>  # save for the next definitions
>  prefix=${line#*=}
> +echo "#define CONFIG_PREFIX \"$prefix\""
>  ;;
>   CONFIG_AUDIO_DRIVERS=*)
>  drivers=${line#*=}
> @@ -104,6 +105,9 @@ case $line in
>  value=${line#*=}
>  echo "#define $name $value"
>  ;;
> + DSOSUF=*)
> +echo "#define HOST_DSOSUF \"${line#*=}\""
> +;;
>  esac
>  
>  done # read
> diff --git a/util/module.c b/util/module.c
> index 7acc33d..ef75f8e 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -13,6 +13,8 @@
>   * GNU GPL, version 2 or (at your option) any later version.
>   */
>  
> +#include 
> +#include 
>  #include "qemu-common.h"
>  #include "qemu/queue.h"
>  #include "qemu/module.h"
> @@ -79,3 +81,54 @@ void module_

Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 09:27, Paolo Bonzini ha scritto:
> 
> There are a couple of things that can be improved still (I don't like
> obj-save-y for example), but things are taking shape and all of this
> looks like something that can be fixed on top.  If you look at
> converting more parts to modules (e.g. rbd or spice), you can drop that
> RFC! :)

Talking about spice, a question for Gerd.

With Fam's work to enable shared modules, hw/display/qxl* would have to
be placed in a module as well because they depend on ui/spice-core.c.
Right now, modularization is limited to files that are built once for
all of QEMU, which is not the case for qxl.

It looks like TARGET_PAGE_SIZE is the only reason why qxl is built
per-target, and in qxl_ram_set_dirty it should be enough to do

qxl_set_dirty(&qxl->vga.vram, offset, offset + 1);

Would it be fine to use a generic 4096 constant everywhere else?

Paolo



Re: [Qemu-devel] [PATCH v3 6/6] qemu-iotests: Additional info from qemu-img info

2013-09-11 Thread Fam Zheng
On Wed, 09/11 09:26, Max Reitz wrote:
> On 2013-09-11 08:23, Fam Zheng wrote:
> >On Tue, 09/10 11:33, Max Reitz wrote:
> >>Add a test for the additional information now provided by qemu-img info
> >>when used on qcow2 images.
> >>
> >>Signed-off-by: Max Reitz 
> >>---
> >>  tests/qemu-iotests/064 | 72 
> >> ++
> >>  tests/qemu-iotests/064.out | 22 ++
> >>  tests/qemu-iotests/group   |  1 +
> >>  3 files changed, 95 insertions(+)
> >>  create mode 100755 tests/qemu-iotests/064
> >>  create mode 100644 tests/qemu-iotests/064.out
> >>
> >>diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
> >>new file mode 100755
> >>index 000..4979db5
> >>--- /dev/null
> >>+++ b/tests/qemu-iotests/064
> >>@@ -0,0 +1,72 @@
> >>+#!/bin/bash
> >>+#
> >>+# Test for additional information emitted by qemu-img info on qcow2
> >>+# images
> >>+#
> >>+# 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 .
> >>+#
> >>+
> >>+# 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
> >>+
> >>+IMG_SIZE=64M
> >>+
> >>+echo
> >>+echo "=== Testing qcow2 image with -o compat=0.10 ==="
> >>+echo
> >>+IMGOPTS="compat=0.10" _make_test_img $IMG_SIZE
> >>+# don't use _img_info, since that function will filter out the
> >>+# additional information we're about to test for
> >>+$QEMU_IMG info "$TEST_IMG" | grep "Format specific information:" -A 42
> >For curiosity, where's 42 from?
> I want to read all format specific information there, and because
> this is the last information emitted by qemu_img -info, I have to
> grep everything after the line "Format specific information:" until
> EOF – I didn't find an easy way to do this, so I just chose a number
> of lines which seemed enough to fetch all of that format specific
> info (currently, 2 would suffice).
> 
Maybe
$QEMU_IMG info "$TEST_IMG" | sed -n 'Format specific information:/,$ p'
?

Fam



[Qemu-devel] [PATCH] qdev: rename qdev_free() to qdev_unparent()

2013-09-11 Thread Stefan Hajnoczi
The qdev_free() function name is misleading since all the function does
is unlink the device from its parent.  The device is not necessarily
freed.

The device will be freed when its QObject refcount reaches zero.  It is
usual for the parent (bus) to hold the final reference but there are
cases where something else holds a reference so "free" is a misleading
name.

I opted to keep a qdev wrapper function instead of making all callers
use object_unparent(OBJECT(qdev)) directly due to the slightly ugly
cast.

Signed-off-by: Stefan Hajnoczi 
---
This patch is based on the "[PATCH 0/6] qdev and blockdev refcount leak fixes"
series that I sent yesterday.

 hw/acpi/piix4.c  |  2 +-
 hw/core/qdev.c   | 10 +-
 hw/pci/pci-hotplug-old.c |  2 +-
 hw/pci/pci_bridge.c  |  2 +-
 hw/pci/pcie.c|  2 +-
 hw/pci/shpc.c|  2 +-
 hw/s390x/virtio-ccw.c|  2 +-
 hw/scsi/scsi-bus.c   |  6 +++---
 hw/usb/bus.c |  4 ++--
 hw/usb/dev-storage.c |  2 +-
 hw/usb/host-legacy.c |  2 +-
 hw/virtio/virtio-bus.c   |  2 +-
 hw/xen/xen_platform.c|  2 +-
 include/hw/qdev-core.h   |  2 +-
 qdev-monitor.c   |  2 +-
 15 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 0b8d1d9..2ec9ada 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -326,7 +326,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned 
slots)
 if (pc->no_hotplug) {
 slot_free = false;
 } else {
-qdev_free(qdev);
+qdev_unparent(qdev);
 }
 }
 }
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 533f6dd..ac2352b 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
 if (local_err != NULL) {
 qerror_report_err(local_err);
 error_free(local_err);
-qdev_free(dev);
+qdev_unparent(dev);
 return -1;
 }
 return 0;
@@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
 int qdev_simple_unplug_cb(DeviceState *dev)
 {
 /* just zap it */
-qdev_free(dev);
+qdev_unparent(dev);
 return 0;
 }
 
@@ -280,8 +280,8 @@ void qdev_init_nofail(DeviceState *dev)
 }
 }
 
-/* Unlink device from bus and free the structure.  */
-void qdev_free(DeviceState *dev)
+/* Unlink device from bus.  dev is freed if refcount reaches zero. */
+void qdev_unparent(DeviceState *dev)
 {
 object_unparent(OBJECT(dev));
 }
@@ -458,7 +458,7 @@ static void bus_unparent(Object *obj)
 
 while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
 DeviceState *dev = kid->child;
-qdev_free(dev);
+qdev_unparent(dev);
 }
 if (bus->parent) {
 QLIST_REMOVE(bus, sibling);
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 619fe47..f197f5f 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 }
 dev = pci_create(bus, devfn, "virtio-blk-pci");
 if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-qdev_free(&dev->qdev);
+qdev_unparent(&dev->qdev);
 dev = NULL;
 break;
 }
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index e6b22b8..68e0bcb 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -391,7 +391,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
 pci_bridge_region_cleanup(s, s->windows);
 memory_region_destroy(&s->address_space_mem);
 memory_region_destroy(&s->address_space_io);
-/* qbus_free() is called automatically by qdev_free() */
+/* qbus_free() is called automatically by qdev_unparent() */
 }
 
 /*
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 50af3c1..edd3f40 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
PCI_EXP_SLTSTA_PDS);
 pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
 } else {
-qdev_free(&pci_dev->qdev);
+qdev_unparent(&pci_dev->qdev);
 pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
  PCI_EXP_SLTSTA_PDS);
 pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index eb092fd..5ba2b17 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -254,7 +254,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int 
slot)
  ++devfn) {
 PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
 if (affected_dev) {
-qdev_free(&affected_dev->qdev);
+qdev_unparent(&affected_dev->qdev);
 }
 }
 }
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index cd67db5..249a0ec 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1239,7 +1239,7 @@ static int virtio_ccw_busdev_unplug(DeviceState *dev)

Re: [Qemu-devel] [PATCH] qdev: rename qdev_free() to qdev_unparent()

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 09:45, Stefan Hajnoczi ha scritto:
> The qdev_free() function name is misleading since all the function does
> is unlink the device from its parent.  The device is not necessarily
> freed.
> 
> The device will be freed when its QObject refcount reaches zero.  It is
> usual for the parent (bus) to hold the final reference but there are
> cases where something else holds a reference so "free" is a misleading
> name.
> 
> I opted to keep a qdev wrapper function instead of making all callers
> use object_unparent(OBJECT(qdev)) directly due to the slightly ugly
> cast.
> 
> Signed-off-by: Stefan Hajnoczi 
> ---
> This patch is based on the "[PATCH 0/6] qdev and blockdev refcount leak fixes"
> series that I sent yesterday.
> 
>  hw/acpi/piix4.c  |  2 +-
>  hw/core/qdev.c   | 10 +-
>  hw/pci/pci-hotplug-old.c |  2 +-
>  hw/pci/pci_bridge.c  |  2 +-
>  hw/pci/pcie.c|  2 +-
>  hw/pci/shpc.c|  2 +-
>  hw/s390x/virtio-ccw.c|  2 +-
>  hw/scsi/scsi-bus.c   |  6 +++---
>  hw/usb/bus.c |  4 ++--
>  hw/usb/dev-storage.c |  2 +-
>  hw/usb/host-legacy.c |  2 +-
>  hw/virtio/virtio-bus.c   |  2 +-
>  hw/xen/xen_platform.c|  2 +-
>  include/hw/qdev-core.h   |  2 +-
>  qdev-monitor.c   |  2 +-
>  15 files changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 0b8d1d9..2ec9ada 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -326,7 +326,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, 
> unsigned slots)
>  if (pc->no_hotplug) {
>  slot_free = false;
>  } else {
> -qdev_free(qdev);
> +qdev_unparent(qdev);
>  }
>  }
>  }
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 533f6dd..ac2352b 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
>  if (local_err != NULL) {
>  qerror_report_err(local_err);
>  error_free(local_err);
> -qdev_free(dev);
> +qdev_unparent(dev);
>  return -1;
>  }
>  return 0;
> @@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
>  int qdev_simple_unplug_cb(DeviceState *dev)
>  {
>  /* just zap it */
> -qdev_free(dev);
> +qdev_unparent(dev);
>  return 0;
>  }
>  
> @@ -280,8 +280,8 @@ void qdev_init_nofail(DeviceState *dev)
>  }
>  }
>  
> -/* Unlink device from bus and free the structure.  */
> -void qdev_free(DeviceState *dev)
> +/* Unlink device from bus.  dev is freed if refcount reaches zero. */
> +void qdev_unparent(DeviceState *dev)
>  {
>  object_unparent(OBJECT(dev));
>  }
> @@ -458,7 +458,7 @@ static void bus_unparent(Object *obj)
>  
>  while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
>  DeviceState *dev = kid->child;
> -qdev_free(dev);
> +qdev_unparent(dev);
>  }
>  if (bus->parent) {
>  QLIST_REMOVE(bus, sibling);
> diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
> index 619fe47..f197f5f 100644
> --- a/hw/pci/pci-hotplug-old.c
> +++ b/hw/pci/pci-hotplug-old.c
> @@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
>  }
>  dev = pci_create(bus, devfn, "virtio-blk-pci");
>  if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
> -qdev_free(&dev->qdev);
> +qdev_unparent(&dev->qdev);
>  dev = NULL;
>  break;
>  }
> diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
> index e6b22b8..68e0bcb 100644
> --- a/hw/pci/pci_bridge.c
> +++ b/hw/pci/pci_bridge.c
> @@ -391,7 +391,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
>  pci_bridge_region_cleanup(s, s->windows);
>  memory_region_destroy(&s->address_space_mem);
>  memory_region_destroy(&s->address_space_io);
> -/* qbus_free() is called automatically by qdev_free() */
> +/* qbus_free() is called automatically by qdev_unparent() */
>  }
>  
>  /*
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 50af3c1..edd3f40 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
> PCI_EXP_SLTSTA_PDS);
>  pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
>  } else {
> -qdev_free(&pci_dev->qdev);
> +qdev_unparent(&pci_dev->qdev);
>  pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
>   PCI_EXP_SLTSTA_PDS);
>  pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index eb092fd..5ba2b17 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -254,7 +254,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, 
> int slot)
>   ++devfn) {
>  PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
>  if (affected_dev) {
> - 

Re: [Qemu-devel] [PATCH v3 6/6] qemu-iotests: Additional info from qemu-img info

2013-09-11 Thread Max Reitz

On 2013-09-11 09:44, Fam Zheng wrote:

On Wed, 09/11 09:26, Max Reitz wrote:

On 2013-09-11 08:23, Fam Zheng wrote:

On Tue, 09/10 11:33, Max Reitz wrote:

Add a test for the additional information now provided by qemu-img info
when used on qcow2 images.

Signed-off-by: Max Reitz 
---
  tests/qemu-iotests/064 | 72 ++
  tests/qemu-iotests/064.out | 22 ++
  tests/qemu-iotests/group   |  1 +
  3 files changed, 95 insertions(+)
  create mode 100755 tests/qemu-iotests/064
  create mode 100644 tests/qemu-iotests/064.out

diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
new file mode 100755
index 000..4979db5
--- /dev/null
+++ b/tests/qemu-iotests/064
@@ -0,0 +1,72 @@
+#!/bin/bash
+#
+# Test for additional information emitted by qemu-img info on qcow2
+# images
+#
+# 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 .
+#
+
+# 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
+
+IMG_SIZE=64M
+
+echo
+echo "=== Testing qcow2 image with -o compat=0.10 ==="
+echo
+IMGOPTS="compat=0.10" _make_test_img $IMG_SIZE
+# don't use _img_info, since that function will filter out the
+# additional information we're about to test for
+$QEMU_IMG info "$TEST_IMG" | grep "Format specific information:" -A 42

For curiosity, where's 42 from?

I want to read all format specific information there, and because
this is the last information emitted by qemu_img -info, I have to
grep everything after the line "Format specific information:" until
EOF – I didn't find an easy way to do this, so I just chose a number
of lines which seemed enough to fetch all of that format specific
info (currently, 2 would suffice).


Maybe
 $QEMU_IMG info "$TEST_IMG" | sed -n 'Format specific information:/,$ p'
?

Fam
Hm, yes, with a slash up front ('/Format specific information:/,$p') it 
works, I'll use that, then. Thanks.


Max



[Qemu-devel] [PATCH v4 3/6] block/qapi: Human-readable ImageInfoSpecific dump

2013-09-11 Thread Max Reitz
Add a function for generically dumping the ImageInfoSpecific information
in a human-readable format to block/qapi.c.

Use this function in bdrv_image_info_dump and qemu-io-cmds.c:info_f to
allow qemu-img info resp. qemu-io -c info to print that format specific
information.

Signed-off-by: Max Reitz 
---
 block/qapi.c | 121 +++
 include/block/qapi.h |   2 +
 qemu-io-cmds.c   |   6 +++
 3 files changed, 129 insertions(+)

diff --git a/block/qapi.c b/block/qapi.c
index 738469a..dbf1e7b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -25,6 +25,9 @@
 #include "block/qapi.h"
 #include "block/block_int.h"
 #include "qmp-commands.h"
+#include "qapi-visit.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp/types.h"
 
 /*
  * Returns 0 on success, with *p_list either set to describe snapshot
@@ -427,6 +430,119 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf, 
void *f,
 }
 }
 
+static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
+   QDict *dict);
+static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
+   QList *list);
+
+static void dump_qobject(fprintf_function func_fprintf, void *f,
+ int comp_indent, QObject *obj)
+{
+switch (qobject_type(obj)) {
+case QTYPE_QINT: {
+QInt *value = qobject_to_qint(obj);
+func_fprintf(f, "%" PRId64, qint_get_int(value));
+break;
+}
+case QTYPE_QSTRING: {
+QString *value = qobject_to_qstring(obj);
+func_fprintf(f, "%s", qstring_get_str(value));
+break;
+}
+case QTYPE_QDICT: {
+QDict *value = qobject_to_qdict(obj);
+dump_qdict(func_fprintf, f, comp_indent, value);
+break;
+}
+case QTYPE_QLIST: {
+QList *value = qobject_to_qlist(obj);
+dump_qlist(func_fprintf, f, comp_indent, value);
+break;
+}
+case QTYPE_QFLOAT: {
+QFloat *value = qobject_to_qfloat(obj);
+func_fprintf(f, "%g", qfloat_get_double(value));
+break;
+}
+case QTYPE_QBOOL: {
+QBool *value = qobject_to_qbool(obj);
+func_fprintf(f, "%s", qbool_get_int(value) ? "true" : "false");
+break;
+}
+case QTYPE_QERROR: {
+QString *value = qerror_human((QError *)obj);
+func_fprintf(f, "%s", qstring_get_str(value));
+break;
+}
+case QTYPE_NONE:
+break;
+case QTYPE_MAX:
+default:
+abort();
+}
+}
+
+static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
+   QList *list)
+{
+const QListEntry *entry;
+int i = 0;
+
+for (entry = qlist_first(list); entry; entry = qlist_next(entry), i++) {
+qtype_code type = qobject_type(entry->value);
+bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
+const char *format = composite ? "%*s[%i]:\n" : "%*s[%i]: ";
+
+func_fprintf(f, format, indentation * 4, "", i);
+dump_qobject(func_fprintf, f, indentation + 1, entry->value);
+if (!composite) {
+func_fprintf(f, "\n");
+}
+}
+}
+
+static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
+   QDict *dict)
+{
+const QDictEntry *entry;
+
+for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) {
+qtype_code type = qobject_type(entry->value);
+bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
+const char *format = composite ? "%*s%s:\n" : "%*s%s: ";
+char key[strlen(entry->key) + 1];
+int i;
+
+/* replace dashes with spaces in key (variable) names */
+for (i = 0; entry->key[i]; i++) {
+key[i] = entry->key[i] == '-' ? ' ' : entry->key[i];
+}
+key[i] = 0;
+
+func_fprintf(f, format, indentation * 4, "", key);
+dump_qobject(func_fprintf, f, indentation + 1, entry->value);
+if (!composite) {
+func_fprintf(f, "\n");
+}
+}
+}
+
+void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
+   ImageInfoSpecific *info_spec)
+{
+Error *local_err = NULL;
+QmpOutputVisitor *ov = qmp_output_visitor_new();
+QObject *obj, *data;
+
+visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), &info_spec, NULL,
+ &local_err);
+obj = qmp_output_get_qobject(ov);
+assert(qobject_type(obj) == QTYPE_QDICT);
+data = qdict_get(qobject_to_qdict(obj), "data");
+dump_qobject(func_fprintf, f, 0, data);
+qmp_output_visitor_cleanup(ov);
+}
+
 void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
  

[Qemu-devel] [PATCH v4 0/6] Provide additional info through qemu-img info

2013-09-11 Thread Max Reitz
qemu-img info provides only pretty general information about an image.
For any image format, there might be specific options which cannot be
represented in a universal way; for instance, qcow2 provides the
compatibility and lazy_refcount options whose values are certainly
interesting but currently cannot be output by qemu-img info.

Therefore, this series adds a new ImageInfoSpecific union type to
ImageInfo and BlockDriverInfo which may be used by block drivers as a
template for new types dedicated to the specific information they can
provide. It also adds support to qemu-img info and qemu-io -c info to
print the content of these specific structures.

v4:
 - changed dirty "grep -A 42" for grepping all lines until EOF in test
   064 to cleaner "sed -n '//,$p'" (patch 6)
 - rebased on Kevin's block branch (affects line numbers in patches 2, 3
   and 4 as well as the group file change in patch 6)

v3:
 - implemented Fam's remarks:
   - bdrv_get_info already initializes all fields to NULL, no need to do
 this manually (patch 2)
   - implemented bdrv_put_info as a wrapper to
 qapi_free_ImageInfoSpecific, though this may change with further
 extensions to BlockDriverInfo (patch 2)
   - changed one occurence of puts("foo") to printf("foo\n") in order to
 be consistent with the surrounding code (patch 3)
   - other patches (1, 4, 5, 6) remain unmodified

v2:
 - following Eric's recommendation: changed the representation of the
   format specific information from an uninterpreted blobbed string to a
   union of format specific types

Max Reitz (6):
  qapi: Add ImageInfoSpecific type
  block: Add ImageInfoSpecific to BlockDriverInfo
  block/qapi: Human-readable ImageInfoSpecific dump
  qcow2: Add support for ImageInfoSpecific
  qemu-iotests: Discard specific info in _img_info
  qemu-iotests: Additional info from qemu-img info

 block.c  |  16 +-
 block/mirror.c   |  16 --
 block/qapi.c | 125 +++
 block/qcow2.c|  12 +
 include/block/block.h|   3 ++
 include/block/qapi.h |   2 +
 qapi-schema.json |  34 +++-
 qemu-img.c   |   1 +
 qemu-io-cmds.c   |   8 +++
 tests/qemu-iotests/064   |  72 +
 tests/qemu-iotests/064.out   |  22 
 tests/qemu-iotests/common.rc |  19 ++-
 tests/qemu-iotests/group |   1 +
 13 files changed, 323 insertions(+), 8 deletions(-)
 create mode 100755 tests/qemu-iotests/064
 create mode 100644 tests/qemu-iotests/064.out

-- 
1.8.3.1




[Qemu-devel] [PATCH v4 1/6] qapi: Add ImageInfoSpecific type

2013-09-11 Thread Max Reitz
Add a new type ImageInfoSpecific as a union for image format specific
information in ImageInfo.

Signed-off-by: Max Reitz 
---
 qapi-schema.json | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 2b2c8bc..d4c63d9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -210,6 +210,18 @@
 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } }
 
 ##
+# @ImageInfoSpecific:
+#
+# A discriminated record of image format specific information structures.
+#
+# Since: 1.7
+##
+
+{ 'union': 'ImageInfoSpecific',
+  'data': {
+  } }
+
+##
 # @ImageInfo:
 #
 # Information about a QEMU image file
@@ -238,6 +250,9 @@
 #
 # @backing-image: #optional info of the backing image (since 1.6)
 #
+# @info-string: #optional string supplying additional format-specific
+# information (since 1.7)
+#
 # Since: 1.3
 #
 ##
@@ -248,7 +263,8 @@
'*cluster-size': 'int', '*encrypted': 'bool',
'*backing-filename': 'str', '*full-backing-filename': 'str',
'*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'],
-   '*backing-image': 'ImageInfo' } }
+   '*backing-image': 'ImageInfo',
+   '*format-specific': 'ImageInfoSpecific' } }
 
 ##
 # @ImageCheck:
-- 
1.8.3.1




[Qemu-devel] [PATCH v4 6/6] qemu-iotests: Additional info from qemu-img info

2013-09-11 Thread Max Reitz
Add a test for the additional information now provided by qemu-img info
when used on qcow2 images.

Signed-off-by: Max Reitz 
---
 tests/qemu-iotests/064 | 72 ++
 tests/qemu-iotests/064.out | 22 ++
 tests/qemu-iotests/group   |  1 +
 3 files changed, 95 insertions(+)
 create mode 100755 tests/qemu-iotests/064
 create mode 100644 tests/qemu-iotests/064.out

diff --git a/tests/qemu-iotests/064 b/tests/qemu-iotests/064
new file mode 100755
index 000..5c56b56
--- /dev/null
+++ b/tests/qemu-iotests/064
@@ -0,0 +1,72 @@
+#!/bin/bash
+#
+# Test for additional information emitted by qemu-img info on qcow2
+# images
+#
+# 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 .
+#
+
+# 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
+
+IMG_SIZE=64M
+
+echo
+echo "=== Testing qcow2 image with -o compat=0.10 ==="
+echo
+IMGOPTS="compat=0.10" _make_test_img $IMG_SIZE
+# don't use _img_info, since that function will filter out the
+# additional information we're about to test for
+$QEMU_IMG info "$TEST_IMG" | sed -n '/^Format specific information:$/,$p'
+
+echo
+echo "=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=off ==="
+echo
+IMGOPTS="compat=1.1,lazy_refcounts=off" _make_test_img $IMG_SIZE
+$QEMU_IMG info "$TEST_IMG" | sed -n '/^Format specific information:$/,$p'
+
+echo
+echo "=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=on ==="
+echo
+IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img $IMG_SIZE
+$QEMU_IMG info "$TEST_IMG" | sed -n '/^Format specific information:$/,$p'
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/064.out b/tests/qemu-iotests/064.out
new file mode 100644
index 000..6ce5b43
--- /dev/null
+++ b/tests/qemu-iotests/064.out
@@ -0,0 +1,22 @@
+QA output created by 064
+
+=== Testing qcow2 image with -o compat=0.10 ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
+Format specific information:
+compat: 0.10
+
+=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=off ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
+Format specific information:
+compat: 1.1
+lazy refcounts: false
+
+=== Testing qcow2 image with -o compat=1.1,lazy_refcounts=on ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
+Format specific information:
+compat: 1.1
+lazy refcounts: true
+*** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 8012828..49e6d8a 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -68,3 +68,4 @@
 061 rw auto
 062 rw auto
 063 rw auto
+064 rw auto
-- 
1.8.3.1




[Qemu-devel] [PATCH v4 5/6] qemu-iotests: Discard specific info in _img_info

2013-09-11 Thread Max Reitz
In _img_info, filter out additional information specific to the image
format provided by qemu-img info, since tests designed for multiple
image formats would produce different outputs for every image format
else.

Signed-off-by: Max Reitz 
---
 tests/qemu-iotests/common.rc | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 88fecf7..7f68321 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -181,12 +181,29 @@ _check_test_img()
 
 _img_info()
 {
+discard=0
 $QEMU_IMG info "$@" $TEST_IMG 2>&1 | \
 sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
 -e "s#$TEST_DIR#TEST_DIR#g" \
 -e "s#$IMGFMT#IMGFMT#g" \
 -e "/^disk size:/ D" \
--e "/actual-size/ D"
+-e "/actual-size/ D" | \
+while IFS='' read line; do
+if [ "$line" == "Format specific information:" ]; then
+discard=1
+elif [ "`echo "$line" | sed -e 's/^ *//'`" == '"format-specific": 
{' ]; then
+discard=2
+json_indent="`echo "$line" | sed -e 's/^\( *\).*$/\1/'`"
+fi
+if [ $discard == 0 ]; then
+echo "$line"
+elif [ $discard == 1 -a -z "$line" ]; then
+echo
+discard=0
+elif [ $discard == 2 -a "`echo "$line" | sed -e 's/ *$//'`" == 
"${json_indent}}," ]; then
+discard=0
+fi
+done
 }
 
 _get_pids_by_name()
-- 
1.8.3.1




[Qemu-devel] [PATCH v4 4/6] qcow2: Add support for ImageInfoSpecific

2013-09-11 Thread Max Reitz
Add a new ImageInfoSpecificQCow2 type as a subtype of ImageInfoSpecific.
This contains the compatibility level as a string and an optional
lazy_refcounts boolean (optional means mandatory for compat >= 1.1 and
not available for compat == 0.10).

In qcow2_get_info, fill the BlockDriverInfo.format_specific field with
that information.

Signed-off-by: Max Reitz 
---
 block/qcow2.c| 12 
 qapi-schema.json | 16 
 2 files changed, 28 insertions(+)

diff --git a/block/qcow2.c b/block/qcow2.c
index 7c9354c..6bc59c0 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1761,8 +1761,20 @@ static coroutine_fn int 
qcow2_co_flush_to_os(BlockDriverState *bs)
 static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 {
 BDRVQcowState *s = bs->opaque;
+
 bdi->cluster_size = s->cluster_size;
 bdi->vm_state_offset = qcow2_vm_state_offset(s);
+
+bdi->format_specific = g_new0(ImageInfoSpecific, 1);
+bdi->format_specific->kind = IMAGE_INFO_SPECIFIC_KIND_QCOW2;
+bdi->format_specific->qcow2 = g_new0(ImageInfoSpecificQCow2, 1);
+if (s->qcow_version == 2) {
+bdi->format_specific->qcow2->compat = g_strdup("0.10");
+} else if (s->qcow_version == 3) {
+bdi->format_specific->qcow2->compat = g_strdup("1.1");
+bdi->format_specific->qcow2->lazy_refcounts = s->use_lazy_refcounts;
+bdi->format_specific->qcow2->has_lazy_refcounts = true;
+}
 return 0;
 }
 
diff --git a/qapi-schema.json b/qapi-schema.json
index d4c63d9..6de32ea 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -210,6 +210,21 @@
 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } }
 
 ##
+# @ImageInfoSpecificQCow2:
+#
+# @compat: compatibility level
+#
+# @lazy-refcounts: #optional on or off; only valid for compat >= 1.1
+#
+# Since: 1.7
+##
+{ 'type': 'ImageInfoSpecificQCow2',
+  'data': {
+  'compat': 'str',
+  '*lazy-refcounts': 'bool'
+  } }
+
+##
 # @ImageInfoSpecific:
 #
 # A discriminated record of image format specific information structures.
@@ -219,6 +234,7 @@
 
 { 'union': 'ImageInfoSpecific',
   'data': {
+  'qcow2': 'ImageInfoSpecificQCow2'
   } }
 
 ##
-- 
1.8.3.1




[Qemu-devel] [PATCH v4 2/6] block: Add ImageInfoSpecific to BlockDriverInfo

2013-09-11 Thread Max Reitz
Add the new ImageInfoSpecific type also to BlockDriverInfo, as well as a
bdrv_put_info function which releases all data allocated by
bdrv_get_info from BlockDriverInfo (such as the new ImageInfoSpecific
field).

To prevent memory leaks, bdrv_put_info has to be called on every
BlockDriverInfo object when it is no longer required (and bdrv_get_info
has been successful).

Signed-off-by: Max Reitz 
---
 block.c   | 16 +++-
 block/mirror.c| 16 +++-
 block/qapi.c  |  4 
 include/block/block.h |  3 +++
 qemu-img.c|  1 +
 qemu-io-cmds.c|  2 ++
 6 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index b81d1e2..604bef0 100644
--- a/block.c
+++ b/block.c
@@ -1953,8 +1953,10 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
 int *cluster_nb_sectors)
 {
 BlockDriverInfo bdi;
+int ret;
 
-if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size == 0) {
+ret = bdrv_get_info(bs, &bdi);
+if (ret < 0 || bdi.cluster_size == 0) {
 *cluster_sector_num = sector_num;
 *cluster_nb_sectors = nb_sectors;
 } else {
@@ -1963,6 +1965,9 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
 *cluster_nb_sectors = QEMU_ALIGN_UP(sector_num - *cluster_sector_num +
 nb_sectors, c);
 }
+if (ret >= 0) {
+bdrv_put_info(bs, &bdi);
+}
 }
 
 static bool tracked_request_overlaps(BdrvTrackedRequest *req,
@@ -3281,6 +3286,15 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo 
*bdi)
 return drv->bdrv_get_info(bs, bdi);
 }
 
+/**
+ * Releases all data which has been allocated through bdrv_get_info. This
+ * function should be called if and only if bdrv_get_info was successful.
+ */
+void bdrv_put_info(BlockDriverState *bs, BlockDriverInfo *bdi)
+{
+qapi_free_ImageInfoSpecific(bdi->format_specific);
+}
+
 int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
   int64_t pos, int size)
 {
diff --git a/block/mirror.c b/block/mirror.c
index f61a779..7d3eb29 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -320,10 +320,12 @@ static void coroutine_fn mirror_run(void *opaque)
 bdrv_get_backing_filename(s->target, backing_filename,
   sizeof(backing_filename));
 if (backing_filename[0] && !s->target->backing_hd) {
-bdrv_get_info(s->target, &bdi);
-if (s->granularity < bdi.cluster_size) {
-s->buf_size = MAX(s->buf_size, bdi.cluster_size);
-s->cow_bitmap = bitmap_new(length);
+if (bdrv_get_info(s->target, &bdi) >= 0) {
+if (s->granularity < bdi.cluster_size) {
+s->buf_size = MAX(s->buf_size, bdi.cluster_size);
+s->cow_bitmap = bitmap_new(length);
+}
+bdrv_put_info(s->target, &bdi);
 }
 }
 
@@ -545,12 +547,16 @@ void mirror_start(BlockDriverState *bs, BlockDriverState 
*target,
 /* Choose the default granularity based on the target file's cluster
  * size, clamped between 4k and 64k.  */
 BlockDriverInfo bdi;
-if (bdrv_get_info(target, &bdi) >= 0 && bdi.cluster_size != 0) {
+int ret = bdrv_get_info(target, &bdi);
+if (ret >= 0 && bdi.cluster_size != 0) {
 granularity = MAX(4096, bdi.cluster_size);
 granularity = MIN(65536, granularity);
 } else {
 granularity = 65536;
 }
+if (ret >= 0) {
+bdrv_put_info(target, &bdi);
+}
 }
 
 assert ((granularity & (granularity - 1)) == 0);
diff --git a/block/qapi.c b/block/qapi.c
index 782051c..738469a 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -133,6 +133,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
 }
 info->dirty_flag = bdi.is_dirty;
 info->has_dirty_flag = true;
+if (bdi.format_specific) {
+info->format_specific = bdi.format_specific;
+info->has_format_specific = true;
+}
 }
 backing_filename = bs->backing_file;
 if (backing_filename[0] != '\0') {
diff --git a/include/block/block.h b/include/block/block.h
index 1c5f939..a9b3b16 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -18,6 +18,8 @@ typedef struct BlockDriverInfo {
 /* offset at which the VM state can be saved (0 if not possible) */
 int64_t vm_state_offset;
 bool is_dirty;
+/* additional information; NULL if none */
+ImageInfoSpecific *format_specific;
 } BlockDriverInfo;
 
 typedef struct BlockFragInfo {
@@ -334,6 +336,7 @@ int bdrv_get_flags(BlockDriverState *bs);
 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
   const uint8_t *buf, int nb_sectors);
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
+void bdrv_put_info(BlockDriverState *bs, BlockDriverInfo *bdi);
 void bdrv_round_to_clusters(BlockDr

Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Gerd Hoffmann
On Mi, 2013-09-11 at 09:41 +0200, Paolo Bonzini wrote:
> Il 11/09/2013 09:27, Paolo Bonzini ha scritto:
> > 
> > There are a couple of things that can be improved still (I don't like
> > obj-save-y for example), but things are taking shape and all of this
> > looks like something that can be fixed on top.  If you look at
> > converting more parts to modules (e.g. rbd or spice), you can drop that
> > RFC! :)
> 
> Talking about spice, a question for Gerd.
> 
> With Fam's work to enable shared modules, hw/display/qxl* would have to
> be placed in a module as well because they depend on ui/spice-core.c.

Yes.  Can modules depend on modules?  Or would we have to create a
single, big spice module with core, qxl, audio, chardev etc?

> Right now, modularization is limited to files that are built once for
> all of QEMU, which is not the case for qxl.
> 
> It looks like TARGET_PAGE_SIZE is the only reason why qxl is built
> per-target, and in qxl_ram_set_dirty it should be enough to do
> 
> qxl_set_dirty(&qxl->vga.vram, offset, offset + 1);
> 
> Would it be fine to use a generic 4096 constant everywhere else?

Yes.  Maybe s/TARGET_PAGE_SIZE/QXL_PAGE_SIZE/ to make clear that qxl
operates on 4k pages.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH] docs: Fix IO port number for CPU present bitmap.

2013-09-11 Thread Igor Mammedov
On Tue, 10 Sep 2013 17:36:18 +0100
Anthony PERARD  wrote:

> Signed-off-by: Anthony PERARD 
> ---
>  docs/specs/acpi_cpu_hotplug.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
> index 5dec0c5..f6f5774 100644
> --- a/docs/specs/acpi_cpu_hotplug.txt
> +++ b/docs/specs/acpi_cpu_hotplug.txt
> @@ -10,7 +10,7 @@ ACPI GPE block (IO ports 0xafe0-0xafe3, byte access):
>  Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU
>  hot-add/remove event to ACPI BIOS, via SCI interrupt.
>  
> -CPU present bitmap (IO port 0xaf00-0xae1f, 1-byte access):
> +CPU present bitmap (IO port 0xaf00-0xaf1f, 1-byte access):
>  ---
>  One bit per CPU. Bit position reflects corresponding CPU APIC ID.
>  Read-only.

Reviewd-By: Igor Mammedov 



Re: [Qemu-devel] Disabling IRQ error

2013-09-11 Thread Xie Xianshan

Hi Max,
  Thanks for your reply.
  And I am sorry for my unclear description.
  I want to add a new device "fpga" for e500, and trigger an interrupt 
IRQ3 while the register BB_INTR_REG which belongs to device "fpga" is 
wrote by the device driver of "fpga".

  For e500, IRQ3 is an external interrupt irq.

  According the debug log, the disabling error is encoutered during 
writing BB_INTR_REG register.

  - write BB_INTR_REG register
  - qemu_irq_raise() is called.
  - after serval minutes,
the error message about disabling irq is displayed.
  - continue the next execution without error(with poll?)


My sample code is as follows:
--
hw/ppce500_fpga.c
--
typedef struct FPGAState {
SysBusDevice busdev;
MemoryRegion iomem;
qemu_irq irq;

}FPGAState;

static void fpga_write(FPGAState *s, unsigned int offset, uint32_t 
value, unsigned size) {

switch(offset) {
case BB_INTR_REG:
qemu_irq_raise(s->irq);
break;
}
}

static int ppce500_fpga_initfn(SysBusDevice *dev) {
FPGAState *s;
s = FROM_SYSBUS(FPGAState, SYS_BUS_DEVICE(dev));
sysbus_init_irq(dev, &s->irq);
...
}

--
hw/ppc/e500.c
--
void ppce500_init(PPCE500Params *params) {
...
qemu_irq *mpic;

for (i = 0; i < 256; i++) {
mpic[i] = qdev_get_gpio_in(dev, i);
}
...
/* add for FPGA */
dev_fpga = qdev_create(NULL, "fpga");
dev_fpga->id = "fpga";
qdev_init_nofail(dev_fpga);
s = SYS_BUS_DEVICE(dev_fpga);
memory_region_add_subregion(fpga_space, FPGA_REGS_OFFSET,
sysbus_mmio_get_region(s, 0));
sysbus_connect_irq(s, 0, mpic[3]);

}


Thanks

 Simen


于 2013/09/10 16:23, Max Filippov 写道:

On Tue, Sep 10, 2013 at 11:25 AM, Xie Xianshan  wrote:

hi everyone,

I`m getting the nobody cared disabling IRQ error, when i raised external
interrupts IRQ3 to the Openpic in QEMU.
(Actually, any external interrupts irq i raised can reproduce this error,
but internal interrupts work fine)

And this IRQ3 is sharing irq with usb card.


Could you please explain what you mean by "I raised external interrupt",
what you generally try to achieve and what behaviour you expected?

Your description reminds me of this thread:
https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg04063.html




--
Best Regards
Xie Xianshan
--
Xie Xianshan
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
PHONE: +86+25-86630566-9555
FUJITSU INTERNAL: 7998-9555
MAIL: xi...@cn.fujitsu.com
--
This communication is for use by the intended recipient(s) only and may
contain information that is privileged, confidential and exempt from
disclosure under applicable law. If you are not an intended recipient of
this communication, you are hereby notified that any dissemination,
distribution or copying hereof is strictly prohibited.  If you have
received this communication in error, please notify me by reply e-mail,
permanently delete this communication from your system, and destroy any
hard copies you may have printed




Re: [Qemu-devel] [PATCH V4 0/3] qemu-iotests: add test for fd passing via SCM rights

2013-09-11 Thread Wenchao Xia

于 2013/9/11 15:32, Kevin Wolf 写道:

Am 11.09.2013 um 04:38 hat Wenchao Xia geschrieben:

于 2013/9/10 19:47, Kevin Wolf 写道:

Am 09.09.2013 um 13:57 hat Stefan Hajnoczi geschrieben:

On Fri, Sep 06, 2013 at 11:24:31AM +0800, Wenchao Xia wrote:

This series add test case for fd passing with unix socket at runtime. Since
getfd and closefd interface will interact with monitor's data, so it will
help to do regression test for monitor patches. Since python2 do not support
sendmsg(), so a C helper program is added to do the job.

v2:
   1: add missing $ in the makefile rule.

v3:
   Address Eric's comments:
   1: typo fix, remove "." in the end of error message, strick
check argc as "!=", use EXIT_SUCCESS and EXIT_FAILURE as exit
values, strict error check for strtol() call.
   Address Luiz's comments:
   1: change the helper program parameter as "bin<   socket-fd>   <   
file-path>",
the program open the file itself now, data parameter is removed and blank
is always used as iov data, better usage tip message, folder the string parsing
code into a function.
   2: related change for helper program parameter change.
   3: related change for helper program parameter change.
   Other:
   1: remove "LINK" rule in makefile, remove fd checking code inside send_fd()
since it is already checked before calling, add '' around %s for path and
number string in error message.
   2: renamed fd_bin to bin in send_fd_scm() to tip better, add '' around %s
for path in error message.
v4:
   Address Stefan's comments:
   2: add space after # for comments, refined the comment's grammar.
   3: add space after # for comments, refined the comment's grammar, add two
test cases for error path.

Wenchao Xia (3):
   1 qemu-iotests: add unix socket help program
   2 qemu-iotests: add infrastructure of fd passing via SCM
   3 qemu-iotests: add tests for runtime fd passing via SCM rights

  QMP/qmp.py |6 ++
  configure  |2 +-
  tests/Makefile |3 +-
  tests/qemu-iotests/045 |   51 -
  tests/qemu-iotests/045.out |4 +-
  tests/qemu-iotests/check   |1 +
  tests/qemu-iotests/iotests.py  |   23 ++
  tests/qemu-iotests/socket_scm_helper.c |  135 
  8 files changed, 220 insertions(+), 5 deletions(-)
  create mode 100644 tests/qemu-iotests/socket_scm_helper.c

Reviewed-by: Stefan Hajnoczi

I'm not completely convinced that it's a good idea to introduce a helper
binary that isn't automatically rebuilt after an upgrade (I basically

Indeed it will not be rebuilt when code for qemu change, but will be
rebuilt when
socket_scm_helper.c change. The help program have no connection with
qemu's main code,
so I think it is safe.
The binaries built under tests/ will not be cleaned, so I think they
all have a chance to
stay as old version. If this is the issue you mean, I will send a
patch clean them, which
is what I planned to do sometimes ago . :)

The difference is that the binaries under tests/ will usually only ever
be called using 'make check', which does update them. In contrast, I
usually run qemu-iotests by directly executing check -T -nocache -qcow2,
which doesn't update anything.

Kevin


  OK, I see the problem now. I guess "make" is done before to update qemu
binary, so the problem is how to trigger the build of helper. What about
add Makefile in test/qemu-iotests/ ? Then 'make check' in root dir, and
'check -T ..." both trigger the build.


never run 'make check-block', which is the only way that would trigger
it), but given this Reviewed-by, I've applied this to the block branch.

Kevin






Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Fam Zheng
On Wed, 09/11 10:01, Gerd Hoffmann wrote:
> On Mi, 2013-09-11 at 09:41 +0200, Paolo Bonzini wrote:
> > Il 11/09/2013 09:27, Paolo Bonzini ha scritto:
> > > 
> > > There are a couple of things that can be improved still (I don't like
> > > obj-save-y for example), but things are taking shape and all of this
> > > looks like something that can be fixed on top.  If you look at
> > > converting more parts to modules (e.g. rbd or spice), you can drop that
> > > RFC! :)
> > 
> > Talking about spice, a question for Gerd.
> > 
> > With Fam's work to enable shared modules, hw/display/qxl* would have to
> > be placed in a module as well because they depend on ui/spice-core.c.
> 
> Yes.  Can modules depend on modules?  Or would we have to create a
> single, big spice module with core, qxl, audio, chardev etc?
> 
No dependence support yet.

Fam

> > Right now, modularization is limited to files that are built once for
> > all of QEMU, which is not the case for qxl.
> > 
> > It looks like TARGET_PAGE_SIZE is the only reason why qxl is built
> > per-target, and in qxl_ram_set_dirty it should be enough to do
> > 
> > qxl_set_dirty(&qxl->vga.vram, offset, offset + 1);
> > 
> > Would it be fine to use a generic 4096 constant everywhere else?
> 
> Yes.  Maybe s/TARGET_PAGE_SIZE/QXL_PAGE_SIZE/ to make clear that qxl
> operates on 4k pages.
> 
> cheers,
>   Gerd
> 
> 



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Peter Maydell
On 11 September 2013 09:01, Gerd Hoffmann  wrote:
> On Mi, 2013-09-11 at 09:41 +0200, Paolo Bonzini wrote:
>> It looks like TARGET_PAGE_SIZE is the only reason why qxl is built
>> per-target, and in qxl_ram_set_dirty it should be enough to do
>>
>> qxl_set_dirty(&qxl->vga.vram, offset, offset + 1);
>>
>> Would it be fine to use a generic 4096 constant everywhere else?
>
> Yes.  Maybe s/TARGET_PAGE_SIZE/QXL_PAGE_SIZE/ to make clear that qxl
> operates on 4k pages.

Does this mean that the code was previously wrong for targets
which didn't have 4K pages, or would we just have been a bit
inefficient? I ask because ARM's TARGET_PAGE_SIZE is 1K...

-- PMM



Re: [Qemu-devel] [PATCH] target-i386: set model=6 on qemu64 & qemu32 CPU models

2013-09-11 Thread Igor Mammedov
On Tue, 10 Sep 2013 17:48:59 -0300
Eduardo Habkost  wrote:

> There's no Intel CPU with family=6,model=2, and Linux and Windows guests
> disable SEP when seeing that combination due to Pentium Pro erratum #82.
> 
> In addition to just having SEP ignored by guests, Skype (and maybe other
> applications) runs sysenter directly without passing through ntdll on
> Windows, and crashes because Windows ignored the SEP CPUID bit.
> 
> So, having model > 2 is a better default on qemu64 and qemu32 for two
> reasons: making SEP really available for guests, and avoiding crashing
> applications that work on bare metal.
> 
> model=3 would fix the problem, but it causes CPU enumeration problems
> for Windows guests[1]. So this patch sets model=6, that matches "Athlon
> (PM core)" on AMD and "P2 with on-die L2 cache" on Intel and it allows
> Windows to use all CPUs as well as fixing sysenter.
> 
> [1] https://bugzilla.redhat.com/show_bug.cgi?id=508623
> 
> Cc: Andrea Arcangeli 
> Signed-off-by: Eduardo Habkost 
> ---
>  include/hw/i386/pc.h | 8 
>  target-i386/cpu.c| 4 ++--
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 7fb04d8..195e962 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -258,6 +258,14 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
>  .driver = TYPE_X86_CPU,\
>  .property = "pmu",\
>  .value = "on",\
> +},{\
> +.driver   = "qemu64-" TYPE_X86_CPU,\
> +.property = "model",\
> +.value= stringify(2),\
> +},{\
> +.driver   = "qemu32-" TYPE_X86_CPU,\
> +.property = "model",\
> +.value= stringify(3),\
>  }
>  
>  #define PC_COMPAT_1_4 \
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index c36345e..36cfbce 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -544,7 +544,7 @@ static x86_def_t builtin_x86_defs[] = {
>  .level = 4,
>  .vendor = CPUID_VENDOR_AMD,
>  .family = 6,
> -.model = 2,
> +.model = 6,
>  .stepping = 3,
>  .features[FEAT_1_EDX] =
>  PPRO_FEATURES |
> @@ -647,7 +647,7 @@ static x86_def_t builtin_x86_defs[] = {
>  .level = 4,
>  .vendor = CPUID_VENDOR_INTEL,
>  .family = 6,
> -.model = 3,
> +.model = 6,
>  .stepping = 3,
>  .features[FEAT_1_EDX] =
>  PPRO_FEATURES,

Reviewed-By: Igor Mammedov 



Re: [Qemu-devel] [PATCH] qdev: rename qdev_free() to qdev_unparent()

2013-09-11 Thread Andreas Färber
Am 11.09.2013 09:45, schrieb Stefan Hajnoczi:
> The qdev_free() function name is misleading since all the function does
> is unlink the device from its parent.  The device is not necessarily
> freed.
> 
> The device will be freed when its QObject refcount reaches zero.  It is
> usual for the parent (bus) to hold the final reference but there are
> cases where something else holds a reference so "free" is a misleading
> name.
> 
> I opted to keep a qdev wrapper function instead of making all callers
> use object_unparent(OBJECT(qdev)) directly due to the slightly ugly
> cast.
> 
> Signed-off-by: Stefan Hajnoczi 
> ---
> This patch is based on the "[PATCH 0/6] qdev and blockdev refcount leak fixes"
> series that I sent yesterday.
> 
>  hw/acpi/piix4.c  |  2 +-
>  hw/core/qdev.c   | 10 +-
>  hw/pci/pci-hotplug-old.c |  2 +-
>  hw/pci/pci_bridge.c  |  2 +-
>  hw/pci/pcie.c|  2 +-
>  hw/pci/shpc.c|  2 +-
>  hw/s390x/virtio-ccw.c|  2 +-
>  hw/scsi/scsi-bus.c   |  6 +++---
>  hw/usb/bus.c |  4 ++--
>  hw/usb/dev-storage.c |  2 +-
>  hw/usb/host-legacy.c |  2 +-
>  hw/virtio/virtio-bus.c   |  2 +-
>  hw/xen/xen_platform.c|  2 +-
>  include/hw/qdev-core.h   |  2 +-
>  qdev-monitor.c   |  2 +-
>  15 files changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 0b8d1d9..2ec9ada 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -326,7 +326,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, 
> unsigned slots)
>  if (pc->no_hotplug) {
>  slot_free = false;
>  } else {
> -qdev_free(qdev);
> +qdev_unparent(qdev);
>  }
>  }
>  }
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 533f6dd..ac2352b 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
>  if (local_err != NULL) {
>  qerror_report_err(local_err);
>  error_free(local_err);
> -qdev_free(dev);
> +qdev_unparent(dev);
>  return -1;
>  }
>  return 0;
> @@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
>  int qdev_simple_unplug_cb(DeviceState *dev)
>  {
>  /* just zap it */
> -qdev_free(dev);
> +qdev_unparent(dev);
>  return 0;
>  }
>  
> @@ -280,8 +280,8 @@ void qdev_init_nofail(DeviceState *dev)
>  }
>  }
>  
> -/* Unlink device from bus and free the structure.  */
> -void qdev_free(DeviceState *dev)
> +/* Unlink device from bus.  dev is freed if refcount reaches zero. */
> +void qdev_unparent(DeviceState *dev)
>  {
>  object_unparent(OBJECT(dev));
>  }
> @@ -458,7 +458,7 @@ static void bus_unparent(Object *obj)
>  
>  while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
>  DeviceState *dev = kid->child;
> -qdev_free(dev);
> +qdev_unparent(dev);
>  }
>  if (bus->parent) {
>  QLIST_REMOVE(bus, sibling);
> diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
> index 619fe47..f197f5f 100644
> --- a/hw/pci/pci-hotplug-old.c
> +++ b/hw/pci/pci-hotplug-old.c
> @@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
>  }
>  dev = pci_create(bus, devfn, "virtio-blk-pci");
>  if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
> -qdev_free(&dev->qdev);
> +qdev_unparent(&dev->qdev);

This should be DEVICE(dev), making most callers outside qdev.c do a cast
after all.

Also we should name the function device_unparent if we decide to keep it
around.

Andreas

>  dev = NULL;
>  break;
>  }
> diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
> index e6b22b8..68e0bcb 100644
> --- a/hw/pci/pci_bridge.c
> +++ b/hw/pci/pci_bridge.c
> @@ -391,7 +391,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
>  pci_bridge_region_cleanup(s, s->windows);
>  memory_region_destroy(&s->address_space_mem);
>  memory_region_destroy(&s->address_space_io);
> -/* qbus_free() is called automatically by qdev_free() */
> +/* qbus_free() is called automatically by qdev_unparent() */
>  }
>  
>  /*
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 50af3c1..edd3f40 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
> PCI_EXP_SLTSTA_PDS);
>  pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
>  } else {
> -qdev_free(&pci_dev->qdev);
> +qdev_unparent(&pci_dev->qdev);
>  pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
>   PCI_EXP_SLTSTA_PDS);
>  pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index eb092fd..5ba2b17 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -254,7 +254,7 @@ static void shpc_free_dev

Re: [Qemu-devel] guest kernel 3.10 panic at boot (__mcheck_cpu_init_generic) with kvm64 vcpu + amd host cpu (qemu 1.4)

2013-09-11 Thread Gleb Natapov
On Wed, Sep 11, 2013 at 05:39:01AM +0200, Alexandre DERUMIER wrote:
> Hi List,
> I'm trying to boot a debian squeeze guest with a 3.10 kernel, and I have a 
> crash at boot
> 
> This only happen with kvm64 vcpu + amd host (opteron 6100 or opteron 6300).
> 
Check host dmesg for unhandled msrs.

> host vcpu + amd host works fine
> kvm64 vcpu + intel host works fine too.
> 
> 
> host os is proxmox 3.1 (rhel 6.4 2.6.32 kernel + qemu 64)
> 
> I can boot fine this guest with 3.7 kernel.
> 
> (I'll try to build 3.8 and 3.9 kernel later this week).
> 
> Any idea ?
> 
> Regards,
> 
> Alexandre
> 
> 
> 
> 
> [0.00] Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.7 
> root=UUID=a8eb9f6e-dbc6-4797-baea-8e7198e8e541 ro console=ttyS0 console=tty0
> [0.00] e820: BIOS-provided physical RAM map:
> [0.00] BIOS-e820: [mem 0x-0x0009fbff] usable
> [0.00] BIOS-e820: [mem 0x0009fc00-0x0009] reserved
> [0.00] BIOS-e820: [mem 0x000f-0x000f] reserved
> [0.00] BIOS-e820: [mem 0x0010-0xdfffdfff] usable
> [0.00] BIOS-e820: [mem 0xdfffe000-0xdfff] reserved
> [0.00] BIOS-e820: [mem 0xfeffc000-0xfeff] reserved
> [0.00] BIOS-e820: [mem 0xfffc-0x] reserved
> [0.00] BIOS-e820: [mem 0x0001-0x00011fff] usable
> [0.00] NX (Execute Disable) protection: active
> [0.00] SMBIOS 2.4 present.
> [0.00] No AGP bridge found
> [0.00] e820: last_pfn = 0x12 max_arch_pfn = 0x4
> [0.00] x86 PAT enabled: cpu 0, old 0x70406, new 0x7010600070106
> [0.00] e820: last_pfn = 0xdfffe max_arch_pfn = 0x4
> [0.00] found SMP MP-table at [mem 0x000fdaa0-0x000fdaaf] mapped at 
> [880fdaa0]
> [0.00] init_memory_mapping: [mem 0x-0x000f]
> [0.00] init_memory_mapping: [mem 0x11fe0-0x11fff]
> [0.00] init_memory_mapping: [mem 0x11c00-0x11fdf]
> [0.00] init_memory_mapping: [mem 0x1-0x11bff]
> [0.00] init_memory_mapping: [mem 0x0010-0xdfffdfff]
> [0.00] RAMDISK: [mem 0x37576000-0x37fe]
> [0.00] ACPI: RSDP 000fd890 00014 (v00 BOCHS )
> [0.00] ACPI: RSDT dfffe380 00034 (v01 BOCHS  BXPCRSDT 
> 0001 BXPC 0001)
> [0.00] ACPI: FACP df80 00074 (v01 BOCHS  BXPCFACP 
> 0001 BXPC 0001)
> [0.00] ACPI: DSDT dfffe3c0 011A9 (v01   BXPC   BXDSDT 
> 0001 INTL 20100528)
> [0.00] ACPI: FACS df40 00040
> [0.00] ACPI: SSDT d6e0 00858 (v01 BOCHS  BXPCSSDT 
> 0001 BXPC 0001)
> [0.00] ACPI: APIC d5b0 00090 (v01 BOCHS  BXPCAPIC 
> 0001 BXPC 0001)
> [0.00] ACPI: HPET d570 00038 (v01 BOCHS  BXPCHPET 
> 0001 BXPC 0001)
> [0.00] No NUMA configuration found
> [0.00] Faking a node at [mem 0x-0x00011fff]
> [0.00] Initmem setup node 0 [mem 0x-0x11fff]
> [0.00]   NODE_DATA [mem 0x11fff8000-0x11fffbfff]
> [0.00] Zone ranges:
> [0.00]   DMA  [mem 0x1000-0x00ff]
> [0.00]   DMA32[mem 0x0100-0x]
> [0.00]   Normal   [mem 0x1-0x11fff]
> [0.00] Movable zone start for each node
> [0.00] Early memory node ranges
> [0.00]   node   0: [mem 0x1000-0x0009efff]
> [0.00]   node   0: [mem 0x0010-0xdfffdfff]
> [0.00]   node   0: [mem 0x1-0x11fff]
> [0.00] ACPI: PM-Timer IO Port: 0xb008
> [0.00] ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
> [0.00] ACPI: LAPIC (acpi_id[0x01] lapic_id[0x01] enabled)
> [0.00] ACPI: LAPIC (acpi_id[0x02] lapic_id[0x02] enabled)
> [0.00] ACPI: LAPIC (acpi_id[0x03] lapic_id[0x03] enabled)
> [0.00] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
> [0.00] ACPI: IOAPIC (id[0x00] address[0xfec0] gsi_base[0])
> [0.00] IOAPIC[0]: apic_id 0, version 17, address 0xfec0, GSI 0-23
> [0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
> [0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
> [0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
> [0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
> [0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
> [0.00] Using ACPI (MADT) for SMP configuration information
> [0.00] ACPI: HPET id: 0x8086a201 base: 0xfed0
> [0.00] smpboot: Allowing 4 CPUs, 0 hotplug CPUs
> [0.00] PM: Registered nosave memory: 0009f000 - 
> 000a
> [0.00] PM: Registered nosave memory: 000a - 
> 000f
> [0.0

Re: [Qemu-devel] [PATCH] target-i386: set model=6 on qemu64 & qemu32 CPU models

2013-09-11 Thread Andreas Färber
Am 11.09.2013 10:22, schrieb Igor Mammedov:
> On Tue, 10 Sep 2013 17:48:59 -0300
> Eduardo Habkost  wrote:
> 
>> There's no Intel CPU with family=6,model=2, and Linux and Windows guests
>> disable SEP when seeing that combination due to Pentium Pro erratum #82.
>>
>> In addition to just having SEP ignored by guests, Skype (and maybe other
>> applications) runs sysenter directly without passing through ntdll on
>> Windows, and crashes because Windows ignored the SEP CPUID bit.
>>
>> So, having model > 2 is a better default on qemu64 and qemu32 for two
>> reasons: making SEP really available for guests, and avoiding crashing
>> applications that work on bare metal.
>>
>> model=3 would fix the problem, but it causes CPU enumeration problems
>> for Windows guests[1]. So this patch sets model=6, that matches "Athlon
>> (PM core)" on AMD and "P2 with on-die L2 cache" on Intel and it allows
>> Windows to use all CPUs as well as fixing sysenter.
>>
>> [1] https://bugzilla.redhat.com/show_bug.cgi?id=508623
>>
>> Cc: Andrea Arcangeli 
>> Signed-off-by: Eduardo Habkost 
>> ---
>>  include/hw/i386/pc.h | 8 
>>  target-i386/cpu.c| 4 ++--
>>  2 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
>> index 7fb04d8..195e962 100644
>> --- a/include/hw/i386/pc.h
>> +++ b/include/hw/i386/pc.h
>> @@ -258,6 +258,14 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
>>  .driver = TYPE_X86_CPU,\
>>  .property = "pmu",\
>>  .value = "on",\
>> +},{\
>> +.driver   = "qemu64-" TYPE_X86_CPU,\
>> +.property = "model",\
>> +.value= stringify(2),\
>> +},{\
>> +.driver   = "qemu32-" TYPE_X86_CPU,\
>> +.property = "model",\
>> +.value= stringify(3),\
>>  }
>>  
>>  #define PC_COMPAT_1_4 \

Shouldn't this hunk be in PC_COMPAT_1_6 rather than alongside PMU, which
I believe was for 1_5?

Andreas

>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index c36345e..36cfbce 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
>> @@ -544,7 +544,7 @@ static x86_def_t builtin_x86_defs[] = {
>>  .level = 4,
>>  .vendor = CPUID_VENDOR_AMD,
>>  .family = 6,
>> -.model = 2,
>> +.model = 6,
>>  .stepping = 3,
>>  .features[FEAT_1_EDX] =
>>  PPRO_FEATURES |
>> @@ -647,7 +647,7 @@ static x86_def_t builtin_x86_defs[] = {
>>  .level = 4,
>>  .vendor = CPUID_VENDOR_INTEL,
>>  .family = 6,
>> -.model = 3,
>> +.model = 6,
>>  .stepping = 3,
>>  .features[FEAT_1_EDX] =
>>  PPRO_FEATURES,
> 
> Reviewed-By: Igor Mammedov 
> 


-- 
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 RFC 4/4] Curling: the receiver

2013-09-11 Thread junqing . wang
hi,


At 2013-09-10 22:19:48,"Juan Quintela"  wrote:

>> @@ -112,13 +113,24 @@ static void process_incoming_migration_co(void *opaque)
>>  {
>>  QEMUFile *f = opaque;
>>  int ret;
>> +int count = 0;
>>  
>> -ret = qemu_loadvm_state(f);
>> -qemu_fclose(f);
>> -if (ret < 0) {
>> -fprintf(stderr, "load of migration failed\n");
>> -exit(EXIT_FAILURE);
>> +if (ft_enabled()) {
>> +while (qemu_loadvm_state_ft(f) >= 0) {
>> +count++;
>> +DPRINTF("incoming count %d\r", count);
>> +}
>> +qemu_fclose(f);
>> +fprintf(stderr, "ft connection lost, launching self..\n");
>
>Obviously,  here we are needing something more that an fprintf,,  right?
>
>We are not checking either if it is one error.

Agree.

>> +} else {
>> +ret = qemu_loadvm_state(f);
>> +qemu_fclose(f);
>> +if (ret < 0) {
>> +fprintf(stderr, "load of migration failed\n");
>> +exit(EXIT_FAILURE);
>> +}
>>  }
>> +cpu_synchronize_all_post_init();
>>  qemu_announce_self();
>>  DPRINTF("successfully loaded vm state\n");
>>  
>> diff --git a/savevm.c b/savevm.c
>> index 6daf690..d5bf153 100644
>> --- a/savevm.c
>> +++ b/savevm.c
>> @@ -52,6 +52,8 @@
>>  #define ARP_PTYPE_IP 0x0800
>>  #define ARP_OP_REQUEST_REV 0x3
>>  
>> +#define PFB_SIZE 0x01
>> +
>>  static int announce_self_create(uint8_t *buf,
>>  uint8_t *mac_addr)
>>  {
>> @@ -135,6 +137,10 @@ struct QEMUFile {
>>  unsigned int iovcnt;
>>  
>>  int last_error;
>> +
>> +uint8_t *pfb;   /* pfb -> PerFetch Buffer */
>
>s/PreFetch/Prefetcth/
>
>prefetch_buffer as name?  not used in so many places,  makes things
>clearer or more convoluted?  Other comments?
>

Agree.

>> +static int socket_get_prefetch_buffer(void *opaque, uint8_t *buf,
>> +  int64_t pos, int size)
>> +{
>> +QEMUFile *f = opaque;
>> +
>> +if (f->pfb_size - pos <= 0) {
>> +return 0;
>> +}
>> +
>> +if (f->pfb_size - pos < size) {
>> +size = f->pfb_size - pos;
>> +}
>> +
>> +memcpy(buf, f->pfb+pos, size);
>> +
>> +return size;
>> +}
>> +
>> +
>>  static int socket_close(void *opaque)
>>  {
>>  QEMUFileSocket *s = opaque;
>> @@ -440,6 +465,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
>>  static const QEMUFileOps socket_read_ops = {
>>  .get_fd = socket_get_fd,
>>  .get_buffer = socket_get_buffer,
>> +.get_prefetch_buffer = socket_get_prefetch_buffer,
>>  .close =  socket_close
>>  };
>>  
>
>>  if (f->last_error) {
>>  ret = f->last_error;
>>  }
>> +
>> +if (f->pfb) {
>> +g_free(f->pfb);
>
>g_free(f->pfb);
>It already checks for NULL.

Got it.

>> +}
>> +
>>  g_free(f);
>>  return ret;
>>  }
>> @@ -822,6 +853,14 @@ void qemu_put_byte(QEMUFile *f, int v)
>>  
>>  static void qemu_file_skip(QEMUFile *f, int size)
>>  {
>> +if (f->pfb_index + size <= f->pfb_size) {
>> +f->pfb_index += size;
>> +return;
>> +} else {
>> +size -= f->pfb_size - f->pfb_index;
>> +f->pfb_index = f->pfb_size;
>> +}
>> +
>>  if (f->buf_index + size <= f->buf_size) {
>>  f->buf_index += size;
>>  }
>> @@ -831,6 +870,21 @@ static int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, 
>> int size, size_t offset)
>>  {
>>  int pending;
>>  int index;
>> +int done;
>> +
>> +if (f->ops->get_prefetch_buffer) {
>> +if (f->pfb_index + offset < f->pfb_size) {
>> +done = f->ops->get_prefetch_buffer(f, buf, f->pfb_index + 
>> offset,
>> +   size);
>> +if (done == size) {
>> +return size;
>> +}
>> +size -= done;
>> +buf  += done;
>> +} else {
>> +offset -= f->pfb_size - f->pfb_index;
>> +}
>> +}
>>  
>>  assert(!qemu_file_is_writable(f));
>>  
>> @@ -875,7 +929,15 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size)
>>  
>>  static int qemu_peek_byte(QEMUFile *f, int offset)
>>  {
>> -int index = f->buf_index + offset;
>> +int index;
>> +
>> +if (f->pfb_index + offset < f->pfb_size) {
>> +return f->pfb[f->pfb_index + offset];
>> +} else {
>> +offset -= f->pfb_size - f->pfb_index;
>> +}
>> +
>> +index = f->buf_index + offset;
>>  
>>  assert(!qemu_file_is_writable(f));
>>  
>> @@ -1851,7 +1913,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
>>  }
>>  se->ops->set_params(params, se->opaque);
>>  }
>> -
>> +
>>  qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
>>  qemu_put_be32(f, QEMU_VM_FILE_VERSION);
>>  
>> @@ -2294,8 +2356,6 @@ int qemu_loadvm_state(QEMUFile *f)
>>  }
>>  }
>>  
>> -cpu_synchronize_all_post_init();
>> -
>>  ret = 0;
>>  
>>  out:
>> @@ -2311,6 +2371,89 @@ out:
>>  return ret;
>>

Re: [Qemu-devel] qemu-img convert will increase the VM image

2013-09-11 Thread Kevin Wolf
Am 11.09.2013 um 09:14 hat xuanmao_001 geschrieben:
> Hi, all:
>  
> I have question about qemu-img convert ...
>  
> I have a orignal image with following information:
> # qemu-img info ori.qcow2   
> image: ori.qcow2
> file format: qcow2
> virtual size: 2.0G (2097152000 bytes)
> disk size: 308M
> cluster_size: 65536
>  
> when I executed with "qemu-img convert -f qcow2 -O qcow2 ori.qcow2 new.qcow2"
> the new.qcow2 like following:
> # qemu-img info new.qcow2 
> image: new.qcow2
> file format: qcow2
> virtual size: 2.0G (2097152000 bytes)
> disk size: 748M
> cluster_size: 65536
>  
> so, my question is why the image size increased after my operation?

You can try comparing the output of the qemu-io 'map' command for both
images.

Kevin



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Fam Zheng
On Wed, 09/11 09:27, Paolo Bonzini wrote:
> Il 11/09/2013 07:38, Fam Zheng ha scritto:
> > The new option will enable support of shared object build. Otherwise
> > objects are static linked to executables.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  Makefile.target | 6 +-
> >  configure   | 8 
> >  rules.mak   | 8 ++--
> >  3 files changed, 19 insertions(+), 3 deletions(-)
> > 
> > diff --git a/Makefile.target b/Makefile.target
> > index 1d92523..beab0f9 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -152,7 +152,11 @@ obj-y-save := $(obj-y)
> >  block-obj-y :=
> >  common-obj-y :=
> >  include $(SRC_PATH)/Makefile.objs
> > -dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
> > +dummy := $(call unnest-vars,.., \
> > +   block-obj-y \
> > +   block-obj-m \
> > +   common-obj-y \
> > +   common-obj-m)
> >  
> >  # Now restore obj-y
> >  obj-y := $(obj-y-save)
> > diff --git a/configure b/configure
> > index a2858c2..f1d7fa7 100755
> > --- a/configure
> > +++ b/configure
> > @@ -192,6 +192,7 @@ gcov_tool="gcov"
> >  EXESUF=""
> >  DSOSUF=".so"
> >  LDFLAGS_SHARED="-shared"
> > +modules="no"
> >  prefix="/usr/local"
> >  mandir="\${prefix}/share/man"
> >  datadir="\${prefix}/share"
> > @@ -650,6 +651,8 @@ for opt do
> >;;
> >--disable-debug-info)
> >;;
> > +  --enable-modules) modules="yes"
> > +  ;;
> >--cpu=*)
> >;;
> >--target-list=*) target_list="$optarg"
> > @@ -1052,6 +1055,7 @@ echo "  --libdir=PATHinstall libraries in 
> > PATH"
> >  echo "  --sysconfdir=PATHinstall config in PATH$confsuffix"
> >  echo "  --localstatedir=PATH install local state in PATH (set at 
> > runtime on win32)"
> >  echo "  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and 
> > sysconfdir [$confsuffix]"
> > +echo "  --enable-modules enable modules support"
> >  echo "  --enable-debug-tcg   enable TCG debugging"
> >  echo "  --disable-debug-tcg  disable TCG debugging (default)"
> >  echo "  --enable-debug-info   enable debugging information (default)"
> > @@ -3580,6 +3584,7 @@ echo "python$python"
> >  if test "$slirp" = "yes" ; then
> >  echo "smbd  $smbd"
> >  fi
> > +echo "module support$modules"
> >  echo "host CPU  $cpu"
> >  echo "host big endian   $bigendian"
> >  echo "target list   $target_list"
> > @@ -3697,6 +3702,9 @@ echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
> >  
> >  echo "ARCH=$ARCH" >> $config_host_mak
> >  
> > +if test "$modules" = "yes"; then
> > +  echo "CONFIG_MODULES=y" >> $config_host_mak
> > +fi
> >  case "$cpu" in
> >arm|i386|x86_64|x32|ppc|aarch64)
> >  # The TCG interpreter currently does not support ld/st optimization.
> > diff --git a/rules.mak b/rules.mak
> > index ea97888..860b8ac 100644
> > --- a/rules.mak
> > +++ b/rules.mak
> > @@ -185,7 +185,11 @@ $(foreach var,$(nested-vars), $(eval \
> >  $(foreach v,$(filter %-m,$(nested-vars)), \
> >  $(call add-modules,$v))
> >  
> > -$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m)))
> > -$(eval all: modules)
> > +$(if $(CONFIG_MODULES), \
> > +$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m))) \
> > +$(eval all: modules), \
> 
> Since you'll have a v6, please move "all: modules" to Makefile, and in
> rules.mak:
> 
> .PHONY: modules
> modules:
> 
Why is ".PHONY: modules" not in Makefile too? And why do we need blank
"modules:", with the real one generated above?

Fam

> There are a couple of things that can be improved still (I don't like
> obj-save-y for example), but things are taking shape and all of this
> looks like something that can be fixed on top.  If you look at
> converting more parts to modules (e.g. rbd or spice), you can drop that
> RFC! :)
> 
> Thanks,
> 
> Paolo
> 
> > +$(foreach v,$(filter %-m,$(nested-vars)), \
> > +$(eval $(patsubst %-m,%-y,$v) += $($v)) \
> > +$(eval $v := )))
> >  
> >  endef
> > 
> 



Re: [Qemu-devel] [PATCH] target-i386: set model=6 on qemu64 & qemu32 CPU models

2013-09-11 Thread Igor Mammedov
On Wed, 11 Sep 2013 10:25:58 +0200
Andreas Färber  wrote:

> Am 11.09.2013 10:22, schrieb Igor Mammedov:
> > On Tue, 10 Sep 2013 17:48:59 -0300
> > Eduardo Habkost  wrote:
> > 
> >> There's no Intel CPU with family=6,model=2, and Linux and Windows guests
> >> disable SEP when seeing that combination due to Pentium Pro erratum #82.
> >>
> >> In addition to just having SEP ignored by guests, Skype (and maybe other
> >> applications) runs sysenter directly without passing through ntdll on
> >> Windows, and crashes because Windows ignored the SEP CPUID bit.
> >>
> >> So, having model > 2 is a better default on qemu64 and qemu32 for two
> >> reasons: making SEP really available for guests, and avoiding crashing
> >> applications that work on bare metal.
> >>
> >> model=3 would fix the problem, but it causes CPU enumeration problems
> >> for Windows guests[1]. So this patch sets model=6, that matches "Athlon
> >> (PM core)" on AMD and "P2 with on-die L2 cache" on Intel and it allows
> >> Windows to use all CPUs as well as fixing sysenter.
> >>
> >> [1] https://bugzilla.redhat.com/show_bug.cgi?id=508623
> >>
> >> Cc: Andrea Arcangeli 
> >> Signed-off-by: Eduardo Habkost 
> >> ---
> >>  include/hw/i386/pc.h | 8 
> >>  target-i386/cpu.c| 4 ++--
> >>  2 files changed, 10 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> >> index 7fb04d8..195e962 100644
> >> --- a/include/hw/i386/pc.h
> >> +++ b/include/hw/i386/pc.h
> >> @@ -258,6 +258,14 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
> >>  .driver = TYPE_X86_CPU,\
> >>  .property = "pmu",\
> >>  .value = "on",\
> >> +},{\
> >> +.driver   = "qemu64-" TYPE_X86_CPU,\
> >> +.property = "model",\
> >> +.value= stringify(2),\
> >> +},{\
> >> +.driver   = "qemu32-" TYPE_X86_CPU,\
> >> +.property = "model",\
> >> +.value= stringify(3),\
> >>  }
> >>  
> >>  #define PC_COMPAT_1_4 \
> 
> Shouldn't this hunk be in PC_COMPAT_1_6 rather than alongside PMU, which
> I believe was for 1_5?
grr, you are right.
my reviewed-by stands, provided compats are moved to PC_COMPAT_1_6.


> Andreas
> 
> >> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> >> index c36345e..36cfbce 100644
> >> --- a/target-i386/cpu.c
> >> +++ b/target-i386/cpu.c
> >> @@ -544,7 +544,7 @@ static x86_def_t builtin_x86_defs[] = {
> >>  .level = 4,
> >>  .vendor = CPUID_VENDOR_AMD,
> >>  .family = 6,
> >> -.model = 2,
> >> +.model = 6,
> >>  .stepping = 3,
> >>  .features[FEAT_1_EDX] =
> >>  PPRO_FEATURES |
> >> @@ -647,7 +647,7 @@ static x86_def_t builtin_x86_defs[] = {
> >>  .level = 4,
> >>  .vendor = CPUID_VENDOR_INTEL,
> >>  .family = 6,
> >> -.model = 3,
> >> +.model = 6,
> >>  .stepping = 3,
> >>  .features[FEAT_1_EDX] =
> >>  PPRO_FEATURES,
> > 
> > Reviewed-By: Igor Mammedov 
> > 
> 
> 




Re: [Qemu-devel] [PATCH v2] e1000: NetClientInfo.receive_iov implemented

2013-09-11 Thread Stefan Hajnoczi
On Tue, Sep 10, 2013 at 02:19:47PM +0200, Vincenzo Maffione wrote:
> This patch implements the NetClientInfo.receive_iov method for the
> e1000 device emulation. In this way a network backend that uses
> qemu_sendv_packet() can deliver the fragmented packet without
> requiring an additional copy in the frontend/backend network code
> (nc_sendv_compat() function).
> 
> The existing method NetClientInfo.receive has been reimplemented
> using the new method.
> 
> Signed-off-by: Vincenzo Maffione 
> ---
>  hw/net/e1000.c | 71 
> --
>  1 file changed, 59 insertions(+), 12 deletions(-)
> 
> I propose this patch also because our research group (University of Pisa,
> Department of Computer Engineering) is working on the e1000 device
> (optimizations and paravirtual extensions) and we have patches to
> support the VALE switch as a network backend (see
> http://info.iet.unipi.it/~luigi/vale/).
> The VALE backend uses qemu_sendv_packet() to send fragmented packets: For
> this reason we think it could be interesting to better support these packets
> with e1000.

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

Stefan



Re: [Qemu-devel] [PATCH V8 0/8] add internal snapshot support at block device level

2013-09-11 Thread Kevin Wolf
Am 11.09.2013 um 08:04 hat Wenchao Xia geschrieben:
>   This series brings internal snapshot support at block devices level, now we
> have two three methods to do block snapshot lively: 1) backing chain,
> 2) internal one and 3) drive-back up approach.
> 
> Comparation:
>  Advantages:Disadvantages:
> 1)delta data, taken fast, export, sizeperformance, delete slow.
> 2)  taken fast, delete fast, performance, size   delta data, format
> 3)  performance, export, format  taken slow, delta data, size, host 
> I/O
> 
>   I think in most case, saving vmstate in an standalone file is better than
> saving it inside qcow2, So suggest treat internal snapshot as block level
> methods and not encourage user to savevm in qcow2 any more.
> 
> Implemention details:
>   To avoid trouble, this serial have hide ID in create interfaces, this make
> sure no chaos of ID and name will be introduced by these interfaces.
>   There is one patch may be common to Pavel's savvm transaction, patch 1/11,
> others are not quite related. Patch 1/11 will not set errp when no snapshot
> find, since patch 3/11 need to distinguish real error case.
> 
> Next steps to better full VM snapshot:
>   Improve internal snapshot's export capability.
>   Better vmstate saving.
> 
>   Thanks Kevin to give advisement about how add it in qmp_transaction, oldest
> version comes from Dietmar Maurer.

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 10:35, Fam Zheng ha scritto:
>> > Since you'll have a v6, please move "all: modules" to Makefile, and in
>> > rules.mak:
>> > 
>> > .PHONY: modules
>> > modules:
>> > 
> Why is ".PHONY: modules" not in Makefile too?

I think you would need it even in Makefile.target, so I suggested rules.mak.

> And why do we need blank
> "modules:", with the real one generated above?

Just for clarity, since the target is declared only in a somewhat hidden
manner through $(eval).

Paolo



Re: [Qemu-devel] qemu-img convert will increase the VM image

2013-09-11 Thread xuanmao_001
the first 30lines output from orignal image:
1 [   0]  128/ 4096000 sectors allocated at 
offset 0.00 bytes (1)
2 [   65536] 1920/ 4095872 sectors not allocated at 
offset 64 KiB (0)
3 [ 1048576]  128/ 4093952 sectors allocated at 
offset 1 MiB (1)
4 [ 1114112]  128/ 4093824 sectors allocated at 
offset 1 MiB (1)
5 [ 1179648]  128/ 4093696 sectors allocated at 
offset 1 MiB (1)
6 [ 1245184]  128/ 4093568 sectors allocated at 
offset 1 MiB (1)
7 [ 1310720]  256/ 4093440 sectors not allocated at 
offset 1 MiB (0)
8 [ 1441792]  128/ 4093184 sectors allocated at 
offset 1 MiB (1)
9 [ 1507328] 1792/ 4093056 sectors not allocated at 
offset 1 MiB (0)
   10 [ 2424832]  128/ 4091264 sectors allocated at 
offset 2 MiB (1)
   11 [ 2490368] 2560/ 4091136 sectors not allocated at 
offset 2 MiB (0)
   12 [ 3801088]  128/ 4088576 sectors allocated at 
offset 4 MiB (1)
   13 [ 3866624]  512/ 4088448 sectors allocated at 
offset 4 MiB (1)
   14 [ 4128768]  128/ 4087936 sectors allocated at 
offset 4 MiB (1)
   15 [ 4194304]  128/ 4087808 sectors allocated at 
offset 4 MiB (1)
   16 [ 4259840]  128/ 4087680 sectors allocated at 
offset 4 MiB (1)
   17 [ 4325376]  128/ 4087552 sectors allocated at 
offset 4 MiB (1)
   18 [ 4390912]  128/ 4087424 sectors allocated at 
offset 4 MiB (1)
   19 [ 4456448]  128/ 4087296 sectors allocated at 
offset 4 MiB (1)
   20 [ 4521984]  128/ 4087168 sectors allocated at 
offset 4 MiB (1)
   21 [ 4587520]  128/ 4087040 sectors allocated at 
offset 4 MiB (1)
   22 [ 4653056]  128/ 4086912 sectors allocated at 
offset 4 MiB (1)
   23 [ 4718592]  128/ 4086784 sectors allocated at 
offset 4 MiB (1)
   24 [ 4784128]  640/ 4086656 sectors allocated at 
offset 5 MiB (1)
   25 [ 5111808]  128/ 4086016 sectors allocated at 
offset 5 MiB (1)
   26 [ 5177344]  128/ 4085888 sectors allocated at 
offset 5 MiB (1)
   27 [ 5242880] 4096/ 4085760 sectors not allocated at 
offset 5 MiB (0)
   28 [ 7340032]  128/ 4081664 sectors allocated at 
offset 7 MiB (1)
   29 [ 7405568]  128/ 4081536 sectors allocated at 
offset 7 MiB (1)
   30 [ 7471104]  128/ 4081408 sectors allocated at 
offset 7 MiB (1)


the first 30lines output from modify image:
  1 [   0]  128/ 4096000 sectors allocated at 
offset 0.00 bytes (1)
  2 [   65536] 1920/ 4095872 sectors not allocated at 
offset 64 KiB (0)
  3 [ 1048576]  512/ 4093952 sectors allocated at 
offset 1 MiB (1)
  4 [ 1310720]  256/ 4093440 sectors not allocated at 
offset 1 MiB (0)
  5 [ 1441792]  128/ 4093184 sectors allocated at 
offset 1 MiB (1)
  6 [ 1507328] 1792/ 4093056 sectors not allocated at 
offset 1 MiB (0)
  7 [ 2424832]  128/ 4091264 sectors allocated at 
offset 2 MiB (1)
  8 [ 2490368] 2560/ 4091136 sectors not allocated at 
offset 2 MiB (0)
  9 [ 3801088] 2816/ 4088576 sectors allocated at 
offset 4 MiB (1)
 10 [ 5242880] 4096/ 4085760 sectors not allocated at 
offset 5 MiB (0)
 11 [ 7340032] 4224/ 4081664 sectors allocated at 
offset 7 MiB (1)
 12 [ 9502720]  128/ 4077440 sectors not allocated at 
offset 9 MiB (0)
 13 [ 9568256]  896/ 4077312 sectors allocated at 
offset 9 MiB (1)
 14 [10027008]  896/ 4076416 sectors not allocated at 
offset 10 MiB (0)
 15 [10485760] 8320/ 4075520 sectors allocated at 
offset 10 MiB (1)
 16 [14745600] 1920/ 4067200 sectors not allocated at 
offset 14 MiB (0)
 17 [15728640] 4480/ 4065280 sectors allocated at 
offset 15 MiB (1)
 18 [18022400]16000/ 4060800 sectors not allocated at 
offset 17 MiB (0)
 19 [26214400]  128/ 4044800 sectors allocated at 
offset 25 MiB (1)
 20 [26279936]12160/ 4044672 sectors not allocated at 
offset 25 MiB (0)
 21 [32505856]12416/ 4032512 sectors allocated at 
offset 31 MiB (1)
 22 [38862848] 3840/ 4020096 sectors not allocated at 
offset 37 MiB (0)
 23 [40828928] 

Re: [Qemu-devel] [PATCH 1/3 resend v2] savevm: add comments for qemu_file_get_error()

2013-09-11 Thread Juan Quintela
Lei Li  wrote:
> Add comments for qemu_file_get_error(), as its return value
> is not very clear.
>
> Signed-off-by: Lei Li 

Reviewed-by: Juan Quintela 



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Gerd Hoffmann
On Mi, 2013-09-11 at 09:20 +0100, Peter Maydell wrote:
> On 11 September 2013 09:01, Gerd Hoffmann  wrote:
> > On Mi, 2013-09-11 at 09:41 +0200, Paolo Bonzini wrote:
> >> It looks like TARGET_PAGE_SIZE is the only reason why qxl is built
> >> per-target, and in qxl_ram_set_dirty it should be enough to do
> >>
> >> qxl_set_dirty(&qxl->vga.vram, offset, offset + 1);
> >>
> >> Would it be fine to use a generic 4096 constant everywhere else?
> >
> > Yes.  Maybe s/TARGET_PAGE_SIZE/QXL_PAGE_SIZE/ to make clear that qxl
> > operates on 4k pages.
> 
> Does this mean that the code was previously wrong for targets
> which didn't have 4K pages, or would we just have been a bit
> inefficient? I ask because ARM's TARGET_PAGE_SIZE is 1K...

Hmm.  There are three places where TARGET_PAGE_SIZE is used.

 (1) Dirtying.  The page dirtying would be just a bit inefficient
 (range is larger than it needs to be).
 (2) rom_size.  Just needs be cleaned up, is hard-coded to 8192 anyway,
 no need at all to look at the page size.
 (3) rom->num_pages field.  That one will change for arm.  The linux
 kernel qxl kms driver seems not to care at all.  Not surprising,
 it is more convenient to use the offsets in the rom to figure how
 the qxl memory layout looks like.

I still think it is better to go for a fixed page size.  Real hardware
doesn't adapt to the target page size too.  ehci for example operates on
4k pages no matter what, and arm then has to care to allocate 4 1k pages
in a row for usb xfers.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 3/3 resend v2] arch_init: right return for ram_save_iterate

2013-09-11 Thread Juan Quintela
Lei Li  wrote:
> qemu_file_rate_limit() never return negative value since the refactor
> by Commit 1964a39, this patch gets rid of the negative check for it,
> adjust bytes_transferred and return value correspondingly in 
> ram_save_iterate().
>
> Signed-off-by: Lei Li 
> Signed-off-by: Paolo Bonzini 
> ---
>
> Change since v1:
>   Return fixes and improvement from Paolo Bonzini.
>   
>  arch_init.c |   15 ++-
>  1 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index 94d45e1..a26bc89 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -709,15 +709,20 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>   */
>  ram_control_after_iterate(f, RAM_CONTROL_ROUND);
>  
> +bytes_transferred += total_sent;

Agreed.

> +
> +/*
> + * Do not count these 8 bytes into total_sent, so that we can
> + * return 0 if no page had been dirtied.
> + */
> +qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
> +bytes_transferred += 8;
> +
> +ret = qemu_file_get_error(f);
>  if (ret < 0) {

Not sure this is the right solution.

We are sending anyways RAM_SAVE_FLAG_EOS.

And I think that the right solution is make qemu_get_rate_limit() to
return -1 in case of error (or the error, I don't care).  Looking at the
callers:


migration.c::migration_thread()

we check for error when we qemu_file_rate_limit() returns != 0.  Well.

second call:

if (qemu_file_rate_limit(s->file)) {
/* usleep expects microseconds */
g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
}


if should be:

if (qemu_file_rate_limit(s->file) == 1)

block_migration: not correct, we don't check for the error.

arch_init.c:

   check is correct, but we need to return -ERROR in case of errors.

hw/ppc/spapr.c:
   will work correctly even if changed to -ERROR.


savevm.c: qemu_savevm_state_iterate()


if (qemu_file_rate_limit(f)) {
return 0;
}


check is incorrect again, we should return an error if there is one
error.


I think that returning qemu_rate_limit() to return 0/1/negative makes sense.

Thoughts?

Thanks, Juan.



Re: [Qemu-devel] Disabling IRQ error

2013-09-11 Thread Max Filippov
On Wed, Sep 11, 2013 at 12:12 PM, Xie Xianshan  wrote:
>   I want to add a new device "fpga" for e500, and trigger an interrupt IRQ3
> while the register BB_INTR_REG which belongs to device "fpga" is wrote by
> the device driver of "fpga".
>   For e500, IRQ3 is an external interrupt irq.
>   According the debug log, the disabling error is encoutered during writing
> BB_INTR_REG register.
>   - write BB_INTR_REG register
>   - qemu_irq_raise() is called.
>   - after serval minutes,
> the error message about disabling irq is displayed.
>   - continue the next execution without error(with poll?)

So your device raises IRQ, but it doesn't lower it. Real devices
usually don't do that, they either generate a short pulse on the
IRQ line (in case of edge-triggered IRQ) or raise IRQ line on
some event and then lower it on a command from its driver
(level-triggered IRQ).

You can do the following to make your device behave that way:
- make your fpga device capable of lowering its IRQ, e.g. by adding
  another register:

> static void fpga_write(FPGAState *s, unsigned int offset, uint32_t value,
> unsigned size) {
> switch(offset) {
> case BB_INTR_REG:
> qemu_irq_raise(s->irq);
> break;
   case BB_INTC_REG:
   qemu_irq_lower(s->irq);
   break;
> }
> }

- provide an interrupt service routine in the linux driver for your fpga
  device that would check whether the interrupt was caused by its
  device, and if so lower the device's IRQ.

Thanks.
-- Max



Re: [Qemu-devel] [PATCH 3/3 resend v2] arch_init: right return for ram_save_iterate

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 11:17, Juan Quintela ha scritto:
> Lei Li  wrote:
>> qemu_file_rate_limit() never return negative value since the refactor
>> by Commit 1964a39, this patch gets rid of the negative check for it,
>> adjust bytes_transferred and return value correspondingly in 
>> ram_save_iterate().
>>
>> Signed-off-by: Lei Li 
>> Signed-off-by: Paolo Bonzini 
>> ---
>>
>> Change since v1:
>>   Return fixes and improvement from Paolo Bonzini.
>>   
>>  arch_init.c |   15 ++-
>>  1 files changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index 94d45e1..a26bc89 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -709,15 +709,20 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>>   */
>>  ram_control_after_iterate(f, RAM_CONTROL_ROUND);
>>  
>> +bytes_transferred += total_sent;
> 
> Agreed.
> 
>> +
>> +/*
>> + * Do not count these 8 bytes into total_sent, so that we can
>> + * return 0 if no page had been dirtied.
>> + */
>> +qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
>> +bytes_transferred += 8;
>> +
>> +ret = qemu_file_get_error(f);
>>  if (ret < 0) {
> 
> Not sure this is the right solution.
> 
> We are sending anyways RAM_SAVE_FLAG_EOS.

If there is an error, the qemu_put_be64 will do nothing.  It is part of
the design of QEMUFile that you can keep sending stuff to it after an
error happened.

> And I think that the right solution is make qemu_get_rate_limit() to
> return -1 in case of error (or the error, I don't care).

You might do both things, it would avoid the useless g_usleep you
pointed out below.  But Lei's patch is good, because an error could
happen exactly during the qemu_put_be64 that writes RAM_SAVE_FLAG_EOS.

> savevm.c: qemu_savevm_state_iterate()
> 
> if (qemu_file_rate_limit(f)) {
> return 0;
> }
> 
> check is incorrect again, we should return an error if there is one
> error.

Nothing cares if qemu_savevm_state_iterate returns 0 or negative, so
changing qemu_savevm_state_iterate to only return 0/1 would make sense too.

Paolo


> 
> I think that returning qemu_rate_limit() to return 0/1/negative makes sense.
> 
> Thoughts?
> 
> Thanks, Juan.
> 




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

2013-09-11 Thread Michael S. Tsirkin
On Sun, Jul 28, 2013 at 01:22:57AM +0200, Andreas Färber wrote:
> Am 26.07.2013 14:19, schrieb Andreas Färber:
> > Am 25.07.2013 18:19, schrieb Michael S. Tsirkin:
> >> On Thu, Jul 25, 2013 at 05:50:55PM +0200, Andreas Färber wrote:
> >>> Am 24.07.2013 18:01, schrieb Michael S. Tsirkin:
>  This code can also be found here:
>  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git acpi
> 
>  Please review, and consider for 1.6.
> >>>
> >>> Quite frankly, this is still not looking the way I imagined it based on
> >>> the KVM call discussion and Anthony's comments that I remember:
> >>>
> >>> I believe Anthony asked to extract the information from the QOM tree,
> >>> originally from the SeaBIOS side, then later agreeing to do it on the
> >>> QEMU side.
> >>>
> >>> However here I am still seeing *functions* added in device code to check
> >>> device existence and to extract individual fields. I was assuming (and
> >>> clearly prefer) such code to live in a central place, be it acpi-build.c
> >>> or something else, and to use QOM *API*s to obtain information when
> >>> needed rather than building up lots of new structs duplicating that
> >>> data. That would at the same time be a test case for how useful the QOM
> >>> tree is
> >>>
> >>> I'm not sure if there was a misunderstanding or whether the PC QOM model
> >>> still sucks^W is incomplete? Anthony and Ping Fang(?) had both posted
> >>> patches to improve the composition tree once. If there's properties
> >>> missing that you need to access for ACPI, we should simply add them.
> >>> For i440fx we have /machine/i440fx.
> >>> For q35 I encountered an mch child on q35-pcihost, but what's trivially
> >>> missing apparently is to add q35-pcihost as a child to /machine, e.g.
> >>> /machine/q35.
> >>> Then you'll end up doing
> >>> Object *obj = object_resolve_path_component(qdev_get_machine(), 
> >>> "q35/mch");
> >>> object_property_get_int(obj, "foo", &err);
> >>> object_property_get_string(obj, "bar", &err);
> >>> and so on. No need to do the TYPE_... based search for everything.
> >>>
> >>> User-added -devices will show up in /machine/peripheral or
> >>> /machine/peripheral-anon depending on whether id= is used, so there a
> >>> type-based search probably makes sense. And there is nothing wrong with
> >>> moving the TYPE_* constants to a device header where not yet the case,
> >>> to allow that from generic code.
> >>>
> >>> Similarly, please don't open-code OBJECT_CHECK()s, do a trivial patch
> >>> with a macro that we can then reuse elsewhere. I'd be happy to review
> >>> such QOM patches and help fast-track them into master.
> >>>
> >>> Will take a closer look at the implementation later.
> >>
> >> This is not my understanding of previous comments on list
> >> or on KVM call.
> >>
> >> Basically it sounds like you want to make my work depend on completion
> >> of QOM conversion.
> >> I think we explicitly agreed full QOM convertion is not a blocker.
> > 
> > Not sure what you mean with "completion of QOM conversion" or "full QOM
> > conversion". What I am saying is that instead of spending time adding
> > functions to devices that fulfill your own ACPI needs only, that time
> > were better spent adding QOM properties where not yet existent.
> > 
> > Because then what you can access for ACPI can also be accessed by
> > libvirt and other management tools as well as qtest - I consider it a
> > test case. QMP does not offer an instance/path search by type.
> 
> To clarify for everyone what we're talking about here, I'm attaching
> /machine composition tree dumps for pc,accel=kvm and q35,accel=kvm plus
> the rudimentary script I used to generate it.
> 
> It shows for instance the mentioned /machine/i440fx and lack of
> /machine/q35. It also shows that there would be a /machine/fw_cfg.
> 
> Paths starting with /machine/unassigned shouldn't be hardcoded anywhere
> (that's the nobody-added-it-as-a-child<> bucket), except maybe for
> /machine/unassigned/sysbus. But whenever there's a link from a named
> device to a /machine/unassigned/device[n] that may of course be used
> dynamically, e.g. /machine/icc-bridge/icc to discover CPUs and APICs.
> 
> HTH,
> Andreas

So q35 is all "unassigned".
I assume it's fine to use APIs for that, then?

-- 
MST



Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Peter Maydell
On 11 September 2013 09:56, Gerd Hoffmann  wrote:
> On Mi, 2013-09-11 at 09:20 +0100, Peter Maydell wrote:
>> Does this mean that the code was previously wrong for targets
>> which didn't have 4K pages, or would we just have been a bit
>> inefficient? I ask because ARM's TARGET_PAGE_SIZE is 1K...
>
> Hmm.  There are three places where TARGET_PAGE_SIZE is used.
>
>  (1) Dirtying.  The page dirtying would be just a bit inefficient
>  (range is larger than it needs to be).
>  (2) rom_size.  Just needs be cleaned up, is hard-coded to 8192 anyway,
>  no need at all to look at the page size.
>  (3) rom->num_pages field.  That one will change for arm.  The linux
>  kernel qxl kms driver seems not to care at all.  Not surprising,
>  it is more convenient to use the offsets in the rom to figure how
>  the qxl memory layout looks like.

Note that the ARM Linux *kernel* will (probably) be using 4K pages
anyway. It's just that QEMU's TARGET_PAGE_SIZE means "smallest
page size this CPU family could possibly support", which for ARM
is 1K, even if 99.9% of guests won't use 1K pages. This is one
of the reasons it's not very useful for devices -- it's almost just
an internal implementation detail of QEMU's TLB/memory system.

What is the num_pages field supposed to mean, given that
"page size" isn't a well defined platform independent value
(for hardware or for QEMU)?

> I still think it is better to go for a fixed page size.  Real hardware
> doesn't adapt to the target page size too.  ehci for example operates on
> 4k pages no matter what, and arm then has to care to allocate 4 1k pages
> in a row for usb xfers.

I agree that devices should not (in general) be using
TARGET_PAGE_SIZE, not least because it has an odd and
not entirely obvious meaning (see above).

-- PMM



Re: [Qemu-devel] [PATCH v3] libxl: usb2 and usb3 controller support for upstream qemu

2013-09-11 Thread Fabio Fantoni

Il 14/08/2013 12:30, Fabio Fantoni ha scritto:

Il 18/07/2013 14:35, Paolo Bonzini ha scritto:

Il 18/07/2013 14:31, Andreas Färber ha scritto:

I'm just curious, why is this so complicated?  Is this likely to be
fragile and break in the future?

As pointed out previously, the bus=pci.0 bit will break with different
PCI host bridges, such as the q35 machine existing today (-M q35 uses
pcie.0 instead and it has been discussed to make q35 the default at 
some

point). I had thus suggested to use a variable for the bus name to
abstract it. For -M pc-i440fx-1.5 etc. pci.0 should continue to work.

I think if we ever made a PCIe machine the default, it would be
different from what today's q35.  In particular it probably should
include a default DMI-to-PCI bridge, so as to make the command line
compatible with i440FX-based machines.

Paolo


FWIK q35 is not supported now on xen.
Anyone on this?

Based on Anthony Liguori reply the usb2 hardcoded parameter should be 
stable and will be supported in future:

http://lists.xen.org/archives/html/xen-devel/2013-07/msg01692.html

There is also reply of Ian Jackson:
http://lists.xen.org/archives/html/xen-devel/2013-07/msg01702.html

I had also posted v4 of patch:
http://lists.xen.org/archives/html/xen-devel/2013-07/msg01101.html


Reposted the tests results:

Tested on linux domU (ubuntu 12.04 64 bit) with usb redirection:
- with usb1 and usb2 working and no problem found.

- with usb3 linux sees the usb3 controller but usbredirection not 
working (tested with qemu 1.3 of xen-unstable)


Tested on windows 7 pro 64 bit domU with usb redirection:

- with usb1 not working, windows sees the usb devices (flash mass 
storage) with error (unable to start device, code 10); seems

windows bugs.

- with usb2 working and no problem found.

- with usb3 not working, windows sees the usb controller but 
usbredirection is not working (tested with qemu 1.3 of xen-unstable)


About usb3 seems that qemu does not support some functionalities for now.

Qemu log on usb3 test:
xhci_cap_read: reg 2 unimplemented
xhci: unimplemented command 52
xhci: ERDP out of bounds: 7e7d5000
xhci: ER[7] at 0 len 0
xhci: asserted controller error
xhci: ERDP out of bounds: 7eace000
xhci: ER[6] at 0 len 0
xhci: asserted controller error
...
xhci: slot 1 has no device
xhci: error firing data transfer



There wasn't any reply about this for one month. usb1 controller is 
already supported by xen but it has some problems with latest windows. 
usb2 works with both linux and windows but it needs this patch or a 
similar one to add support on xen. usb3 can be removed for now if 
someone think unimplemented functions are a problem.

Thanks for any reply.


Ping



Re: [Qemu-devel] [PATCH v3] libxl: usb2 and usb3 controller support for upstream qemu

2013-09-11 Thread Ian Campbell
On Wed, 2013-09-11 at 12:14 +0200, Fabio Fantoni wrote:
> Ping

Is this directed and Xen or qmeu folks?

What are the outstanding questions which need to be answered?

It doesn't look to me like Ian's concerns from the (great?) grandparent
have been addressed? On the other hand I appear to be missing some of
the mails in this thread.

Ian.





Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Gerd Hoffmann
> >  (3) rom->num_pages field.  That one will change for arm.  The linux
> >  kernel qxl kms driver seems not to care at all.  Not surprising,
> >  it is more convenient to use the offsets in the rom to figure how
> >  the qxl memory layout looks like.
> 
> Note that the ARM Linux *kernel* will (probably) be using 4K pages
> anyway. It's just that QEMU's TARGET_PAGE_SIZE means "smallest
> page size this CPU family could possibly support", which for ARM
> is 1K, even if 99.9% of guests won't use 1K pages. This is one
> of the reasons it's not very useful for devices -- it's almost just
> an internal implementation detail of QEMU's TLB/memory system.
> 
> What is the num_pages field supposed to mean, given that
> "page size" isn't a well defined platform independent value
> (for hardware or for QEMU)?

It's 4k on x86 and not really defined on !x86 (with the !x86 installed
base being pretty close to zero).

I think we should just define it to be 4k everywhere.

cheers,
  Gerd






Re: [Qemu-devel] [PATCH v2] e1000: NetClientInfo.receive_iov implemented

2013-09-11 Thread Vincenzo Maffione
Thanks for the help!

Actually I've found out that the variable "copied" I use in this patch can
be removed, we can simply increment the variable "ba" instead (ba +=
iov_copy).

I have the patch v3 to do that ready. Do you think it is worth sending it?


Best regards,
  Vincenzo


2013/9/11 Stefan Hajnoczi 

> On Tue, Sep 10, 2013 at 02:19:47PM +0200, Vincenzo Maffione wrote:
> > This patch implements the NetClientInfo.receive_iov method for the
> > e1000 device emulation. In this way a network backend that uses
> > qemu_sendv_packet() can deliver the fragmented packet without
> > requiring an additional copy in the frontend/backend network code
> > (nc_sendv_compat() function).
> >
> > The existing method NetClientInfo.receive has been reimplemented
> > using the new method.
> >
> > Signed-off-by: Vincenzo Maffione 
> > ---
> >  hw/net/e1000.c | 71
> --
> >  1 file changed, 59 insertions(+), 12 deletions(-)
> >
> > I propose this patch also because our research group (University of Pisa,
> > Department of Computer Engineering) is working on the e1000 device
> > (optimizations and paravirtual extensions) and we have patches to
> > support the VALE switch as a network backend (see
> > http://info.iet.unipi.it/~luigi/vale/).
> > The VALE backend uses qemu_sendv_packet() to send fragmented packets: For
> > this reason we think it could be interesting to better support these
> packets
> > with e1000.
>
> Thanks, applied to my net tree:
> https://github.com/stefanha/qemu/commits/net
>
> Stefan
>



-- 
Vincenzo Maffione


Re: [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules

2013-09-11 Thread Peter Maydell
On 11 September 2013 11:37, Gerd Hoffmann  wrote:
>> What is the num_pages field supposed to mean, given that
>> "page size" isn't a well defined platform independent value
>> (for hardware or for QEMU)?
>
> It's 4k on x86 and not really defined on !x86 (with the !x86 installed
> base being pretty close to zero).
>
> I think we should just define it to be 4k everywhere.

Yeah, if you're just using it as a "we didn't want a 64 bit
field so we could make this a simple byte count" then
saying "it's in units of 4K" is the simplest fix.

-- PMM



Re: [Qemu-devel] [PATCH 3/3 resend v2] arch_init: right return for ram_save_iterate

2013-09-11 Thread Juan Quintela
Paolo Bonzini  wrote:
> Il 11/09/2013 11:17, Juan Quintela ha scritto:
>> Lei Li  wrote:
>>> qemu_file_rate_limit() never return negative value since the refactor
>>> by Commit 1964a39, this patch gets rid of the negative check for it,
>>> adjust bytes_transferred and return value correspondingly in 
>>> ram_save_iterate().
>>>
>>> Signed-off-by: Lei Li 
>>> Signed-off-by: Paolo Bonzini 
>>> ---
>>>
>>> Change since v1:
>>>   Return fixes and improvement from Paolo Bonzini.
>>>   
>>>  arch_init.c |   15 ++-
>>>  1 files changed, 10 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/arch_init.c b/arch_init.c
>>> index 94d45e1..a26bc89 100644
>>> --- a/arch_init.c
>>> +++ b/arch_init.c
>>> @@ -709,15 +709,20 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>>>   */
>>>  ram_control_after_iterate(f, RAM_CONTROL_ROUND);
>>>  
>>> +bytes_transferred += total_sent;
>> 
>> Agreed.
>> 
>>> +
>>> +/*
>>> + * Do not count these 8 bytes into total_sent, so that we can
>>> + * return 0 if no page had been dirtied.
>>> + */
>>> +qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
>>> +bytes_transferred += 8;
>>> +
>>> +ret = qemu_file_get_error(f);
>>>  if (ret < 0) {
>> 
>> Not sure this is the right solution.
>> 
>> We are sending anyways RAM_SAVE_FLAG_EOS.
>
> If there is an error, the qemu_put_be64 will do nothing.  It is part of
> the design of QEMUFile that you can keep sending stuff to it after an
> error happened.
>
>> And I think that the right solution is make qemu_get_rate_limit() to
>> return -1 in case of error (or the error, I don't care).
>
> You might do both things, it would avoid the useless g_usleep you
> pointed out below.  But Lei's patch is good, because an error could
> happen exactly during the qemu_put_be64 that writes RAM_SAVE_FLAG_EOS.


Caller checks also.  This is the reason I wanted qemu_file_* callos to
return an error.  It has some advantages and some disadvantages.  We
don't agree on which ones are bigger O:-)

>
>> savevm.c: qemu_savevm_state_iterate()
>> 
>> if (qemu_file_rate_limit(f)) {
>> return 0;
>> }
>> 
>> check is incorrect again, we should return an error if there is one
>> error.
>
> Nothing cares if qemu_savevm_state_iterate returns 0 or negative, so
> changing qemu_savevm_state_iterate to only return 0/1 would make sense too.

In this case, 0 means:
  please, call us again
when what we mean is:
  don't care about calling us again, there is an error.  Handle the error.

Notice that qemu_save_iterate() already returns errors in other code
paths, not there because it don't know, code should be:

ret = qemu_file_rate_limit(f))

if (ret == 1) {
   return 0;
} else if (ret < 0) {
   return ret;
}

If we change th ereturn value for qemu_file_rate_limit() the change that
cames with this patch is not needed, that was my point.

>
> Paolo
>
>
>> 
>> I think that returning qemu_rate_limit() to return 0/1/negative makes sense.
>> 
>> Thoughts?
>> 
>> Thanks, Juan.
>> 



Re: [Qemu-devel] [PATCH 3/3 resend v2] arch_init: right return for ram_save_iterate

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 13:06, Juan Quintela ha scritto:
>>> And I think that the right solution is make qemu_get_rate_limit() to
>>> return -1 in case of error (or the error, I don't care).
>>
>> You might do both things, it would avoid the useless g_usleep you
>> pointed out below.  But Lei's patch is good, because an error could
>> happen exactly during the qemu_put_be64 that writes RAM_SAVE_FLAG_EOS.
> 
> Caller checks also.  This is the reason I wanted qemu_file_* callers to
> return an error.  It has some advantages and some disadvantages.  We
> don't agree on which ones are bigger O:-)

I think the disadvantages are bigger.  It litters the code with error
handling, hides where things actually happen, and doesn't even simplify
QEMUFile itself.  Checking only at the toplevel is simpler, all we need
to do is ensure that we get there every now and then (and that's what
qemu_file_rate_limit does).

>>> savevm.c: qemu_savevm_state_iterate()
>>>
>>> if (qemu_file_rate_limit(f)) {
>>> return 0;
>>> }
>>>
>>> check is incorrect again, we should return an error if there is one
>>> error.
>>
>> Nothing cares if qemu_savevm_state_iterate returns 0 or negative, so
>> changing qemu_savevm_state_iterate to only return 0/1 would make sense too.
> 
> In this case, 0 means:
>   please, call us again
> when what we mean is:
>   don't care about calling us again, there is an error.  Handle the error.

Or alternatively, 0 means:

   we haven't finished the work

when what we mean is:

   we haven't finished the work (BTW, please check if there is an error)

> Notice that qemu_save_iterate() already returns errors in other code
> paths

Yes that's also unnecessary.

> If we change th ereturn value for qemu_file_rate_limit() the change that
> cames with this patch is not needed, that was my point.

This is what an earlier patch from Lei did.  I told him (or her?) to
leave qemu_file_rate_limit aside since the idea behind QEMUFile is to
only handle the error at the top.

Paolo



[Qemu-devel] [PATCH 3/4] qxl: simplify page dirtying

2013-09-11 Thread Gerd Hoffmann
No need to do target page size calculations here,
memory_region_set_dirty will care for us.

Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index bcbf97a..ee2db0d 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -414,9 +414,8 @@ static void qxl_ram_set_dirty(PCIQXLDevice *qxl, void *ptr)
 intptr_t offset;
 
 offset = ptr - base;
-offset &= ~(TARGET_PAGE_SIZE-1);
 assert(offset < qxl->vga.vram_size);
-qxl_set_dirty(&qxl->vga.vram, offset, offset + TARGET_PAGE_SIZE);
+qxl_set_dirty(&qxl->vga.vram, offset, offset + 3);
 }
 
 /* can be called from spice server thread context */
-- 
1.8.3.1




[Qemu-devel] [PATCH 1/4] qxl: define qxl operating on 4k pages

2013-09-11 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl.c | 5 +++--
 hw/display/qxl.h | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index c50e285..f0bfd2c 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -364,7 +364,7 @@ static void init_qxl_rom(PCIQXLDevice *d)
 num_pages  = d->vga.vram_size;
 num_pages -= ram_header_size;
 num_pages -= surface0_area_size;
-num_pages  = num_pages / TARGET_PAGE_SIZE;
+num_pages  = num_pages / QXL_PAGE_SIZE;
 
 rom->draw_area_offset   = cpu_to_le32(0);
 rom->surface0_area_size = cpu_to_le32(surface0_area_size);
@@ -528,7 +528,8 @@ static void interface_get_init_info(QXLInstance *sin, 
QXLDevInitInfo *info)
 info->num_memslots = NUM_MEMSLOTS;
 info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
 info->internal_groupslot_id = 0;
-info->qxl_ram_size = le32_to_cpu(qxl->shadow_rom.num_pages) << 
TARGET_PAGE_BITS;
+info->qxl_ram_size =
+le32_to_cpu(qxl->shadow_rom.num_pages) << QXL_PAGE_BITS;
 info->n_surfaces = qxl->ssd.num_surfaces;
 }
 
diff --git a/hw/display/qxl.h b/hw/display/qxl.h
index 8e9b0c2..84f0182 100644
--- a/hw/display/qxl.h
+++ b/hw/display/qxl.h
@@ -27,6 +27,9 @@ enum qxl_mode {
 
 #define QXL_NUM_DIRTY_RECTS 64
 
+#define QXL_PAGE_BITS 12
+#define QXL_PAGE_SIZE (1 << QXL_PAGE_BITS);
+
 typedef struct PCIQXLDevice {
 PCIDevice  pci;
 SimpleSpiceDisplay ssd;
-- 
1.8.3.1




[Qemu-devel] [PATCH 2/4] qxl: simplify qxl_rom_size

2013-09-11 Thread Gerd Hoffmann
Nowdays rom size is fixed at 8192 for live migration compat reasons.
So we can ditch the pointless math trying to calculate the size needed.
Also make the size sanity check fail at compile time not runtime.

Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index f0bfd2c..bcbf97a 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -313,9 +313,7 @@ static ram_addr_t qxl_rom_size(void)
  sizeof(qxl_modes);
 uint32_t rom_size = 8192; /* two pages */
 
-required_rom_size = MAX(required_rom_size, TARGET_PAGE_SIZE);
-required_rom_size = msb_mask(required_rom_size * 2 - 1);
-assert(required_rom_size <= rom_size);
+QEMU_BUILD_BUG_ON(required_rom_size > rom_size);
 return rom_size;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 4/4] qxl: compile only once

2013-09-11 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/display/Makefile.objs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 6e9fb3b..540df82 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -31,5 +31,4 @@ obj-$(CONFIG_TCX) += tcx.o
 
 obj-$(CONFIG_VGA) += vga.o
 
-common-obj-$(CONFIG_QXL) += qxl-logger.o qxl-render.o
-obj-$(CONFIG_QXL) += qxl.o
+common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v3] libxl: usb2 and usb3 controller support for upstream qemu

2013-09-11 Thread Fabio Fantoni

Il 11/09/2013 12:19, Ian Campbell ha scritto:

On Wed, 2013-09-11 at 12:14 +0200, Fabio Fantoni wrote:

Ping

Is this directed and Xen or qmeu folks?

What are the outstanding questions which need to be answered?

It doesn't look to me like Ian's concerns from the (great?) grandparent
have been addressed? On the other hand I appear to be missing some of
the mails in this thread.

Ian.




I quoted the complete mail:
http://lists.xen.org/archives/html/xen-devel/2013-08/msg01425.html

The ping was directed to xen-devel, I added qemu-devel to get some 
definite answers about qemu hardcoded parameters on which you have doubts.
There were answers from qemu developersand after also positive reply 
from Ian Jackson.
I did a v4 of this patch with the missed advices but no more replies 
after qemu parameters question that seems solved on this old thread.


All details are on mail linked above.

Thanks for any reply and sorry for my bad english.



Re: [Qemu-devel] [PATCH] qdev: rename qdev_free() to qdev_unparent()

2013-09-11 Thread Stefan Hajnoczi
On Wed, Sep 11, 2013 at 10:23 AM, Andreas Färber  wrote:
> Am 11.09.2013 09:45, schrieb Stefan Hajnoczi:
>> diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
>> index 619fe47..f197f5f 100644
>> --- a/hw/pci/pci-hotplug-old.c
>> +++ b/hw/pci/pci-hotplug-old.c
>> @@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
>>  }
>>  dev = pci_create(bus, devfn, "virtio-blk-pci");
>>  if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
>> -qdev_free(&dev->qdev);
>> +qdev_unparent(&dev->qdev);
>
> This should be DEVICE(dev), making most callers outside qdev.c do a cast
> after all.
>
> Also we should name the function device_unparent if we decide to keep it
> around.

This is true.  We should probably just use object_unref(OBJECT(foo)) everywhere.

I'll drop qdev_free() completely and resend.

Stefan



[Qemu-devel] [Bug 1222034] Re: QEMU + SPICE + AUDIO = FAILURE

2013-09-11 Thread will
That above example is from a debian x64 guest.

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

Title:
  QEMU + SPICE + AUDIO = FAILURE

Status in QEMU:
  New

Bug description:
  Hello it's my first time doing this, since the major round of
  timer/block changes in August I have not been able to have audio
  working in any guest with the spice protocol.

  64 bit linux , AMD SVM, IOMMUv1  ASUS M5A99FX PRO R2.0

  Example command line:

  qemu-system-x86_64 -m 1024 -cdrom Sabayon_Linux_DAILY_x86_Xfce.iso
  -soundhw hda -vga qxl -spice port=5999,addr=0.0.0.0,disable-ticketing
  -enable-kvm -device virtio-serial-pci -device
  virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev
  spicevmc,id=spicechannel0,name=vdagent

  Any time the guest tries to access the emulated hardware it will hang
  for a very long period of time and play no audio through spice. It
  doesn't seem to matter what guest (x86_64 or x86) I run (the above is
  just one example) and it also doesn't matter what sound hardware I
  choose to emulate or which command line method I use to specify it (ie
  -soundhw doesn't work and neither does -device) or whether a vdagent
  service has been configured correctly inside the guest or not.

  This issue does not happen with the 1.6.0 release.

  If you are unable to replicate this I will go to the trouble of
  getting the race message that happens in the guest but I am assuming
  at this point that my configuration is not exotic and it should be
  very easy to see the issue.

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



[Qemu-devel] [Bug 1222034] Re: QEMU + SPICE + AUDIO = FAILURE

2013-09-11 Thread will
Here is the dmesg that occurs inside the guest using any recent qemu
upstream build for me:

[  248.943541] input: spice vdagent tablet as /devices/virtual/input/input6
[  677.164385] input: spice vdagent tablet as /devices/virtual/input/input7
[183308.532032] INFO: rcu_sched self-detected stall on CPU { 1}  (t=22338 
jiffies g=1183551 c=1183550 q=30)
[183308.532032] sending NMI to all CPUs:
[183308.532032] NMI backtrace for cpu 1
[183308.532032] CPU: 1 PID: 2765 Comm: alsa-sink-ID 22 Tainted: GW
3.10-2-amd64 #1 Debian 3.10.7-1
[183308.532032] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
[183308.532032] task: 88007b1a3840 ti: 88007b1b2000 task.ti: 
88007b1b2000
[183308.532032] RIP: 0010:[]  [] 
native_write_msr_safe+0x6/0x9
[183308.532032] RSP: 0018:88007fd03e18  EFLAGS: 0046
[183308.532032] RAX: 0400 RBX: 0001 RCX: 
0830
[183308.532032] RDX: 0001 RSI: 0400 RDI: 
0830
[183308.532032] RBP: b0ca R08: 81693c40 R09: 
814f1e2a
[183308.532032] R10:  R11: 8800 R12: 
0002
[183308.532032] R13: 81693c40 R14: 0001 R15: 
0008
[183308.532032] FS:  7f0cb7b1f700() GS:88007fd0() 
knlGS:
[183308.532032] CS:  0010 DS:  ES:  CR0: 80050033
[183308.532032] CR2: 7f0cbd234000 CR3: 7b3e CR4: 
000406e0
[183308.532032] DR0:  DR1:  DR2: 

[183308.532032] DR3:  DR6: 0ff0 DR7: 
0400
[183308.532032] Stack:
[183308.532032]  8102a739 8102a85c 0086 
2710
[183308.532032]  88007fd0e8e0 8163cd00 88007fd0e2b0 
88007b1b2000
[183308.532032]  0001 8102829b 8163cd00 
810a0a53
[183308.532032] Call Trace:
[183308.532032]  
[183308.532032]  [] ? paravirt_write_msr+0xb/0xe
[183308.532032]  [] ? __x2apic_send_IPI_mask+0x70/0xa5
[183308.532032]  [] ? arch_trigger_all_cpu_backtrace+0x4d/0x7e
[183308.532032]  [] ? rcu_check_callbacks+0x1a4/0x4bb
[183308.532032]  [] ? tick_sched_do_timer+0x25/0x25
[183308.532032]  [] ? update_process_times+0x31/0x5c
[183308.532032]  [] ? tick_sched_handle+0x3e/0x4a
[183308.532032]  [] ? tick_sched_timer+0x30/0x4c
[183308.532032]  [] ? __run_hrtimer+0xac/0x151
[183308.532032]  [] ? hrtimer_interrupt+0xbd/0x19e
[183308.532032]  [] ? smp_apic_timer_interrupt+0x6d/0x7e
[183308.532032]  [] ? apic_timer_interrupt+0x6d/0x80
[183308.532032]  
[183308.532032]  [] ? 
snd_timer_user_append_to_tqueue+0x3f/0x3f [snd_timer]
[183308.532032]  [] ? arch_local_irq_enable+0x4/0x8 [snd_pcm]
[183308.532032]  [] ? snd_pcm_action_lock_irq+0x91/0x9d 
[snd_pcm]
[183308.532032]  [] ? snd_pcm_common_ioctl1+0x3f2/0xaed 
[snd_pcm]
[183308.532032]  [] ? snd_ctl_ioctl+0x2eb/0x65f [snd]
[183308.532032]  [] ? kfree+0x50/0x6f
[183308.532032]  [] ? snd_pcm_playback_ioctl1+0x230/0x24d 
[snd_pcm]
[183308.532032]  [] ? do_filp_open+0x2a/0x6e
[183308.532032]  [] ? snd_pcm_playback_ioctl+0x26/0x29 
[snd_pcm]
[183308.532032]  [] ? vfs_ioctl+0x1b/0x25
[183308.532032]  [] ? do_vfs_ioctl+0x3e8/0x42a
[183308.532032]  [] ? SyS_futex+0x133/0x165
[183308.532032]  [] ? fput+0xe/0xb6
[183308.532032]  [] ? SyS_ioctl+0x4e/0x79
[183308.532032]  [] ? system_call_fastpath+0x16/0x1b
[183308.532032] Code: 0f 01 f9 48 c1 e2 20 89 0f 48 09 c2 48 89 d0 c3 89 f9 0f 
32 31 ff 48 c1 e2 20 89 c0 89 3e 48 09 c2 48 89 d0 c3 89 f0 89 f9 0f 30 <31> c0 
c3 89 f9 0f 33 48 c1 e2 20 89 c0 48 09 c2 48 89 d0 c3 66
[183308.535258] NMI backtrace for cpu 0
[183308.535258] CPU: 0 PID: 0 Comm: swapper/0 Tainted: GW
3.10-2-amd64 #1 Debian 3.10.7-1
[183308.535258] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
[183308.535258] task: 81613400 ti: 8160 task.ti: 
8160
[183308.535258] RIP: 0010:[]  [] 
azx_get_position+0x4d/0x259 [snd_hda_intel]
[183308.535258] RSP: 0018:88007fc03dd8  EFLAGS: 0046
[183308.535258] RAX: c93b8160 RBX: 88007bfd9de8 RCX: 

[183308.535258] RDX:  RSI:  RDI: 
880037287000
[183308.535258] RBP: 1200 R08: 88007cc00050 R09: 
0034
[183308.535258] R10: 0001 R11:  R12: 
880037287000
[183308.535258] R13: 88007b7e4780 R14: 0074 R15: 
88007cad4400
[183308.535258] FS:  7f6045ffd700() GS:88007fc0() 
knlGS:
[183308.535258] CS:  0010 DS:  ES:  CR0: 8005003b
[183308.535258] CR2: 7f1f10013000 CR3: 59a83000 CR4: 
000406f0
[183308.535258] DR0:  DR1:  DR2: 

[183308.535258] DR3:  DR6: 0ff0 DR7: 
0400
[183308.535258] Stack:
[183308.535258]  811bcb21 880037384478 88007cad44

[Qemu-devel] [PATCH v2] qdev: drop misleading qdev_free() function

2013-09-11 Thread Stefan Hajnoczi
The qdev_free() function name is misleading since all the function does
is unlink the device from its parent.  The device is not necessarily
freed.

The device will be freed when its QObject refcount reaches zero.  It is
usual for the parent (bus) to hold the final reference but there are
cases where something else holds a reference so "free" is a misleading
name.

Call object_unparent(obj) directly instead of having a qdev wrapper
function.

Signed-off-by: Stefan Hajnoczi 
---
Based on "[PATCH 0/6] qdev and blockdev refcount leak fixes".

v2:
 * Drop qdev_free() instead of renaming it to qdev_unparent() [afaerber]

 hw/acpi/piix4.c  |  2 +-
 hw/core/qdev.c   | 12 +++-
 hw/pci/pci-hotplug-old.c |  2 +-
 hw/pci/pci_bridge.c  |  2 +-
 hw/pci/pcie.c|  2 +-
 hw/pci/shpc.c|  2 +-
 hw/s390x/virtio-ccw.c|  2 +-
 hw/scsi/scsi-bus.c   |  6 +++---
 hw/usb/bus.c |  7 ---
 hw/usb/dev-storage.c |  2 +-
 hw/usb/host-legacy.c |  2 +-
 hw/virtio/virtio-bus.c   |  4 +---
 hw/xen/xen_platform.c|  2 +-
 include/hw/qdev-core.h   |  1 -
 qdev-monitor.c   |  2 +-
 15 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 0b8d1d9..e9e7d32 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -326,7 +326,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned 
slots)
 if (pc->no_hotplug) {
 slot_free = false;
 } else {
-qdev_free(qdev);
+object_unparent(OBJECT(qdev));
 }
 }
 }
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 533f6dd..e374a93 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
 if (local_err != NULL) {
 qerror_report_err(local_err);
 error_free(local_err);
-qdev_free(dev);
+object_unparent(OBJECT(dev));
 return -1;
 }
 return 0;
@@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
 int qdev_simple_unplug_cb(DeviceState *dev)
 {
 /* just zap it */
-qdev_free(dev);
+object_unparent(OBJECT(dev));
 return 0;
 }
 
@@ -280,12 +280,6 @@ void qdev_init_nofail(DeviceState *dev)
 }
 }
 
-/* Unlink device from bus and free the structure.  */
-void qdev_free(DeviceState *dev)
-{
-object_unparent(OBJECT(dev));
-}
-
 void qdev_machine_creation_done(void)
 {
 /*
@@ -458,7 +452,7 @@ static void bus_unparent(Object *obj)
 
 while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
 DeviceState *dev = kid->child;
-qdev_free(dev);
+object_unparent(OBJECT(dev));
 }
 if (bus->parent) {
 QLIST_REMOVE(bus, sibling);
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 619fe47..8dbc3c1 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -248,7 +248,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 }
 dev = pci_create(bus, devfn, "virtio-blk-pci");
 if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-qdev_free(&dev->qdev);
+object_unparent(OBJECT(dev));
 dev = NULL;
 break;
 }
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index e6b22b8..290abab 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -391,7 +391,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
 pci_bridge_region_cleanup(s, s->windows);
 memory_region_destroy(&s->address_space_mem);
 memory_region_destroy(&s->address_space_io);
-/* qbus_free() is called automatically by qdev_free() */
+/* qbus_free() is called automatically during device deletion */
 }
 
 /*
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 50af3c1..a27acf3 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
PCI_EXP_SLTSTA_PDS);
 pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
 } else {
-qdev_free(&pci_dev->qdev);
+object_unparent(OBJECT(pci_dev));
 pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
  PCI_EXP_SLTSTA_PDS);
 pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index eb092fd..29a8c36 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -254,7 +254,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int 
slot)
  ++devfn) {
 PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
 if (affected_dev) {
-qdev_free(&affected_dev->qdev);
+object_unparent(OBJECT(affected_dev));
 }
 }
 }
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index cd67db5..f93a81c 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1239,7 +1239,7 @@ static int virtio_ccw_busdev_unplug(DeviceState *dev)
 
 css_generate_sch_crws(sc

[Qemu-devel] [RFC 0/4] ARM aarch64 disas output libvixl support

2013-09-11 Thread Claudio Fontana

This is the aarch64 libvixl support patchset in the current state.
It provides (limited) support for disassembly output on aarch64.
Only host disassembly is enabled, since target for aarch64 is not in yet.

An external objdump solution as exemplified before by R.H. seems preferable
to me, even if it means giving up the monitor support.
I'd rather have correct output from -d.
The run time need for debugging assembly is already fulfilled by gdb better
than the monitor.

libvixl does not support many opcodes right now, is C++, and it is documented
as working only for a 64bit host with a LP64 memory model.

Claudio Fontana (4):
  configure: add c++ compiler support
  rules.mak: support C++ compiling and linking
  disas: add libvixl source code for aarch64
  disas: implement host disassembly output for aarch64

 configure|   21 +
 disas.c  |2 +
 disas/Makefile.objs  |7 +
 disas/aarch64-cxx.cc |   53 +
 disas/aarch64.c  |   45 +
 disas/libvixl/LICENCE|   30 +
 disas/libvixl/Makefile.objs  |6 +
 disas/libvixl/README.md  |  128 ++
 disas/libvixl/doc/changelog.md   |   12 +
 disas/libvixl/doc/supported-instructions.md  | 1133 ++
 disas/libvixl/src/a64/assembler-a64.cc   | 2172 ++
 disas/libvixl/src/a64/assembler-a64.h| 1784 +
 disas/libvixl/src/a64/constants-a64.h| 1104 +
 disas/libvixl/src/a64/cpu-a64.cc |  148 ++
 disas/libvixl/src/a64/cpu-a64.h  |   56 +
 disas/libvixl/src/a64/debugger-a64.cc| 1511 ++
 disas/libvixl/src/a64/debugger-a64.h |  188 +++
 disas/libvixl/src/a64/decoder-a64.cc |  712 +
 disas/libvixl/src/a64/decoder-a64.h  |  198 +++
 disas/libvixl/src/a64/disasm-a64.cc  | 1678 
 disas/libvixl/src/a64/disasm-a64.h   |  109 ++
 disas/libvixl/src/a64/instructions-a64.cc|  238 +++
 disas/libvixl/src/a64/instructions-a64.h |  344 
 disas/libvixl/src/a64/instrument-a64.cc  |  638 
 disas/libvixl/src/a64/instrument-a64.h   |  108 ++
 disas/libvixl/src/a64/macro-assembler-a64.cc | 1108 +
 disas/libvixl/src/a64/macro-assembler-a64.h  | 1175 ++
 disas/libvixl/src/a64/simulator-a64.cc   | 2077 
 disas/libvixl/src/a64/simulator-a64.h|  576 +++
 disas/libvixl/src/globals.h  |   66 +
 disas/libvixl/src/platform.h |   43 +
 disas/libvixl/src/utils.cc   |  120 ++
 disas/libvixl/src/utils.h|  126 ++
 include/disas/bfd.h  |1 +
 rules.mak|   24 +-
 35 files changed, 17737 insertions(+), 4 deletions(-)
 create mode 100644 disas/aarch64-cxx.cc
 create mode 100644 disas/aarch64.c
 create mode 100644 disas/libvixl/LICENCE
 create mode 100644 disas/libvixl/Makefile.objs
 create mode 100644 disas/libvixl/README.md
 create mode 100644 disas/libvixl/doc/changelog.md
 create mode 100644 disas/libvixl/doc/supported-instructions.md
 create mode 100644 disas/libvixl/src/a64/assembler-a64.cc
 create mode 100644 disas/libvixl/src/a64/assembler-a64.h
 create mode 100644 disas/libvixl/src/a64/constants-a64.h
 create mode 100644 disas/libvixl/src/a64/cpu-a64.cc
 create mode 100644 disas/libvixl/src/a64/cpu-a64.h
 create mode 100644 disas/libvixl/src/a64/debugger-a64.cc
 create mode 100644 disas/libvixl/src/a64/debugger-a64.h
 create mode 100644 disas/libvixl/src/a64/decoder-a64.cc
 create mode 100644 disas/libvixl/src/a64/decoder-a64.h
 create mode 100644 disas/libvixl/src/a64/disasm-a64.cc
 create mode 100644 disas/libvixl/src/a64/disasm-a64.h
 create mode 100644 disas/libvixl/src/a64/instructions-a64.cc
 create mode 100644 disas/libvixl/src/a64/instructions-a64.h
 create mode 100644 disas/libvixl/src/a64/instrument-a64.cc
 create mode 100644 disas/libvixl/src/a64/instrument-a64.h
 create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.cc
 create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.h
 create mode 100644 disas/libvixl/src/a64/simulator-a64.cc
 create mode 100644 disas/libvixl/src/a64/simulator-a64.h
 create mode 100644 disas/libvixl/src/globals.h
 create mode 100644 disas/libvixl/src/platform.h
 create mode 100644 disas/libvixl/src/utils.cc
 create mode 100644 disas/libvixl/src/utils.h

-- 
1.8.1





[Qemu-devel] [RFC 1/4] configure: add c++ compiler support

2013-09-11 Thread Claudio Fontana

This patch is similar to Tomoki Sekiyama's
[PATCH v9 01/10] configure: Support configuring C++ compile,
with the main differences being:

not using "c++" as default compiler, instead do not enable by default
(requires explicit CXX env, --cxx option  or cross-compilation prefix)

separate CFLAGS and CXXFLAGS in the default way.

Signed-off-by: Claudio Fontana 
---
 configure | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/configure b/configure
index 0a55c20..6b73d99 100755
--- a/configure
+++ b/configure
@@ -252,6 +252,8 @@ for opt do
   ;;
   --cc=*) CC="$optarg"
   ;;
+  --cxx=*) CXX="$optarg"
+  ;;
   --source-path=*) source_path="$optarg"
   ;;
   --cpu=*) cpu="$optarg"
@@ -282,6 +284,12 @@ else
   cc="${CC-${cross_prefix}gcc}"
 fi
 
+if test -z "${CXX}${cross_prefix}"; then
+  cxx=""
+else
+  cxx="${CXX-${cross_prefix}g++}"
+fi
+
 ar="${AR-${cross_prefix}ar}"
 as="${AS-${cross_prefix}as}"
 cpp="${CPP-$cc -E}"
@@ -305,6 +313,7 @@ QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 
-D_LARGEFILE_SOURCE $QEMU_CFLA
 QEMU_INCLUDES="-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include"
 if test "$debug_info" = "yes"; then
 CFLAGS="-g $CFLAGS"
+CXXFLAGS="-g $CXXFLAGS"
 LDFLAGS="-g $LDFLAGS"
 fi
 
@@ -622,6 +631,8 @@ for opt do
   ;;
   --host-cc=*) host_cc="$optarg"
   ;;
+  --cxx=*)
+  ;;
   --objcc=*) objcc="$optarg"
   ;;
   --make=*) make="$optarg"
@@ -1023,6 +1034,7 @@ echo "  --cross-prefix=PREFIXuse PREFIX for compile 
tools [$cross_prefix]"
 echo "  --cc=CC  use C compiler CC [$cc]"
 echo "  --host-cc=CC use C compiler CC [$host_cc] for code run at"
 echo "   build time"
+echo "  --cxx=CXXuse C++ compiler CXX [$cxx]"
 echo "  --objcc=OBJCCuse Objective-C compiler OBJCC [$objcc]"
 echo "  --extra-cflags=CFLAGSappend extra C compiler flags QEMU_CFLAGS"
 echo "  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS"
@@ -3553,6 +3565,7 @@ fi
 echo "Source path   $source_path"
 echo "C compiler$cc"
 echo "Host C compiler   $host_cc"
+echo "C++ compiler  $cxx"
 echo "Objective-C compiler $objcc"
 echo "CFLAGS$CFLAGS"
 echo "QEMU_CFLAGS   $QEMU_CFLAGS"
@@ -4140,6 +4153,7 @@ echo "PYTHON=$python" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 echo "CC_I386=$cc_i386" >> $config_host_mak
 echo "HOST_CC=$host_cc" >> $config_host_mak
+echo "CXX=$cxx" >> $config_host_mak
 echo "OBJCC=$objcc" >> $config_host_mak
 echo "AR=$ar" >> $config_host_mak
 echo "AS=$as" >> $config_host_mak
@@ -4149,6 +4163,7 @@ echo "LD=$ld" >> $config_host_mak
 echo "WINDRES=$windres" >> $config_host_mak
 echo "LIBTOOL=$libtool" >> $config_host_mak
 echo "CFLAGS=$CFLAGS" >> $config_host_mak
+echo "CXXFLAGS=$CXXFLAGS" >> $config_host_mak
 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
 echo "QEMU_INCLUDES=$QEMU_INCLUDES" >> $config_host_mak
 if test "$sparse" = "yes" ; then
-- 
1.8.1





[Qemu-devel] [RFC 2/4] rules.mak: support C++ compiling and linking

2013-09-11 Thread Claudio Fontana
support compilation of .cc and .cpp files,
and if C++ is enabled always link with C++ in the non-libtool case.

Signed-off-by: Claudio Fontana 
---
 rules.mak | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/rules.mak b/rules.mak
index 4499745..d2f1b1f 100644
--- a/rules.mak
+++ b/rules.mak
@@ -8,9 +8,14 @@ MAKEFLAGS += -rR
 %.d:
 %.h:
 %.c:
+%.cc:
+%.cpp:
 %.m:
 %.mak:
 
+# Flags for C++ compilation
+QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
+
 # Flags for dependency generation
 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 
@@ -21,11 +26,21 @@ QEMU_INCLUDES += -I$(/dev/null 2>&1 && echo OK), $2, $3)
 
-VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh %.rc
+VPATH_SUFFIXES = %.c %.h %.S %.cpp %.cc %.m %.mak %.texi %.sh %.rc
+
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath 
$(PATTERN) $1)))
 
 # find-in-path
-- 
1.8.1





[Qemu-devel] [RFC 4/4] disas: implement host disassembly output for aarch64

2013-09-11 Thread Claudio Fontana
use C++ libvixl to implement output, for now only enabled for the host output
disasm, since we don't have the aarch64 target yet.

Signed-off-by: Claudio Fontana 
---
 configure   |  6 +
 disas.c |  2 ++
 disas/Makefile.objs |  7 ++
 disas/aarch64-cxx.cc| 53 +
 disas/aarch64.c | 45 ++
 disas/libvixl/Makefile.objs |  6 +
 include/disas/bfd.h |  1 +
 7 files changed, 120 insertions(+)
 create mode 100644 disas/aarch64-cxx.cc
 create mode 100644 disas/aarch64.c
 create mode 100644 disas/libvixl/Makefile.objs

diff --git a/configure b/configure
index 6b73d99..1a2648a 100755
--- a/configure
+++ b/configure
@@ -4443,6 +4443,12 @@ ldflags=""
 
 for i in $ARCH $TARGET_BASE_ARCH ; do
   case "$i" in
+  aarch64)
+if test "x${cxx}" != "x"; then
+  echo "CONFIG_AARCH64_DIS=y"  >> $config_target_mak
+  echo "CONFIG_AARCH64_DIS=y"  >> config-all-disas.mak
+fi
+  ;;
   alpha)
 echo "CONFIG_ALPHA_DIS=y"  >> $config_target_mak
 echo "CONFIG_ALPHA_DIS=y"  >> config-all-disas.mak
diff --git a/disas.c b/disas.c
index 0203ef2..cc20c4a 100644
--- a/disas.c
+++ b/disas.c
@@ -356,6 +356,8 @@ void disas(FILE *out, void *code, unsigned long size)
 #elif defined(_ARCH_PPC)
 s.info.disassembler_options = (char *)"any";
 print_insn = print_insn_ppc;
+#elif defined(__aarch64__)
+print_insn = print_insn_aarch64;
 #elif defined(__alpha__)
 print_insn = print_insn_alpha;
 #elif defined(__sparc__)
diff --git a/disas/Makefile.objs b/disas/Makefile.objs
index 3b1e77a..f468c22 100644
--- a/disas/Makefile.objs
+++ b/disas/Makefile.objs
@@ -1,3 +1,10 @@
+ifeq ($(CONFIG_AARCH64_DIS),y)
+libvixldir = $(SRC_PATH)/disas/libvixl/src
+QEMU_CFLAGS += -I$(libvixldir) -Wno-undef
+common-obj-$(CONFIG_AARCH64_DIS) += libvixl/
+common-obj-$(CONFIG_AARCH64_DIS) += aarch64.o aarch64-cxx.o
+endif
+
 common-obj-$(CONFIG_ALPHA_DIS) += alpha.o
 common-obj-$(CONFIG_ARM_DIS) += arm.o
 common-obj-$(CONFIG_CRIS_DIS) += cris.o
diff --git a/disas/aarch64-cxx.cc b/disas/aarch64-cxx.cc
new file mode 100644
index 000..524f5ae
--- /dev/null
+++ b/disas/aarch64-cxx.cc
@@ -0,0 +1,53 @@
+/*
+ * Aarch64 disassembly output wrapper to libvixl - C++ part
+ * Copyright (c) 2013 Linaro Limited
+ * Written by Claudio Fontana
+ *
+ * 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 .
+ */
+
+#include "a64/simulator-a64.h"
+#include "a64/macro-assembler-a64.h"
+
+extern "C" {
+int vixl_is_initialized(int);
+int vixl_init(FILE *f);
+int vixl_decode_insn(uint8_t *bytes);
+}
+
+using namespace vixl;
+
+static Decoder *vixl_decoder = NULL;
+static Disassembler *vixl_disasm = NULL;
+
+int vixl_is_initialized(int unused)
+{
+return vixl_decoder != NULL;
+}
+
+/* Disassemble Aarch64 bytecode - wrappers */
+int vixl_init(FILE *f) {
+vixl_decoder = new Decoder();
+vixl_disasm = new PrintDisassembler(f);
+vixl_decoder->AppendVisitor(vixl_disasm);
+return 1;
+}
+
+int vixl_decode_insn(uint8_t *bytes)
+{
+Instr instr;
+instr = bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
+vixl_decoder->Decode(reinterpret_cast(&instr));
+return 1;
+}
diff --git a/disas/aarch64.c b/disas/aarch64.c
new file mode 100644
index 000..7e44837
--- /dev/null
+++ b/disas/aarch64.c
@@ -0,0 +1,45 @@
+/*
+ * Aarch64 disassembly output wrapper to libvixl - C part
+ * Copyright (c) 2013 Linaro Limited
+ * Written by Claudio Fontana
+ *
+ * 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 .
+ */
+
+#include "disas/bfd.h"
+#define INSN_SIZE 4
+
+extern int vixl_is_initialized(int);
+extern int vixl_init(FILE *);
+extern int vixl_decode_insn(uint8_t *);
+
+/* Disassemble Aarch64

Re: [Qemu-devel] [RFC 0/4] ARM aarch64 disas output libvixl support

2013-09-11 Thread Andreas Färber
Hi Claudio,

Am 11.09.2013 14:54, schrieb Claudio Fontana:
> 
> This is the aarch64 libvixl support patchset in the current state.
> It provides (limited) support for disassembly output on aarch64.
> Only host disassembly is enabled, since target for aarch64 is not in yet.
> 
> An external objdump solution as exemplified before by R.H. seems preferable
> to me, even if it means giving up the monitor support.
[snip]

That has been committed August 24th, hasn't it?

Regards,
Andreas

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



Re: [Qemu-devel] [PATCH v3] libxl: usb2 and usb3 controller support for upstream qemu

2013-09-11 Thread Fabio Fantoni

Il 11/09/2013 13:38, Fabio Fantoni ha scritto:

Il 11/09/2013 12:19, Ian Campbell ha scritto:

On Wed, 2013-09-11 at 12:14 +0200, Fabio Fantoni wrote:

Ping

Is this directed and Xen or qmeu folks?

What are the outstanding questions which need to be answered?

It doesn't look to me like Ian's concerns from the (great?) grandparent
have been addressed? On the other hand I appear to be missing some of
the mails in this thread.

Ian.




I quoted the complete mail:
http://lists.xen.org/archives/html/xen-devel/2013-08/msg01425.html

The ping was directed to xen-devel, I added qemu-devel to get some 
definite answers about qemu hardcoded parameters on which you have 
doubts.
There were answers from qemu developersand after also positive reply 
from Ian Jackson.
I did a v4 of this patch with the missed advices but no more replies 
after qemu parameters question that seems solved on this old thread.


All details are on mail linked above.

Thanks for any reply and sorry for my bad english.


To clarify my previous mail the mainly question is:
Is the patch v4 ok or does it need other improvement?
The only doubt I have about is on usb3 controller support. I'm in doubt 
if to add it or not because some parts of it were included only in the 
latest versions of qemu, and from my recents test maybe stillincomplete 
somewhere.


Thanks for any reply.



Re: [Qemu-devel] [PATCH v3 for 1.6 0/8] Guest memory allocation fixes & cleanup

2013-09-11 Thread Markus Armbruster
Markus Armbruster  writes:

> Series has been on list for more than 8 weeks (not counting the initial
> PATCH RFC), and rebased twice.  Right now, it still applies.  Please
> either merge or tell me what I need to do to get it merged.  Thanks!

Twelve weeks now.

> Markus Armbruster  writes:
>
>> All I wanted to do is exit(1) instead of abort() on guest memory
>> allocation failure [07/08].  But that lead me into a minor #ifdef bog,
>> and here's what I brought back.  Enjoy!
>>
>> Testing:
>> * Christian Borntraeger reports v1 works fine under LPAR (new S390
>>   KVM, i.e. generic allocation) and as second guest under z/VM (old
>>   S390 KVM, i.e. legacy S390 allocation).  Thanks for testing, and for
>>   catching a stupid mistake.  v2 differs from v1 only in code that
>>   isn't reachable on S390.
>>
>> Changes since v2:
>> * Straightforward rebase, only 4/8 conflicted
>> Changes since v1:
>> * 5/8: Fix assertion in qemu_ram_remap() (Paolo)
>> * All other patches unchanged except for Acked-by in commit messages
>> Changes since RFC:
>> * 1-3+8/8 unchanged except for commit message tweaks
>> * 4+6/8 rewritten to address Paolo's review
>> * 5/8 rewritten: don't fix dead code, just assert it's dead
>> * 7/8 fix mistakes caught by Richard Henderson and Peter Maydell
>>
>> Markus Armbruster (8):
>>   exec: Fix Xen RAM allocation with unusual options
>>   exec: Clean up fall back when -mem-path allocation fails
>>   exec: Reduce ifdeffery around -mem-path
>>   exec: Simplify the guest physical memory allocation hook
>>   exec: Drop incorrect & dead S390 code in qemu_ram_remap()
>>   exec: Clean up unnecessary S390 ifdeffery
>>   exec: Don't abort when we can't allocate guest memory
>>   pc_sysfw: Fix ISA BIOS init for ridiculously big flash
>>
>>  exec.c  | 120 
>> ++--
>>  hw/block/pc_sysfw.c |   5 +-
>>  include/exec/cpu-all.h  |   2 -
>>  include/exec/exec-all.h |   2 +
>>  include/sysemu/kvm.h|   5 --
>>  kvm-all.c   |  13 --
>>  target-s390x/kvm.c  |  23 +++---
>>  util/oslib-posix.c  |   4 +-
>>  util/oslib-win32.c  |   5 +-
>>  9 files changed, 77 insertions(+), 102 deletions(-)



Re: [Qemu-devel] [RFC 0/4] ARM aarch64 disas output libvixl support

2013-09-11 Thread Peter Maydell
On 11 September 2013 14:14, Andreas Färber  wrote:
> Am 11.09.2013 14:54, schrieb Claudio Fontana:
>> This is the aarch64 libvixl support patchset in the current state.
>> It provides (limited) support for disassembly output on aarch64.
>> Only host disassembly is enabled, since target for aarch64 is not in yet.
>>
>> An external objdump solution as exemplified before by R.H. seems preferable
>> to me, even if it means giving up the monitor support.
> [snip]
>
> That has been committed August 24th, hasn't it?

Yes, but at the moment it's only for targets without a
builtin disassembler. If we're going to have it be the
standard setup we use for every target that's one thing.
But otherwise I'd rather aarch64 not be a second class
citizen in this regard.

-- PMM



[Qemu-devel] [PATCH v6 4/8] module: implement module loading function

2013-09-11 Thread Fam Zheng
Added three types of modules:

typedef enum {
MODULE_LOAD_BLOCK = 0,
MODULE_LOAD_UI,
MODULE_LOAD_NET,
MODULE_LOAD_MAX,
} module_load_type;

and their loading function:

void module_load(module_load_type).

which loads all ".so" files in a subdir under "${PREFIX}/qemu/", e.g.
"/usr/lib/qemu/block". Modules of each type should be loaded before
respective subsystem initialization code.

Requires gmodule-2.0 from glib.

Signed-off-by: Fam Zheng 
---
 block.c   |  1 +
 bsd-user/main.c   |  3 +++
 configure | 28 ++-
 include/qemu/module.h |  9 +
 linux-user/main.c |  3 +++
 scripts/create_config |  7 +++
 util/module.c | 53 +++
 vl.c  |  2 ++
 8 files changed, 97 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index 26639e8..16ceaaf 100644
--- a/block.c
+++ b/block.c
@@ -4008,6 +4008,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
 
 void bdrv_init(void)
 {
+module_load(MODULE_LOAD_BLOCK);
 module_call_init(MODULE_INIT_BLOCK);
 }
 
diff --git a/bsd-user/main.c b/bsd-user/main.c
index f9246aa..6cb9e35 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -33,6 +33,7 @@
 #include "tcg.h"
 #include "qemu/timer.h"
 #include "qemu/envlist.h"
+#include "qemu/module.h"
 
 int singlestep;
 #if defined(CONFIG_USE_GUEST_BASE)
@@ -749,6 +750,8 @@ int main(int argc, char **argv)
 if (argc <= 1)
 usage();
 
+module_load(MODULE_LOAD_UI);
+module_load(MODULE_LOAD_NET);
 module_call_init(MODULE_INIT_QOM);
 
 if ((envlist = envlist_create()) == NULL) {
diff --git a/configure b/configure
index c6d4a62..a80f143 100755
--- a/configure
+++ b/configure
@@ -198,6 +198,7 @@ datadir="\${prefix}/share"
 qemu_docdir="\${prefix}/share/doc/qemu"
 bindir="\${prefix}/bin"
 libdir="\${prefix}/lib"
+moddir="\${prefix}/lib/qemu"
 libexecdir="\${prefix}/libexec"
 includedir="\${prefix}/include"
 sysconfdir="\${prefix}/etc"
@@ -673,6 +674,8 @@ for opt do
   ;;
   --libdir=*) libdir="$optarg"
   ;;
+  --moddir=*) moddir="$optarg"
+  ;;
   --libexecdir=*) libexecdir="$optarg"
   ;;
   --includedir=*) includedir="$optarg"
@@ -1049,6 +1052,7 @@ echo "  --datadir=PATH   install firmware in 
PATH$confsuffix"
 echo "  --docdir=PATHinstall documentation in PATH$confsuffix"
 echo "  --bindir=PATHinstall binaries in PATH"
 echo "  --libdir=PATHinstall libraries in PATH"
+echo "  --moddir=PATHinstall modules in PATH"
 echo "  --sysconfdir=PATHinstall config in PATH$confsuffix"
 echo "  --localstatedir=PATH install local state in PATH (set at runtime 
on win32)"
 echo "  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and 
sysconfdir [$confsuffix]"
@@ -2252,15 +2256,19 @@ if test "$mingw32" = yes; then
 else
 glib_req_ver=2.12
 fi
-if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
-glib_cflags=`$pkg_config --cflags gthread-2.0`
-glib_libs=`$pkg_config --libs gthread-2.0`
-CFLAGS="$glib_cflags $CFLAGS"
-LIBS="$glib_libs $LIBS"
-libs_qga="$glib_libs $libs_qga"
-else
-error_exit "glib-$glib_req_ver required to compile QEMU"
-fi
+
+for i in gthread-2.0 gmodule-2.0; do
+if $pkg_config --atleast-version=$glib_req_ver $i; then
+glib_cflags=`$pkg_config --cflags $i`
+glib_libs=`$pkg_config --libs $i`
+CFLAGS="$glib_cflags $CFLAGS"
+LIBS="$glib_libs $LIBS"
+libs_qga="$glib_libs $libs_qga"
+else
+error_exit "glib-$glib_req_ver required to compile QEMU"
+fi
+done
+
 
 ##
 # pixman support probe
@@ -3553,6 +3561,7 @@ echo "Install prefix$prefix"
 echo "BIOS directory`eval echo $qemu_datadir`"
 echo "binary directory  `eval echo $bindir`"
 echo "library directory `eval echo $libdir`"
+echo "module directory  `eval echo $moddir`"
 echo "libexec directory `eval echo $libexecdir`"
 echo "include directory `eval echo $includedir`"
 echo "config directory  `eval echo $sysconfdir`"
@@ -3675,6 +3684,7 @@ echo all: >> $config_host_mak
 echo "prefix=$prefix" >> $config_host_mak
 echo "bindir=$bindir" >> $config_host_mak
 echo "libdir=$libdir" >> $config_host_mak
+echo "moddir=$moddir" >> $config_host_mak
 echo "libexecdir=$libexecdir" >> $config_host_mak
 echo "includedir=$includedir" >> $config_host_mak
 echo "mandir=$mandir" >> $config_host_mak
diff --git a/include/qemu/module.h b/include/qemu/module.h
index c4ccd57..f00bc25 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -37,4 +37,13 @@ void register_module_init(void (*fn)(void), module_init_type 
type);
 
 void module_call_init(module_init_type type);
 
+typedef enum {
+MODULE_LOAD_BLOCK = 0,
+MODULE_LOAD_UI,
+MODULE_LOAD_NET,
+MODULE_LOAD_MAX,
+} module_load_type;
+
+void module_load(module_load_type type);
+
 #endif
diff

[Qemu-devel] [PATCH v6 7/8] .gitignore: ignore module related files (dll, so, mo)

2013-09-11 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index d2c5c2f..4d0ac09 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,9 @@ fsdev/virtfs-proxy-helper.pod
 *.cp
 *.dvi
 *.exe
+*.dll
+*.so
+*.mo
 *.fn
 *.ky
 *.log
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 0/2] Try to fix problem with emulated smartcards where invalid PIN succeeds

2013-09-11 Thread Ray Strode
Hi,

On Mon, Sep 9, 2013 at 2:19 PM, Robert Relyea  wrote:
> ack... The original problem is a little worse than ray says. It's not a
> 60 second window, it's pretty much anytime until the card is explicitly
> logged out. Ray's patch will fix this.
Okay, I'll resend the patch series with an improved commit message for
the second patch and Reviewed-By's for you and alon.

--Ray



[Qemu-devel] [PATCH v6 5/8] configure: introduce --enable-modules

2013-09-11 Thread Fam Zheng
The new option will enable support of shared object build. Otherwise
objects are static linked to executables.

Signed-off-by: Fam Zheng 
---
 Makefile.target | 6 +-
 configure   | 8 
 rules.mak   | 6 +-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 87906ea..7fb9e4d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -152,7 +152,11 @@ obj-y-save := $(obj-y)
 block-obj-y :=
 common-obj-y :=
 include $(SRC_PATH)/Makefile.objs
-dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
+dummy := $(call unnest-vars,.., \
+   block-obj-y \
+   block-obj-m \
+   common-obj-y \
+   common-obj-m)
 
 # Now restore obj-y
 obj-y := $(obj-y-save)
diff --git a/configure b/configure
index a80f143..275b1a0 100755
--- a/configure
+++ b/configure
@@ -192,6 +192,7 @@ gcov_tool="gcov"
 EXESUF=""
 DSOSUF=".so"
 LDFLAGS_SHARED="-shared"
+modules="no"
 prefix="/usr/local"
 mandir="\${prefix}/share/man"
 datadir="\${prefix}/share"
@@ -651,6 +652,8 @@ for opt do
   ;;
   --disable-debug-info)
   ;;
+  --enable-modules) modules="yes"
+  ;;
   --cpu=*)
   ;;
   --target-list=*) target_list="$optarg"
@@ -1056,6 +1059,7 @@ echo "  --moddir=PATHinstall modules in PATH"
 echo "  --sysconfdir=PATHinstall config in PATH$confsuffix"
 echo "  --localstatedir=PATH install local state in PATH (set at runtime 
on win32)"
 echo "  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and 
sysconfdir [$confsuffix]"
+echo "  --enable-modules enable modules support"
 echo "  --enable-debug-tcg   enable TCG debugging"
 echo "  --disable-debug-tcg  disable TCG debugging (default)"
 echo "  --enable-debug-info   enable debugging information (default)"
@@ -3585,6 +3589,7 @@ echo "python$python"
 if test "$slirp" = "yes" ; then
 echo "smbd  $smbd"
 fi
+echo "module support$modules"
 echo "host CPU  $cpu"
 echo "host big endian   $bigendian"
 echo "target list   $target_list"
@@ -3703,6 +3708,9 @@ echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
 
 echo "ARCH=$ARCH" >> $config_host_mak
 
+if test "$modules" = "yes"; then
+  echo "CONFIG_MODULES=y" >> $config_host_mak
+fi
 case "$cpu" in
   arm|i386|x86_64|x32|ppc|aarch64)
 # The TCG interpreter currently does not support ld/st optimization.
diff --git a/rules.mak b/rules.mak
index 9275d91..22492a9 100644
--- a/rules.mak
+++ b/rules.mak
@@ -187,6 +187,10 @@ $(if $1,$(foreach v,$(nested-vars),$(eval \
 $(foreach v,$(filter %-m,$(nested-vars)), \
 $(call add-modules,$v))
 
-$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m)))
+$(if $(CONFIG_MODULES), \
+$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m))) \
+$(foreach v,$(filter %-m,$(nested-vars)), \
+$(eval $(patsubst %-m,%-y,$v) += $($v)) \
+$(eval $v := )))
 
 endef
-- 
1.8.3.1




[Qemu-devel] [PATCH v6 2/8] rule.mak: allow per object cflags and libs

2013-09-11 Thread Fam Zheng
Adds extract-libs in LINK to expand any "per object libs", the syntax to define
such a libs options is like:

foo.o-libs := $(CURL_LIBS)

in block/Makefile.objs.

Similarly,

foo.o-cflags := $(FOO_CFLAGS)

is also supported.

"foo.o" must be listed a nested var (e.g. common-obj-y) to make the
option variables effective.

Signed-off-by: Fam Zheng 
---
 rules.mak | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/rules.mak b/rules.mak
index 9344c27..b1d53b5 100644
--- a/rules.mak
+++ b/rules.mak
@@ -17,15 +17,17 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
 QEMU_INCLUDES += -I$(

[Qemu-devel] [PATCH v6 8/8] block: convert block drivers linked with libs to modules

2013-09-11 Thread Fam Zheng
The converted block drivers are:

curl
iscsi
rbd
ssh
glusterfs

no longer adds flags and libs for them to global variables, instead
create config-host.mak variables like FOO_CFLAGS and FOO_LIBS, which is
used as per object cflags and libs.

Signed-off-by: Fam Zheng 
---
 block/Makefile.objs | 11 ++-
 configure   | 33 +++--
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 3bb85b5..f98d379 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -23,4 +23,13 @@ common-obj-y += commit.o
 common-obj-y += mirror.o
 common-obj-y += backup.o
 
-$(obj)/curl.o: QEMU_CFLAGS+=$(CURL_CFLAGS)
+iscsi.o-cflags := $(LIBISCSI_CFLAGS)
+iscsi.o-libs   := $(LIBISCSI_LIBS)
+curl.o-cflags  := $(CURL_CFLAGS)
+curl.o-libs:= $(CURL_LIBS)
+rbd.o-cflags   := $(RBD_CFLAGS)
+rbd.o-libs := $(RBD_LIBS)
+gluster.o-cflags   := $(GLUSTERFS_CFLAGS)
+gluster.o-libs := $(GLUSTERFS_LIBS)
+ssh.o-cflags   := $(LIBSSH2_CFLAGS)
+ssh.o-libs := $(LIBSSH2_LIBS)
diff --git a/configure b/configure
index 275b1a0..2f02b3d 100755
--- a/configure
+++ b/configure
@@ -2221,8 +2221,6 @@ EOF
   curl_libs=`$curlconfig --libs 2>/dev/null`
   if compile_prog "$curl_cflags" "$curl_libs" ; then
 curl=yes
-libs_tools="$curl_libs $libs_tools"
-libs_softmmu="$curl_libs $libs_softmmu"
   else
 if test "$curl" = "yes" ; then
   feature_not_found "curl"
@@ -2382,8 +2380,6 @@ EOF
   rbd_libs="-lrbd -lrados"
   if compile_prog "" "$rbd_libs" ; then
 rbd=yes
-libs_tools="$rbd_libs $libs_tools"
-libs_softmmu="$rbd_libs $libs_softmmu"
   else
 if test "$rbd" = "yes" ; then
   feature_not_found "rados block device"
@@ -2400,9 +2396,6 @@ if test "$libssh2" != "no" ; then
 libssh2_cflags=`$pkg_config libssh2 --cflags`
 libssh2_libs=`$pkg_config libssh2 --libs`
 libssh2=yes
-libs_tools="$libssh2_libs $libs_tools"
-libs_softmmu="$libssh2_libs $libs_softmmu"
-QEMU_CFLAGS="$QEMU_CFLAGS $libssh2_cflags"
   else
 if test "$libssh2" = "yes" ; then
   error_exit "libssh2 >= $min_libssh2_version required for 
--enable-libssh2"
@@ -2618,9 +2611,6 @@ if test "$glusterfs" != "no" ; then
 glusterfs="yes"
 glusterfs_cflags=`$pkg_config --cflags glusterfs-api`
 glusterfs_libs=`$pkg_config --libs glusterfs-api`
-CFLAGS="$CFLAGS $glusterfs_cflags"
-libs_tools="$glusterfs_libs $libs_tools"
-libs_softmmu="$glusterfs_libs $libs_softmmu"
 if $pkg_config --atleast-version=5 glusterfs-api; then
   glusterfs_discard="yes"
 fi
@@ -2988,11 +2978,9 @@ EOF
 libiscsi="yes"
 libiscsi_cflags=$($pkg_config --cflags libiscsi)
 libiscsi_libs=$($pkg_config --libs libiscsi)
-CFLAGS="$CFLAGS $libiscsi_cflags"
-LIBS="$LIBS $libiscsi_libs"
   elif compile_prog "" "-liscsi" ; then
 libiscsi="yes"
-LIBS="$LIBS -liscsi"
+libiscsi_libs="-liscsi"
   else
 if test "$libiscsi" = "yes" ; then
   feature_not_found "libiscsi"
@@ -3907,8 +3895,9 @@ if test "$bswap_h" = "yes" ; then
   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
 fi
 if test "$curl" = "yes" ; then
-  echo "CONFIG_CURL=y" >> $config_host_mak
+  echo "CONFIG_CURL=m" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
+  echo "CURL_LIBS=$curl_libs" >> $config_host_mak
 fi
 if test "$brlapi" = "yes" ; then
   echo "CONFIG_BRLAPI=y" >> $config_host_mak
@@ -3997,7 +3986,9 @@ if test "$glx" = "yes" ; then
 fi
 
 if test "$libiscsi" = "yes" ; then
-  echo "CONFIG_LIBISCSI=y" >> $config_host_mak
+  echo "CONFIG_LIBISCSI=m" >> $config_host_mak
+  echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
+  echo "LIBISCSI_LIBS=$libiscsi_libs" >> $config_host_mak
 fi
 
 if test "$seccomp" = "yes"; then
@@ -4018,7 +4009,9 @@ if test "$qom_cast_debug" = "yes" ; then
   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
 fi
 if test "$rbd" = "yes" ; then
-  echo "CONFIG_RBD=y" >> $config_host_mak
+  echo "CONFIG_RBD=m" >> $config_host_mak
+  echo "RBD_CFLAGS=$rbd_cflags" >> $config_host_mak
+  echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
 fi
 
 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
@@ -4056,7 +4049,9 @@ if test "$getauxval" = "yes" ; then
 fi
 
 if test "$glusterfs" = "yes" ; then
-  echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
+  echo "CONFIG_GLUSTERFS=m" >> $config_host_mak
+  echo "GLUSTERFS_CFLAGS=$glusterfs_cflags" >> $config_host_mak
+  echo "GLUSTERFS_LIBS=$glusterfs_libs" >> $config_host_mak
 fi
 
 if test "$glusterfs_discard" = "yes" ; then
@@ -4064,7 +4059,9 @@ if test "$glusterfs_discard" = "yes" ; then
 fi
 
 if test "$libssh2" = "yes" ; then
-  echo "CONFIG_LIBSSH2=y" >> $config_host_mak
+  echo "CONFIG_LIBSSH2=m" >> $config_host_mak
+  echo "LIBSSH2_CFLAGS=$libssh2_cflags" >> $config_host_mak
+  echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
 fi
 
 if test "$virtio_blk_data

Re: [Qemu-devel] [RFC 0/4] ARM aarch64 disas output libvixl support

2013-09-11 Thread Peter Maydell
On 11 September 2013 13:54, Claudio Fontana  wrote:
> This is the aarch64 libvixl support patchset in the current state.
> It provides (limited) support for disassembly output on aarch64.
> Only host disassembly is enabled, since target for aarch64 is not in yet.

Incidentally, people interested in aarch64 might like to know that
the first public beta release of the ARMv8-A ARM ARM is now
available on infocenter:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0487a/index.html
(needs an account on infocenter, which is a 'just fill in a webform'
sort of process).

-- PMM



Re: [Qemu-devel] [PATCH v6 1/8] make.rule: fix $(obj) to a real relative path

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 15:34, Fam Zheng ha scritto:
> Makefile.target includes rule.mak and unnested common-obj-y, then prefix
> them with '../', this will ignore object specific QEMU_CFLAGS in subdir
> Makefile.objs:
> 
> $(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)
> 
> Because $(obj) here is './block', instead of '../block'. This doesn't
> hurt compiling because we basically build all .o from top Makefile,
> before entering Makefile.target, but it will affact arriving per-object
> libs support.
> 
> The starting point of $(obj) is passed in as argument of unnest-vars, as
> well as nested variables, so that different Makefiles can pass in a
> right value.
> 
> Signed-off-by: Fam Zheng 
> ---
>  Makefile| 16 +++-
>  Makefile.objs   | 16 +---
>  Makefile.target | 17 +
>  configure   |  1 +
>  rules.mak   | 16 +++-
>  5 files changed, 41 insertions(+), 25 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 806946e..9e603c6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -115,14 +115,28 @@ defconfig:
>  
>  ifneq ($(wildcard config-host.mak),)
>  include $(SRC_PATH)/Makefile.objs
> -include $(SRC_PATH)/tests/Makefile
>  endif
>  ifeq ($(CONFIG_SMARTCARD_NSS),y)
>  include $(SRC_PATH)/libcacard/Makefile
>  endif
>  
> +dummy := $(call unnest-vars,, \
> +stub-obj-y \
> +util-obj-y \
> +qga-obj-y \
> +block-obj-y \
> +common-obj-y)
> +
> +ifneq ($(wildcard config-host.mak),)
> +include $(SRC_PATH)/tests/Makefile
> +endif
> +
>  all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
>  
> +vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
> +
> +vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
> +
>  config-host.h: config-host.h-timestamp
>  config-host.h-timestamp: config-host.mak
>  qemu-options.def: $(SRC_PATH)/qemu-options.hx
> diff --git a/Makefile.objs b/Makefile.objs
> index f46a4cd..4f7a364 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -41,7 +41,7 @@ libcacard-y += libcacard/vcardt.o
>  # single QEMU executable should support all CPUs and machines.
>  
>  ifeq ($(CONFIG_SOFTMMU),y)
> -common-obj-y = $(block-obj-y) blockdev.o blockdev-nbd.o block/
> +common-obj-y = blockdev.o blockdev-nbd.o block/
>  common-obj-y += net/
>  common-obj-y += readline.o
>  common-obj-y += qdev-monitor.o device-hotplug.o
> @@ -109,17 +109,3 @@ version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
>  # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
>  # by libqemuutil.a.  These should be moved to a separate .json schema.
>  qga-obj-y = qga/ qapi-types.o qapi-visit.o
> -
> -vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
> -
> -vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
> -
> -QEMU_CFLAGS+=$(GLIB_CFLAGS)
> -
> -nested-vars += \
> - stub-obj-y \
> - util-obj-y \
> - qga-obj-y \
> - block-obj-y \
> - common-obj-y
> -dummy := $(call unnest-vars)
> diff --git a/Makefile.target b/Makefile.target
> index 9a49852..87906ea 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -143,13 +143,22 @@ endif # CONFIG_SOFTMMU
>  # Workaround for http://gcc.gnu.org/PR55489, see configure.
>  %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
>  
> -nested-vars += obj-y
> +dummy := $(call unnest-vars,,obj-y)
>  
> -# This resolves all nested paths, so it must come last
> +# we are making another call to unnest-vars with different vars, protect 
> obj-y,
> +# it can be overriden in subdir Makefile.objs
> +obj-y-save := $(obj-y)
> +
> +block-obj-y :=
> +common-obj-y :=
>  include $(SRC_PATH)/Makefile.objs
> +dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
> +
> +# Now restore obj-y
> +obj-y := $(obj-y-save)
> +
> +all-obj-y = $(obj-y) $(common-obj-y) $(block-obj-y)
>  
> -all-obj-y = $(obj-y)
> -all-obj-y += $(addprefix ../, $(common-obj-y))
>  
>  ifndef CONFIG_HAIKU
>  LIBS+=-lm
> diff --git a/configure b/configure
> index e989609..cc3cd4d 100755
> --- a/configure
> +++ b/configure
> @@ -2251,6 +2251,7 @@ fi
>  if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
>  glib_cflags=`$pkg_config --cflags gthread-2.0`
>  glib_libs=`$pkg_config --libs gthread-2.0`
> +CFLAGS="$glib_cflags $CFLAGS"
>  LIBS="$glib_libs $LIBS"
>  libs_qga="$glib_libs $libs_qga"
>  else
> diff --git a/rules.mak b/rules.mak
> index 4499745..9344c27 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -103,9 +103,6 @@ clean: clean-timestamp
>  
>  # magic to descend into other directories
>  
> -obj := .
> -old-nested-dirs :=
> -
>  define push-var
>  $(eval save-$2-$1 = $(value $1))
>  $(eval $1 :=)
> @@ -119,9 +116,11 @@ endef
>  
>  define unnest-dir
>  $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
> -$(eval obj := $(obj)/$1)
> +$(eval obj-parent-$1 := $(obj))
> +$(eval obj := $(if $(obj),$(obj)/$1,$1))
>  $(eval include $(SRC_PATH)/$1/Makefile.objs)
> -$(eval obj := $(patsubst %/$1,%,$(obj)))
> +$(eval obj := $(obj-parent-$1))
> +$(eval obj-parent-$1 := )
>  $(foreach var,$(nested-

[Qemu-devel] [PATCH] Quote extra_cflags in config-host.mak

2013-09-11 Thread Gabriel Kerneis
The variable extra_cflags needs to be quoted in config-host.mak,
in particular because it might contain parentheses that would
otherwise be interpreted by the shell when reloading the file.

For instance, if one wants to define some attribute with configure:

./configure --extra-cflags="-Dcoroutine_fn='__attribute__((coroutine_fn))'"

A more robust approach would be to escape every variable properly, but
there is no portable equivalent to bash's "printf %q" solution. The
current patch, while not bullet-proof, works well in the common case.

Signed-off-by: Gabriel Kerneis 
---
 configure |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index e989609..23114de 100755
--- a/configure
+++ b/configure
@@ -3681,7 +3681,7 @@ if test "$mingw32" = "no" ; then
   echo "qemu_localstatedir=$local_statedir" >> $config_host_mak
 fi
 echo "qemu_helperdir=$libexecdir" >> $config_host_mak
-echo "extra_cflags=$EXTRA_CFLAGS" >> $config_host_mak
+echo "extra_cflags=\"$EXTRA_CFLAGS\"" >> $config_host_mak
 echo "extra_ldflags=$EXTRA_LDFLAGS" >> $config_host_mak
 echo "qemu_localedir=$qemu_localedir" >> $config_host_mak
 echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
-- 
1.7.10.4




[Qemu-devel] [PATCH v6 3/8] Makefile: introduce common-obj-m and block-obj-m for DSO

2013-09-11 Thread Fam Zheng
Add necessary rules and flags for shared object generation.
$(common-obj-m) will include $(block-obj-m), like $(common-obj-y) does
for $(block-obj-y). The new rules introduced here are:

0) For all %.so compiling:

QEMU_CFLAGS += -fPIC

1) %.o in $(common-obj-m) is compiled to %.o, then linked to %.so.

2) %.mo in $(common-obj-m) is the placeholder for %.so for pattern
matching in Makefile. It's linked to "-shared" with all its dependencies
(multiple *.o) as input. Which means the list of depended objects must
be ruled out in each sub-Makefile.objs with an variable:

foo.mo-objs := bar.o baz.o qux.o

in the same style with foo.o-cflags and foo.o-libs.

Signed-off-by: Fam Zheng 
---
 Makefile  | 10 --
 Makefile.objs |  2 ++
 configure |  6 ++
 rules.mak | 45 +
 4 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 9e603c6..c50b4b3 100644
--- a/Makefile
+++ b/Makefile
@@ -125,13 +125,15 @@ dummy := $(call unnest-vars,, \
 util-obj-y \
 qga-obj-y \
 block-obj-y \
-common-obj-y)
+block-obj-m \
+common-obj-y \
+common-obj-m)
 
 ifneq ($(wildcard config-host.mak),)
 include $(SRC_PATH)/tests/Makefile
 endif
 
-all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
+all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules
 
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
@@ -249,6 +251,10 @@ clean:
rm -f qemu-options.def
find . -name '*.[oda]' -type f -exec rm -f {} +
find . -name '*.l[oa]' -type f -exec rm -f {} +
+   find . -name '*.so' -type f -exec rm -f {} +
+   find . -name '*.mo' -type f -exec rm -f {} +
+   find . -name '*.dll' -type f -exec rm -f {} +
+
rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
rm -Rf .libs
rm -f qemu-img-cmds.h
diff --git a/Makefile.objs b/Makefile.objs
index 4f7a364..023166b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -19,6 +19,8 @@ block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o 
qemu-coroutine-io.o
 block-obj-y += qemu-coroutine-sleep.o
 block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
 
+block-obj-m = block/
+
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
 # only pull in the actual virtio-9p device if we also enabled virtio.
diff --git a/configure b/configure
index cc3cd4d..c6d4a62 100755
--- a/configure
+++ b/configure
@@ -190,6 +190,8 @@ mingw32="no"
 gcov="no"
 gcov_tool="gcov"
 EXESUF=""
+DSOSUF=".so"
+LDFLAGS_SHARED="-shared"
 prefix="/usr/local"
 mandir="\${prefix}/share/man"
 datadir="\${prefix}/share"
@@ -485,6 +487,7 @@ OpenBSD)
 Darwin)
   bsd="yes"
   darwin="yes"
+  LDFLAGS_SHARED="-bundle"
   if [ "$cpu" = "x86_64" ] ; then
 QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
 LDFLAGS="-arch x86_64 $LDFLAGS"
@@ -584,6 +587,7 @@ fi
 
 if test "$mingw32" = "yes" ; then
   EXESUF=".exe"
+  DSOSUF=".dll"
   QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
@@ -4175,6 +4179,8 @@ echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
+echo "DSOSUF=$DSOSUF" >> $config_host_mak
+echo "LDFLAGS_SHARED=$LDFLAGS_SHARED" >> $config_host_mak
 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
 echo "POD2MAN=$POD2MAN" >> $config_host_mak
 echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index b1d53b5..9275d91 100644
--- a/rules.mak
+++ b/rules.mak
@@ -18,6 +18,9 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 QEMU_INCLUDES += -I$(

Re: [Qemu-devel] [PATCH v6 2/8] rule.mak: allow per object cflags and libs

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 15:34, Fam Zheng ha scritto:
> Adds extract-libs in LINK to expand any "per object libs", the syntax to 
> define
> such a libs options is like:
> 
> foo.o-libs := $(CURL_LIBS)
> 
> in block/Makefile.objs.
> 
> Similarly,
> 
> foo.o-cflags := $(FOO_CFLAGS)
> 
> is also supported.
> 
> "foo.o" must be listed a nested var (e.g. common-obj-y) to make the
> option variables effective.
> 
> Signed-off-by: Fam Zheng 
> ---
>  rules.mak | 19 ---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/rules.mak b/rules.mak
> index 9344c27..b1d53b5 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -17,15 +17,17 @@ QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
>  # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
>  QEMU_INCLUDES += -I$(  
> +extract-libs = $(strip $(foreach o,$1,$($o-libs)))
> +
>  %.o: %.c
> - $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) 
> $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CC$(TARGET_DIR)$@")
> + $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) 
> $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<,"  CC$(TARGET_DIR)$@")
>  %.o: %.rc
>   $(call quiet-command,$(WINDRES) -I. -o $@ $<,"  RC$(TARGET_DIR)$@")
>  
>  ifeq ($(LIBTOOL),)
>  LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
> $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
> -   $(LIBS),"  LINK  $(TARGET_DIR)$@")
> +   $(call extract-libs,$^) $(LIBS),"  LINK  $(TARGET_DIR)$@")
>  else
>  LIBTOOL += $(if $(V),,--quiet)
>  %.lo: %.c
> @@ -41,7 +43,7 @@ LINK = $(call quiet-command,\
> $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
> $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
> $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
> -   $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", "  LINK  
> ")"$(TARGET_DIR)$@")
> +   $(call extract-libs,$^) $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK 
> ", "  LINK  ")"$(TARGET_DIR)$@")
>  endif
>  
>  %.asm: %.S
> @@ -114,11 +116,22 @@ $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
>  $(eval save-$2-$1 :=)
>  endef
>  
> +define fix-obj-vars
> +$(foreach v,$($1), \
> + $(if $($v-cflags), \
> + $(eval $2$v-cflags := $($v-cflags)) \
> + $(eval $v-cflags := )) \
> + $(if $($v-libs), \
> + $(eval $2$v-libs := $($v-libs)) \
> + $(eval $v-libs := )))
> +endef
> +
>  define unnest-dir
>  $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
>  $(eval obj-parent-$1 := $(obj))
>  $(eval obj := $(if $(obj),$(obj)/$1,$1))
>  $(eval include $(SRC_PATH)/$1/Makefile.objs)
> +$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(if $(obj),$(obj)/)))
>  $(eval obj := $(obj-parent-$1))
>  $(eval obj-parent-$1 := )
>  $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
> 

I'm not sure this will work for targets in the toplevel directory when
obj-base is not empty.  This can be fixed later though, as part of a
general revamping of obj-base.  Please add a FIXME comment.

Paolo



[Qemu-devel] [PATCH v6 6/8] Makefile: install modules with "make install"

2013-09-11 Thread Fam Zheng
Install all the subdirs for modules under configure option "moddir".

Signed-off-by: Fam Zheng 
---
 Makefile | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Makefile b/Makefile
index c50b4b3..ca84d32 100644
--- a/Makefile
+++ b/Makefile
@@ -360,6 +360,12 @@ install-datadir install-localstatedir
 ifneq ($(TOOLS),)
$(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
 endif
+ifneq ($(CONFIG_MODULES),)
+   for s in $(patsubst %.mo,%.so,$(modules-m)); do \
+   $(INSTALL_DIR) "$(DESTDIR)$(moddir)/$$(dirname $$s)"; \
+   $(INSTALL_PROG) $(STRIP_OPT) $$s 
"$(DESTDIR)$(moddir)/$$(dirname $$s)"; \
+   done
+endif
 ifneq ($(HELPERS-y),)
$(INSTALL_DIR) "$(DESTDIR)$(libexecdir)"
$(INSTALL_PROG) $(STRIP_OPT) $(HELPERS-y) "$(DESTDIR)$(libexecdir)"
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v6 5/8] configure: introduce --enable-modules

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 15:34, Fam Zheng ha scritto:
> The new option will enable support of shared object build. Otherwise
> objects are static linked to executables.
> 
> Signed-off-by: Fam Zheng 
> ---
>  Makefile.target | 6 +-
>  configure   | 8 
>  rules.mak   | 6 +-
>  3 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 87906ea..7fb9e4d 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -152,7 +152,11 @@ obj-y-save := $(obj-y)
>  block-obj-y :=
>  common-obj-y :=
>  include $(SRC_PATH)/Makefile.objs
> -dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
> +dummy := $(call unnest-vars,.., \
> +   block-obj-y \
> +   block-obj-m \
> +   common-obj-y \
> +   common-obj-m)
>  

This would have to be in patch 3; in fact, it probably makes sense to
squash the two together.

Paolo

>  # Now restore obj-y
>  obj-y := $(obj-y-save)
> diff --git a/configure b/configure
> index a80f143..275b1a0 100755
> --- a/configure
> +++ b/configure
> @@ -192,6 +192,7 @@ gcov_tool="gcov"
>  EXESUF=""
>  DSOSUF=".so"
>  LDFLAGS_SHARED="-shared"
> +modules="no"
>  prefix="/usr/local"
>  mandir="\${prefix}/share/man"
>  datadir="\${prefix}/share"
> @@ -651,6 +652,8 @@ for opt do
>;;
>--disable-debug-info)
>;;
> +  --enable-modules) modules="yes"
> +  ;;
>--cpu=*)
>;;
>--target-list=*) target_list="$optarg"
> @@ -1056,6 +1059,7 @@ echo "  --moddir=PATHinstall modules in 
> PATH"
>  echo "  --sysconfdir=PATHinstall config in PATH$confsuffix"
>  echo "  --localstatedir=PATH install local state in PATH (set at runtime 
> on win32)"
>  echo "  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and 
> sysconfdir [$confsuffix]"
> +echo "  --enable-modules enable modules support"
>  echo "  --enable-debug-tcg   enable TCG debugging"
>  echo "  --disable-debug-tcg  disable TCG debugging (default)"
>  echo "  --enable-debug-info   enable debugging information (default)"
> @@ -3585,6 +3589,7 @@ echo "python$python"
>  if test "$slirp" = "yes" ; then
>  echo "smbd  $smbd"
>  fi
> +echo "module support$modules"
>  echo "host CPU  $cpu"
>  echo "host big endian   $bigendian"
>  echo "target list   $target_list"
> @@ -3703,6 +3708,9 @@ echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
>  
>  echo "ARCH=$ARCH" >> $config_host_mak
>  
> +if test "$modules" = "yes"; then
> +  echo "CONFIG_MODULES=y" >> $config_host_mak
> +fi
>  case "$cpu" in
>arm|i386|x86_64|x32|ppc|aarch64)
>  # The TCG interpreter currently does not support ld/st optimization.
> diff --git a/rules.mak b/rules.mak
> index 9275d91..22492a9 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -187,6 +187,10 @@ $(if $1,$(foreach v,$(nested-vars),$(eval \
>  $(foreach v,$(filter %-m,$(nested-vars)), \
>  $(call add-modules,$v))
>  
> -$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m)))
> +$(if $(CONFIG_MODULES), \
> +$(eval modules: $(patsubst %.mo,%$(DSOSUF),$(modules-m))) \
> +$(foreach v,$(filter %-m,$(nested-vars)), \
> +$(eval $(patsubst %-m,%-y,$v) += $($v)) \
> +$(eval $v := )))
>  
>  endef
> 




[Qemu-devel] [PATCH v6 1/8] make.rule: fix $(obj) to a real relative path

2013-09-11 Thread Fam Zheng
Makefile.target includes rule.mak and unnested common-obj-y, then prefix
them with '../', this will ignore object specific QEMU_CFLAGS in subdir
Makefile.objs:

$(obj)/curl.o: QEMU_CFLAGS += $(CURL_CFLAGS)

Because $(obj) here is './block', instead of '../block'. This doesn't
hurt compiling because we basically build all .o from top Makefile,
before entering Makefile.target, but it will affact arriving per-object
libs support.

The starting point of $(obj) is passed in as argument of unnest-vars, as
well as nested variables, so that different Makefiles can pass in a
right value.

Signed-off-by: Fam Zheng 
---
 Makefile| 16 +++-
 Makefile.objs   | 16 +---
 Makefile.target | 17 +
 configure   |  1 +
 rules.mak   | 16 +++-
 5 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/Makefile b/Makefile
index 806946e..9e603c6 100644
--- a/Makefile
+++ b/Makefile
@@ -115,14 +115,28 @@ defconfig:
 
 ifneq ($(wildcard config-host.mak),)
 include $(SRC_PATH)/Makefile.objs
-include $(SRC_PATH)/tests/Makefile
 endif
 ifeq ($(CONFIG_SMARTCARD_NSS),y)
 include $(SRC_PATH)/libcacard/Makefile
 endif
 
+dummy := $(call unnest-vars,, \
+stub-obj-y \
+util-obj-y \
+qga-obj-y \
+block-obj-y \
+common-obj-y)
+
+ifneq ($(wildcard config-host.mak),)
+include $(SRC_PATH)/tests/Makefile
+endif
+
 all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
 
+vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
+
+vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
+
 config-host.h: config-host.h-timestamp
 config-host.h-timestamp: config-host.mak
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
diff --git a/Makefile.objs b/Makefile.objs
index f46a4cd..4f7a364 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -41,7 +41,7 @@ libcacard-y += libcacard/vcardt.o
 # single QEMU executable should support all CPUs and machines.
 
 ifeq ($(CONFIG_SOFTMMU),y)
-common-obj-y = $(block-obj-y) blockdev.o blockdev-nbd.o block/
+common-obj-y = blockdev.o blockdev-nbd.o block/
 common-obj-y += net/
 common-obj-y += readline.o
 common-obj-y += qdev-monitor.o device-hotplug.o
@@ -109,17 +109,3 @@ version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
 # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
 # by libqemuutil.a.  These should be moved to a separate .json schema.
 qga-obj-y = qga/ qapi-types.o qapi-visit.o
-
-vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
-
-vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
-
-QEMU_CFLAGS+=$(GLIB_CFLAGS)
-
-nested-vars += \
-   stub-obj-y \
-   util-obj-y \
-   qga-obj-y \
-   block-obj-y \
-   common-obj-y
-dummy := $(call unnest-vars)
diff --git a/Makefile.target b/Makefile.target
index 9a49852..87906ea 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -143,13 +143,22 @@ endif # CONFIG_SOFTMMU
 # Workaround for http://gcc.gnu.org/PR55489, see configure.
 %/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)
 
-nested-vars += obj-y
+dummy := $(call unnest-vars,,obj-y)
 
-# This resolves all nested paths, so it must come last
+# we are making another call to unnest-vars with different vars, protect obj-y,
+# it can be overriden in subdir Makefile.objs
+obj-y-save := $(obj-y)
+
+block-obj-y :=
+common-obj-y :=
 include $(SRC_PATH)/Makefile.objs
+dummy := $(call unnest-vars,..,block-obj-y common-obj-y)
+
+# Now restore obj-y
+obj-y := $(obj-y-save)
+
+all-obj-y = $(obj-y) $(common-obj-y) $(block-obj-y)
 
-all-obj-y = $(obj-y)
-all-obj-y += $(addprefix ../, $(common-obj-y))
 
 ifndef CONFIG_HAIKU
 LIBS+=-lm
diff --git a/configure b/configure
index e989609..cc3cd4d 100755
--- a/configure
+++ b/configure
@@ -2251,6 +2251,7 @@ fi
 if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
 glib_cflags=`$pkg_config --cflags gthread-2.0`
 glib_libs=`$pkg_config --libs gthread-2.0`
+CFLAGS="$glib_cflags $CFLAGS"
 LIBS="$glib_libs $LIBS"
 libs_qga="$glib_libs $libs_qga"
 else
diff --git a/rules.mak b/rules.mak
index 4499745..9344c27 100644
--- a/rules.mak
+++ b/rules.mak
@@ -103,9 +103,6 @@ clean: clean-timestamp
 
 # magic to descend into other directories
 
-obj := .
-old-nested-dirs :=
-
 define push-var
 $(eval save-$2-$1 = $(value $1))
 $(eval $1 :=)
@@ -119,9 +116,11 @@ endef
 
 define unnest-dir
 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
-$(eval obj := $(obj)/$1)
+$(eval obj-parent-$1 := $(obj))
+$(eval obj := $(if $(obj),$(obj)/$1,$1))
 $(eval include $(SRC_PATH)/$1/Makefile.objs)
-$(eval obj := $(patsubst %/$1,%,$(obj)))
+$(eval obj := $(obj-parent-$1))
+$(eval obj-parent-$1 := )
 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
 endef
 
@@ -136,9 +135,16 @@ $(if $(nested-dirs),
 endef
 
 define unnest-vars
+$(eval obj := $1)
+$(eval nested-vars := $2)
+$(eval old-nested-dirs := )
 $(call unnest-vars-1)
 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)
 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($

[Qemu-devel] [PATCH v2 0/2] Try to fix problem with emulated smartcards where invalid PIN succeeds

2013-09-11 Thread Ray Strode
This updated patch series includes Reviewed-By lines from Alon Levy and Robert 
Relyea,
and also improves the accuracy of the second commit message. This set should be 
ready to merge.

Back story is that I started writing a blog post about virtualized smartcards 
here:

https://blogs.gnome.org/halfline/2013/09/08/another-smartcard-post/

and while testing what I was writing I noticed an invalid PIN worked when it
shouldn't have. It turns out that typing a valid PIN once in one program in the
guest, is enough to make all future programs in the guest ask for the PIN to
succeed regardless of what gets typed in for the PIN.

I did some digging through the libcacard code, and noticed it uses the
NSS PK11_Authenticate function which calls a function that has this comment 
above it:

If we're already logged in and this function is called we
will still prompt for a password, but we will probably succeed
no matter what the password was.

Also, PK11_Authenticate short-circuits to an early "return SECSuccess" if the 
token
is already logged in.

The two patches in this series attempt to correct this problem by calling 
PK11_Logout.




[Qemu-devel] [PATCHv2 2/2] libcacard: Lock NSS cert db when selecting an applet on an emulated card

2013-09-11 Thread Ray Strode
From: Ray Strode 

When a process in a guest uses an emulated smartcard, libcacard running
on the host passes the PIN from the guest to the PK11_Authenticate NSS
function. The first time PK11_Authenticate is called the passed in PIN
is used to unlock the certificate database. Subsequent calls to
PK11_Authenticate will transparently succeed, regardless of the passed in
PIN. This is a convenience for applications provided by NSS.

Of course, the guest may have many applications using the one emulated
smart card all driven from the same host QEMU process.  That means if a
user enters the right PIN in one program in the guest, and then enters the
wrong PIN in another program in the guest, the wrong PIN will still
successfully unlock the virtual smartcard.

This commit forces the NSS certificate database to be locked anytime an
applet is selected on an emulated smartcard by calling vcard_emul_logout.

Signed-off-by: Ray Strode 
Reviewed-By: Robert Relyea 
Reviewed-By: Alon Levy 
---
 libcacard/vcard.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libcacard/vcard.c b/libcacard/vcard.c
index 539177b..cf02a25 100644
--- a/libcacard/vcard.c
+++ b/libcacard/vcard.c
@@ -243,60 +243,65 @@ vcard_find_applet(VCard *card, unsigned char *aid, int 
aid_len)
 {
 VCardApplet *current_applet;
 
 for (current_applet = card->applet_list; current_applet;
 current_applet = current_applet->next) 
{
 if (current_applet->aid_len != aid_len) {
 continue;
 }
 if (memcmp(current_applet->aid, aid, aid_len) == 0) {
 break;
 }
 }
 return current_applet;
 }
 
 unsigned char *
 vcard_applet_get_aid(VCardApplet *applet, int *aid_len)
 {
 if (applet == NULL) {
 return NULL;
 }
 *aid_len = applet->aid_len;
 return applet->aid;
 }
 
 
 void
 vcard_select_applet(VCard *card, int channel, VCardApplet *applet)
 {
 assert(channel < MAX_CHANNEL);
+
+/* If using an emulated card, make sure to log out of any already logged in
+ * session. */
+vcard_emul_logout(card);
+
 card->current_applet[channel] = applet;
 /* reset the applet */
 if (applet && applet->reset_applet) {
 applet->reset_applet(card, channel);
 }
 }
 
 VCardAppletPrivate *
 vcard_get_current_applet_private(VCard *card, int channel)
 {
 VCardApplet *applet = card->current_applet[channel];
 
 if (applet == NULL) {
 return NULL;
 }
 return applet->applet_private;
 }
 
 VCardStatus
 vcard_process_applet_apdu(VCard *card, VCardAPDU *apdu,
   VCardResponse **response)
 {
 if (card->current_applet[apdu->a_channel]) {
 return card->current_applet[apdu->a_channel]->process_apdu(
 card, apdu, response);
 }
 return VCARD_NEXT;
 }
 
 /*
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH] Quote extra_cflags in config-host.mak

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 15:41, Gabriel Kerneis ha scritto:
> The variable extra_cflags needs to be quoted in config-host.mak,
> in particular because it might contain parentheses that would
> otherwise be interpreted by the shell when reloading the file.
> 
> For instance, if one wants to define some attribute with configure:
> 
> ./configure --extra-cflags="-Dcoroutine_fn='__attribute__((coroutine_fn))'"
> 
> A more robust approach would be to escape every variable properly, but
> there is no portable equivalent to bash's "printf %q" solution. The
> current patch, while not bullet-proof, works well in the common case.
> 
> Signed-off-by: Gabriel Kerneis 

Where does the shell read config-host.mak?  Make does not need the quotes.

Paolo



[Qemu-devel] [PATCHv2 1/2] libcacard: introduce new vcard_emul_logout

2013-09-11 Thread Ray Strode
From: Ray Strode 

vcard_emul_reset currently only logs NSS out, but there is a TODO
for potentially sending insertion/removal events when powering down
or powering up.

For clarity, this commit moves the current guts of vcard_emul_reset to
a new vcard_emul_logout function which will never send insertion/removal
events. The vcard_emul_reset function now just calls vcard_emul_logout,
but also retains its TODO for watching power state transitions and sending
insertion/removal events.

Signed-off-by: Ray Strode 
Reviewed-By: Robert Relyea 
Reviewed-By: Alon Levy 
---
 libcacard/vcard_emul.h |  1 +
 libcacard/vcard_emul_nss.c | 16 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/libcacard/vcard_emul.h b/libcacard/vcard_emul.h
index 963563f..f09ee98 100644
--- a/libcacard/vcard_emul.h
+++ b/libcacard/vcard_emul.h
@@ -13,53 +13,54 @@
 #ifndef VCARD_EMUL_H
 #define VCARD_EMUL_H 1
 
 #include "card_7816t.h"
 #include "vcard.h"
 #include "vcard_emul_type.h"
 
 /*
  * types
  */
 typedef enum {
 VCARD_EMUL_OK = 0,
 VCARD_EMUL_FAIL,
 /* return values by vcard_emul_init */
 VCARD_EMUL_INIT_ALREADY_INITED,
 } VCardEmulError;
 
 /* options are emul specific. call card_emul_parse_args to change a string
  * To an options struct */
 typedef struct VCardEmulOptionsStruct VCardEmulOptions;
 
 /*
  * Login functions
  */
 /* return the number of login attempts still possible on the card. if unknown,
  * return -1 */
 int vcard_emul_get_login_count(VCard *card);
 /* login into the card, return the 7816 status word (sw2 || sw1) */
 vcard_7816_status_t vcard_emul_login(VCard *card, unsigned char *pin,
  int pin_len);
+void vcard_emul_logout(VCard *card);
 
 /*
  * key functions
  */
 /* delete a key */
 void vcard_emul_delete_key(VCardKey *key);
 /* RSA sign/decrypt with the key, signature happens 'in place' */
 vcard_7816_status_t vcard_emul_rsa_op(VCard *card, VCardKey *key,
   unsigned char *buffer, int buffer_size);
 
 void vcard_emul_reset(VCard *card, VCardPower power);
 void vcard_emul_get_atr(VCard *card, unsigned char *atr, int *atr_len);
 
 /* Re-insert of a card that has been removed by force removal */
 VCardEmulError vcard_emul_force_card_insert(VReader *vreader);
 /* Force a card removal even if the card is not physically removed */
 VCardEmulError vcard_emul_force_card_remove(VReader *vreader);
 
 VCardEmulOptions *vcard_emul_options(const char *args);
 VCardEmulError vcard_emul_init(const VCardEmulOptions *options);
 void vcard_emul_replay_insertion_events(void);
 void vcard_emul_usage(void);
 #endif
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index fb429b1..c3a26d7 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -374,78 +374,86 @@ vcard_emul_login(VCard *card, unsigned char *pin, int 
pin_len)
 if (!nss_emul_init) {
 return VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED;
 }
 slot = vcard_emul_card_get_slot(card);
  /* We depend on the PKCS #11 module internal login state here because we
   * create a separate process to handle each guest instance. If we needed
   * to handle multiple guests from one process, then we would need to keep
   * a lot of extra state in our card structure
   * */
 pin_string = g_malloc(pin_len+1);
 memcpy(pin_string, pin, pin_len);
 pin_string[pin_len] = 0;
 
 /* handle CAC expanded pins correctly */
 for (i = pin_len-1; i >= 0 && (pin_string[i] == 0xff); i--) {
 pin_string[i] = 0;
 }
 
 rv = PK11_Authenticate(slot, PR_FALSE, pin_string);
 memset(pin_string, 0, pin_len);  /* don't let the pin hang around in memory
 to be snooped */
 g_free(pin_string);
 if (rv == SECSuccess) {
 return VCARD7816_STATUS_SUCCESS;
 }
 /* map the error from port get error */
 return VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED;
 }
 
 void
-vcard_emul_reset(VCard *card, VCardPower power)
+vcard_emul_logout(VCard *card)
 {
 PK11SlotInfo *slot;
 
 if (!nss_emul_init) {
 return;
 }
 
+slot = vcard_emul_card_get_slot(card);
+if (PK11_IsLoggedIn(slot,NULL)) {
+PK11_Logout(slot); /* NOTE: ignoring SECStatus return value */
+}
+}
+
+void
+vcard_emul_reset(VCard *card, VCardPower power)
+{
 /*
  * if we reset the card (either power on or power off), we lose our login
  * state
  */
+vcard_emul_logout(card);
+
 /* TODO: we may also need to send insertion/removal events? */
-slot = vcard_emul_card_get_slot(card);
-PK11_Logout(slot); /* NOTE: ignoring SECStatus return value */
 }
 
-
 static VReader *
 vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot)
 {
 VReaderList *reader_list = vreader_get_reader_list();
 VReaderListEntry *current_entry = NULL;
 
 if (reader_list == NULL) {
 return NULL;
 }
 fo

Re: [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function

2013-09-11 Thread Peter Maydell
On 11 September 2013 06:38, Fam Zheng  wrote:
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -34,6 +34,7 @@
>  #include "qemu/timer.h"
>  #include "qemu/envlist.h"
>  #include "elf.h"
> +#include 
>
>  char *exec_path;
>
> @@ -3551,6 +3552,8 @@ int main(int argc, char **argv, char **envp)
>  int i;
>  int ret;
>
> +module_load(MODULE_LOAD_UI);
> +module_load(MODULE_LOAD_NET);
>  module_call_init(MODULE_INIT_QOM);

This looks kind of fishy. The *-user binaries don't even
have any UI, and they shouldn't be using the networking
either. For that matter it's really unclear to me that they
should have any kind of loadable modules at all.

-- PMM



Re: [Qemu-devel] [PATCH v6 6/8] Makefile: install modules with "make install"

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 15:34, Fam Zheng ha scritto:
> Install all the subdirs for modules under configure option "moddir".
> 
> Signed-off-by: Fam Zheng 
> ---
>  Makefile | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index c50b4b3..ca84d32 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -360,6 +360,12 @@ install-datadir install-localstatedir
>  ifneq ($(TOOLS),)
>   $(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
>  endif
> +ifneq ($(CONFIG_MODULES),)

Perhaps modules-m instead of CONFIG_MODULES would be more clearer given
the "for" line immediately below.

> + for s in $(patsubst %.mo,%.so,$(modules-m)); do \

DSOSUF here.

> + $(INSTALL_DIR) "$(DESTDIR)$(moddir)/$$(dirname $$s)"; \
> + $(INSTALL_PROG) $(STRIP_OPT) $$s 
> "$(DESTDIR)$(moddir)/$$(dirname $$s)"; \

Paolo

> + done
> +endif
>  ifneq ($(HELPERS-y),)
>   $(INSTALL_DIR) "$(DESTDIR)$(libexecdir)"
>   $(INSTALL_PROG) $(STRIP_OPT) $(HELPERS-y) "$(DESTDIR)$(libexecdir)"
> 




[Qemu-devel] [PATCH v6 0/8] Shared Library Module Support

2013-09-11 Thread Fam Zheng
This series implements feature of shared object building as described in:

http://wiki.qemu.org/Features/Modules

The main idea behind modules is to isolate dependencies on third party
libraries from qemu executables, such as libglusterfs or librbd, so that the
end users can install core qemu package with fewer dependencies.  And only for
those who want to use particular modules, need they install qemu-foo
sub-package, which in turn requires libbar and libbiz packages.

It's implemented in three steps:

1. The first patches fix current build system to correctly handle nested
   variables and object specific options:

[01/08] make.rule: fix $(obj) to a real relative path
[02/08] rule.mak: allow per object cflags and libs

2. The Makefile changes adds necessary options and rules to build DSO objects:

[03/08] Makefile: introduce common-obj-m and block-obj-m for DSO

3. The next patch adds framework to load modules from installed directory:

[04/08] module: implement module loading function

A few more changes are following to complete it:

[05/08] configure: introduce --enable-modules
[06/08] Makefile: install modules with "make install"
[07/08] .gitignore: ignore module related files (dll, so, mo)

In the end of series, the block drivers are converted:

[08/08] block: convert block drivers linked with libs to modules


v6: Dropping RFC.

[01] Move addprefix to unnest-vars.
[01] Drop unnest-vars in tests/Makefile.
[03] Move "all: modules" to Makefile.
[03] Add empty modules: in rules.mak, for clarity.
[03] .mo is no longer storing object list, just an empty file now. In
expand-objs, objects are extracted with $foo.mo-objs). another reason for
this is for makefile.target, objects in .mo file would be prefixed with
../, so generated two times in one "make all", which always outdates the
link target.
[04] Use CONFIG_MODDIR instead of CONFIG_PREFIX for module searching.
[06] Added make install.
[07] New.
[08] Drop qed changes, added iscsi, ssh, rbd and gluster as modules.

v5: Keep foo.mo-objs idea for module objects.
Unnest block-obj-m and common-obj-m in Makefile.target.
Move add-modules to unnest-vars to be reused in Makefile.target.
Use /dev/null to replace realpath for expand-objs.

v4: Added --enable-modules in the end of series.
Make nested-vars and obj-base as arguemnts to unnest-vars.
Take Paolo's idea in comments for v2 and switch back module objects syntax
to:
$(obj)/foo.mo : $(addprefix $(obj)/, bar.o biz.o qux.o)

because this needs less duplication among Makefiles.


Fam Zheng (8):
  make.rule: fix $(obj) to a real relative path
  rule.mak: allow per object cflags and libs
  Makefile: introduce common-obj-m and block-obj-m for DSO
  module: implement module loading function
  configure: introduce --enable-modules
  Makefile: install modules with "make install"
  .gitignore: ignore module related files (dll, so, mo)
  block: convert block drivers linked with libs to modules

 .gitignore|  3 ++
 Makefile  | 30 ++--
 Makefile.objs | 18 ++--
 Makefile.target   | 21 +++---
 block.c   |  1 +
 block/Makefile.objs   | 11 +++-
 bsd-user/main.c   |  3 ++
 configure | 74 +++-
 include/qemu/module.h |  9 ++
 linux-user/main.c |  3 ++
 rules.mak | 78 ++-
 scripts/create_config |  7 +
 util/module.c | 53 ++
 vl.c  |  2 ++
 14 files changed, 252 insertions(+), 61 deletions(-)

-- 
1.8.3.1




Re: [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function

2013-09-11 Thread Paolo Bonzini
Il 11/09/2013 16:10, Alex Bligh ha scritto:
> 
> 
> --On 11 September 2013 13:38:27 +0800 Fam Zheng  wrote:
> 
>> +switch (type) {
>> +case MODULE_LOAD_BLOCK:
>> +path = CONFIG_PREFIX "/qemu/block/";
>> +break;
>> +case MODULE_LOAD_UI:
>> +path = CONFIG_PREFIX "/qemu/ui/";
>> +break;
>> +case MODULE_LOAD_NET:
>> +path = CONFIG_PREFIX "/qemu/net/";
>> +break;
>> +default:
>> +return;
>> +}
>> +
> 
> I appreciate I am coming in late into this discussion, and am only scanning
> the code quickly, so apologies if I have the wrong end of the stick.

You're absolutely not coming in late!  So far we really just discussed
the build side of the implementation, and I didn't review this patch at all.

> This APPEARS to load modules from
> a) a fixed path determined at compile time
> b) a path which is not dependent on qemu version

c) a path that is not under the normal /usr/lib or similar path.

> This would make it hard to have 2 versions of qemu installed on a
> system at once, or even develop one version of qemu with another
> version installed.

This is hard anyway because the firmware files are not necessarily
compatible with different QEMU versions.  With 2 versions of QEMU
installed on a system, I would suggest putting both of them in different
subdirectories under /opt.

However, (c) is a problem and...

> I suspect this will be hard not only for developers,
> but also for distributions, particularly if the idea is to keep vms
> running during upgrades. Consider the case where packages A and B
> both depend on qemu module package C, then you wish to upgrade to
> A', B' and C'. At some point you are likely to want both C and C'
> installed. Is the idea here that QEMU is always built with CONFIG_PREFIX
> having versioning inside it (in a distro environment)?
> 
> Can I suggest that at the very least, it should be possible to specify
> an alternate path to the module directory via the CLI?

... this is also a good idea.  Probably it should use an algorithm
similar to that used for data_dir.

Paolo




Re: [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function

2013-09-11 Thread Alex Bligh



--On 11 September 2013 13:38:27 +0800 Fam Zheng  wrote:


+switch (type) {
+case MODULE_LOAD_BLOCK:
+path = CONFIG_PREFIX "/qemu/block/";
+break;
+case MODULE_LOAD_UI:
+path = CONFIG_PREFIX "/qemu/ui/";
+break;
+case MODULE_LOAD_NET:
+path = CONFIG_PREFIX "/qemu/net/";
+break;
+default:
+return;
+}
+


I appreciate I am coming in late into this discussion, and am only scanning
the code quickly, so apologies if I have the wrong end of the stick.

This APPEARS to load modules from
a) a fixed path determined at compile time
b) a path which is not dependent on qemu version

This would make it hard to have 2 versions of qemu installed on a
system at once, or even develop one version of qemu with another
version installed. I suspect this will be hard not only for developers,
but also for distributions, particularly if the idea is to keep vms
running during upgrades. Consider the case where packages A and B
both depend on qemu module package C, then you wish to upgrade to
A', B' and C'. At some point you are likely to want both C and C'
installed. Is the idea here that QEMU is always built with CONFIG_PREFIX
having versioning inside it (in a distro environment)?

Can I suggest that at the very least, it should be possible to specify
an alternate path to the module directory via the CLI?

--
Alex Bligh



[Qemu-devel] [PATCH v4 17/24] arm11mpcore: Create container MemoryRegion in instance_init

2013-09-11 Thread Andreas Färber
This allows to map the region directly after object initialization.

Signed-off-by: Andreas Färber 
---
 hw/cpu/arm11mpcore.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/hw/cpu/arm11mpcore.c b/hw/cpu/arm11mpcore.c
index 8719634..5f80e7b 100644
--- a/hw/cpu/arm11mpcore.c
+++ b/hw/cpu/arm11mpcore.c
@@ -90,8 +90,6 @@ static void mpcore_priv_map_setup(ARM11MPCorePriveState *s)
 SysBusDevice *gicbusdev = SYS_BUS_DEVICE(s->gic);
 SysBusDevice *timerbusdev = SYS_BUS_DEVICE(s->mptimer);
 SysBusDevice *wdtbusdev = SYS_BUS_DEVICE(s->wdtimer);
-memory_region_init(&s->container, OBJECT(s),
-   "mpcore-priv-container", 0x2000);
 memory_region_init_io(&s->iomem, OBJECT(s),
   &mpcore_scu_ops, s, "mpcore-scu", 0x100);
 memory_region_add_subregion(&s->container, 0, &s->iomem);
@@ -155,10 +153,19 @@ static int mpcore_priv_init(SysBusDevice *sbd)
 qdev_init_nofail(s->wdtimer);
 
 mpcore_priv_map_setup(s);
-sysbus_init_mmio(sbd, &s->container);
 return 0;
 }
 
+static void mpcore_priv_initfn(Object *obj)
+{
+SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+ARM11MPCorePriveState *s = ARM11MPCORE_PRIV(obj);
+
+memory_region_init(&s->container, OBJECT(s),
+   "mpcore-priv-container", 0x2000);
+sysbus_init_mmio(sbd, &s->container);
+}
+
 #define TYPE_REALVIEW_MPCORE_RIRQ "realview_mpcore"
 #define REALVIEW_MPCORE_RIRQ(obj) \
 OBJECT_CHECK(mpcore_rirq_state, (obj), TYPE_REALVIEW_MPCORE_RIRQ)
@@ -277,6 +284,7 @@ static const TypeInfo mpcore_priv_info = {
 .name  = TYPE_ARM11MPCORE_PRIV,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(ARM11MPCorePriveState),
+.instance_init = mpcore_priv_initfn,
 .class_init= mpcore_priv_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 04/24] a9scu: QOM cleanups

2013-09-11 Thread Andreas Färber
From: Andreas Färber 

Rename A9SCUState::busdev field to parent_obj and turn realizefn into an
instance_init function to allow early MMIO mapping.

Reviewed-by: Peter Crosthwaite 
Signed-off-by: Andreas Färber 
---
 hw/misc/a9scu.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
index 601b573..2661014 100644
--- a/hw/misc/a9scu.c
+++ b/hw/misc/a9scu.c
@@ -13,7 +13,10 @@
 /* A9MP private memory region.  */
 
 typedef struct A9SCUState {
-SysBusDevice busdev;
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
 MemoryRegion iomem;
 uint32_t control;
 uint32_t status;
@@ -114,12 +117,12 @@ static void a9_scu_reset(DeviceState *dev)
 s->control = 0;
 }
 
-static void a9_scu_realize(DeviceState *dev, Error ** errp)
+static void a9_scu_init(Object *obj)
 {
-A9SCUState *s = A9_SCU(dev);
-SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+A9SCUState *s = A9_SCU(obj);
+SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-memory_region_init_io(&s->iomem, OBJECT(dev), &a9_scu_ops, s,
+memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
   "a9-scu", 0x100);
 sysbus_init_mmio(sbd, &s->iomem);
 }
@@ -144,7 +147,6 @@ static void a9_scu_class_init(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc->realize = a9_scu_realize;
 dc->props = a9_scu_properties;
 dc->vmsd = &vmstate_a9_scu;
 dc->reset = a9_scu_reset;
@@ -154,6 +156,7 @@ static const TypeInfo a9_scu_info = {
 .name  = TYPE_A9_SCU,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(A9SCUState),
+.instance_init = a9_scu_init,
 .class_init= a9_scu_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 00/24] arm: ARM11MPCore+A9MPCore+A15MPCore QOM'ification

2013-09-11 Thread Andreas Färber
From: Andreas Färber 

Hello Peter,

This series fully QOM'ifies A9MPCore so that it can be embedded for Tegra2.
It goes on to do the same for A15MPCore, which had previously been taken as
template for Cortex-A57 by John Rigby, and since v3 ARM11MPCore.

Separate headers are introduced to only expose device state to whom asks for it.

v4 is a rebase that addresses concerns about potential future GICState
size mismatches by asserting in QOM infrastructure.

Regards,
Andreas

v3 -> v4:
* Rebased; object_initialize() now takes additional size argument.
* Subject prefixes unified.

v2 -> v3:
* Split off hw/intc/arm_gic_common.h from new arm_gic.h (PMM).
* Added patches converting arm11mpcore, too.
* Split off arm11scu from arm11mpcore, following a9scu/a9mpcore model.
* Added patch to enforce building a9scu only once.
* Split off RealView MPCore from ARM11 MPCore using a new arm11mpcore.h.

v1 -> v2:
* Renamed MP_TIMER to MPTIMER (Peter C.).
* Don't include gic_internal.h, introduce new arm_gic.h header (PMM).
* a9mpcore: Init only container MemoryRegion in instance_init (Peter C.).
* a9mpcore/a15mpcore: Replaced all qdev_init_nofail()s for error propagation.

Cc: Peter Maydell 
Cc: Peter Crosthwaite 
Cc: Mian M. Hamayun 
Cc: Claudio Fontana 

Andreas Färber (24):
  a9mpcore: Split off instance_init
  arm_gic: Extract headers hw/intc/arm_gic{,_common}.h
  a9mpcore: Embed GICState
  a9scu: QOM cleanups
  a9mpcore: Embed A9SCUState
  arm_mptimer: Convert to QOM realize
  a9mpcore: Embed ARMMPTimerState
  a9mpcore: Convert to QOM realize
  a9mpcore: Prepare for QOM embedding
  a15mpcore: Split off instance_init
  a15mpcore: Embed GICState
  a15mpcore: Convert to QOM realize
  a15mpcore: Prepare for QOM embedding
  a9scu: Build only once
  arm11mpcore: Fix typo in MemoryRegion name
  arm11mpcore: Drop unused fields
  arm11mpcore: Create container MemoryRegion in instance_init
  arm11mpcore: Split off SCU device
  arm11mpcore: Convert ARM11MPCorePriveState to QOM realize
  realview_gic: Convert to QOM realize
  realview_gic: Prepare for QOM embedding
  arm11mpcore: Convert mpcore_rirq_state to QOM realize
  arm11mpcore: Prepare for QOM embedding
  arm11mpcore: Split off RealView MPCore

 default-configs/arm-softmmu.mak  |   1 +
 hw/cpu/Makefile.objs |   1 +
 hw/cpu/a15mpcore.c   |  81 ++---
 hw/cpu/a9mpcore.c| 120 +++
 hw/cpu/arm11mpcore.c | 251 ++-
 hw/cpu/realview_mpcore.c | 139 ++
 hw/intc/arm_gic_common.c |  18 +--
 hw/intc/gic_internal.h   |  80 +
 hw/intc/realview_gic.c   |  58 +
 hw/misc/Makefile.objs|   3 +-
 hw/misc/a9scu.c  |  25 +---
 hw/misc/arm11scu.c   | 100 
 hw/timer/arm_mptimer.c   |  60 +++---
 include/hw/cpu/a15mpcore.h   |  44 +++
 include/hw/cpu/a9mpcore.h|  37 ++
 include/hw/cpu/arm11mpcore.h |  35 ++
 include/hw/intc/arm_gic.h|  42 +++
 include/hw/intc/arm_gic_common.h |  92 ++
 include/hw/intc/realview_gic.h   |  28 +
 include/hw/misc/a9scu.h  |  31 +
 include/hw/misc/arm11scu.h   |  29 +
 include/hw/timer/arm_mptimer.h   |  54 +
 22 files changed, 879 insertions(+), 450 deletions(-)
 create mode 100644 hw/cpu/realview_mpcore.c
 create mode 100644 hw/misc/arm11scu.c
 create mode 100644 include/hw/cpu/a15mpcore.h
 create mode 100644 include/hw/cpu/a9mpcore.h
 create mode 100644 include/hw/cpu/arm11mpcore.h
 create mode 100644 include/hw/intc/arm_gic.h
 create mode 100644 include/hw/intc/arm_gic_common.h
 create mode 100644 include/hw/intc/realview_gic.h
 create mode 100644 include/hw/misc/a9scu.h
 create mode 100644 include/hw/misc/arm11scu.h
 create mode 100644 include/hw/timer/arm_mptimer.h

-- 
1.8.1.4




[Qemu-devel] [PATCH v4 15/24] arm11mpcore: Fix typo in MemoryRegion name

2013-09-11 Thread Andreas Färber
"mpcode" -> "mpcore"

Signed-off-by: Andreas Färber 
---
 hw/cpu/arm11mpcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/cpu/arm11mpcore.c b/hw/cpu/arm11mpcore.c
index a786c62..27cd32b 100644
--- a/hw/cpu/arm11mpcore.c
+++ b/hw/cpu/arm11mpcore.c
@@ -93,7 +93,7 @@ static void mpcore_priv_map_setup(ARM11MPCorePriveState *s)
 SysBusDevice *timerbusdev = SYS_BUS_DEVICE(s->mptimer);
 SysBusDevice *wdtbusdev = SYS_BUS_DEVICE(s->wdtimer);
 memory_region_init(&s->container, OBJECT(s),
-   "mpcode-priv-container", 0x2000);
+   "mpcore-priv-container", 0x2000);
 memory_region_init_io(&s->iomem, OBJECT(s),
   &mpcore_scu_ops, s, "mpcore-scu", 0x100);
 memory_region_add_subregion(&s->container, 0, &s->iomem);
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 13/24] a15mpcore: Prepare for QOM embedding

2013-09-11 Thread Andreas Färber
From: Andreas Färber 

Signed-off-by: Andreas Färber 
---
 hw/cpu/a15mpcore.c | 21 +
 include/hw/cpu/a15mpcore.h | 44 
 2 files changed, 45 insertions(+), 20 deletions(-)
 create mode 100644 include/hw/cpu/a15mpcore.h

diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
index 10dc35a..acc419e 100644
--- a/hw/cpu/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
@@ -18,27 +18,8 @@
  * with this program; if not, see .
  */
 
-#include "hw/sysbus.h"
+#include "hw/cpu/a15mpcore.h"
 #include "sysemu/kvm.h"
-#include "hw/intc/arm_gic.h"
-
-/* A15MP private memory region.  */
-
-#define TYPE_A15MPCORE_PRIV "a15mpcore_priv"
-#define A15MPCORE_PRIV(obj) \
-OBJECT_CHECK(A15MPPrivState, (obj), TYPE_A15MPCORE_PRIV)
-
-typedef struct A15MPPrivState {
-/*< private >*/
-SysBusDevice parent_obj;
-/*< public >*/
-
-uint32_t num_cpu;
-uint32_t num_irq;
-MemoryRegion container;
-
-GICState gic;
-} A15MPPrivState;
 
 static void a15mp_priv_set_irq(void *opaque, int irq, int level)
 {
diff --git a/include/hw/cpu/a15mpcore.h b/include/hw/cpu/a15mpcore.h
new file mode 100644
index 000..b423533
--- /dev/null
+++ b/include/hw/cpu/a15mpcore.h
@@ -0,0 +1,44 @@
+/*
+ * Cortex-A15MPCore internal peripheral emulation.
+ *
+ * Copyright (c) 2012 Linaro Limited.
+ * Written by Peter Maydell.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+#ifndef HW_CPU_A15MPCORE_H
+#define HW_CPU_A15MPCORE_H
+
+#include "hw/sysbus.h"
+#include "hw/intc/arm_gic.h"
+
+/* A15MP private memory region.  */
+
+#define TYPE_A15MPCORE_PRIV "a15mpcore_priv"
+#define A15MPCORE_PRIV(obj) \
+OBJECT_CHECK(A15MPPrivState, (obj), TYPE_A15MPCORE_PRIV)
+
+typedef struct A15MPPrivState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+uint32_t num_cpu;
+uint32_t num_irq;
+MemoryRegion container;
+
+GICState gic;
+} A15MPPrivState;
+
+#endif
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 06/24] arm_mptimer: Convert to QOM realize

2013-09-11 Thread Andreas Färber
From: Andreas Färber 

Split the SysBusDevice initfn into instance_init and realizefn.

Signed-off-by: Andreas Färber 
---
 hw/timer/arm_mptimer.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
index 8020c9f..2853db4 100644
--- a/hw/timer/arm_mptimer.c
+++ b/hw/timer/arm_mptimer.c
@@ -225,8 +225,18 @@ static void arm_mptimer_reset(DeviceState *dev)
 }
 }
 
-static int arm_mptimer_init(SysBusDevice *dev)
+static void arm_mptimer_init(Object *obj)
 {
+ARMMPTimerState *s = ARM_MPTIMER(obj);
+
+memory_region_init_io(&s->iomem, obj, &arm_thistimer_ops, s,
+  "arm_mptimer_timer", 0x20);
+sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static void arm_mptimer_realize(DeviceState *dev, Error **errp)
+{
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 ARMMPTimerState *s = ARM_MPTIMER(dev);
 int i;
 
@@ -243,19 +253,14 @@ static int arm_mptimer_init(SysBusDevice *dev)
  *  * timer for core 1
  * and so on.
  */
-memory_region_init_io(&s->iomem, OBJECT(s), &arm_thistimer_ops, s,
-  "arm_mptimer_timer", 0x20);
-sysbus_init_mmio(dev, &s->iomem);
 for (i = 0; i < s->num_cpu; i++) {
 TimerBlock *tb = &s->timerblock[i];
 tb->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, timerblock_tick, tb);
-sysbus_init_irq(dev, &tb->irq);
+sysbus_init_irq(sbd, &tb->irq);
 memory_region_init_io(&tb->iomem, OBJECT(s), &timerblock_ops, tb,
   "arm_mptimer_timerblock", 0x20);
-sysbus_init_mmio(dev, &tb->iomem);
+sysbus_init_mmio(sbd, &tb->iomem);
 }
-
-return 0;
 }
 
 static const VMStateDescription vmstate_timerblock = {
@@ -292,9 +297,8 @@ static Property arm_mptimer_properties[] = {
 static void arm_mptimer_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
 
-sbc->init = arm_mptimer_init;
+dc->realize = arm_mptimer_realize;
 dc->vmsd = &vmstate_arm_mptimer;
 dc->reset = arm_mptimer_reset;
 dc->no_user = 1;
@@ -305,6 +309,7 @@ static const TypeInfo arm_mptimer_info = {
 .name  = TYPE_ARM_MPTIMER,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(ARMMPTimerState),
+.instance_init = arm_mptimer_init,
 .class_init= arm_mptimer_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 07/24] a9mpcore: Embed ARMMPTimerState

2013-09-11 Thread Andreas Färber
From: Andreas Färber 

Prepares for QOM realize.

Signed-off-by: Andreas Färber 
---
 hw/cpu/a9mpcore.c  | 29 ++-
 hw/timer/arm_mptimer.c | 35 ---
 include/hw/timer/arm_mptimer.h | 54 ++
 3 files changed, 76 insertions(+), 42 deletions(-)
 create mode 100644 include/hw/timer/arm_mptimer.h

diff --git a/hw/cpu/a9mpcore.c b/hw/cpu/a9mpcore.c
index df92e3f..db3907e 100644
--- a/hw/cpu/a9mpcore.c
+++ b/hw/cpu/a9mpcore.c
@@ -11,6 +11,7 @@
 #include "hw/sysbus.h"
 #include "hw/intc/arm_gic.h"
 #include "hw/misc/a9scu.h"
+#include "hw/timer/arm_mptimer.h"
 
 #define TYPE_A9MPCORE_PRIV "a9mpcore_priv"
 #define A9MPCORE_PRIV(obj) \
@@ -23,12 +24,12 @@ typedef struct A9MPPrivState {
 
 uint32_t num_cpu;
 MemoryRegion container;
-DeviceState *mptimer;
-DeviceState *wdt;
 uint32_t num_irq;
 
 GICState gic;
 A9SCUState scu;
+ARMMPTimerState mptimer;
+ARMMPTimerState wdt;
 } A9MPPrivState;
 
 static void a9mp_priv_set_irq(void *opaque, int irq, int level)
@@ -50,12 +51,18 @@ static void a9mp_priv_initfn(Object *obj)
 
 object_initialize(&s->scu, sizeof(s->scu), TYPE_A9_SCU);
 qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default());
+
+object_initialize(&s->mptimer, sizeof(s->mptimer), TYPE_ARM_MPTIMER);
+qdev_set_parent_bus(DEVICE(&s->mptimer), sysbus_get_default());
+
+object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ARM_MPTIMER);
+qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default());
 }
 
 static int a9mp_priv_init(SysBusDevice *dev)
 {
 A9MPPrivState *s = A9MPCORE_PRIV(dev);
-DeviceState *gicdev, *scudev;
+DeviceState *gicdev, *scudev, *mptimerdev, *wdtdev;
 SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev;
 int i;
 
@@ -76,15 +83,15 @@ static int a9mp_priv_init(SysBusDevice *dev)
 qdev_init_nofail(scudev);
 scubusdev = SYS_BUS_DEVICE(&s->scu);
 
-s->mptimer = qdev_create(NULL, "arm_mptimer");
-qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
-qdev_init_nofail(s->mptimer);
-timerbusdev = SYS_BUS_DEVICE(s->mptimer);
+mptimerdev = DEVICE(&s->mptimer);
+qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
+qdev_init_nofail(mptimerdev);
+timerbusdev = SYS_BUS_DEVICE(&s->mptimer);
 
-s->wdt = qdev_create(NULL, "arm_mptimer");
-qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu);
-qdev_init_nofail(s->wdt);
-wdtbusdev = SYS_BUS_DEVICE(s->wdt);
+wdtdev = DEVICE(&s->wdt);
+qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
+qdev_init_nofail(wdtdev);
+wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
 
 /* Memory map (addresses are offsets from PERIPHBASE):
  *  0x-0x00ff -- Snoop Control Unit
diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
index 2853db4..d9f9494 100644
--- a/hw/timer/arm_mptimer.c
+++ b/hw/timer/arm_mptimer.c
@@ -19,7 +19,7 @@
  * with this program; if not, see .
  */
 
-#include "hw/sysbus.h"
+#include "hw/timer/arm_mptimer.h"
 #include "qemu/timer.h"
 #include "qom/cpu.h"
 
@@ -27,34 +27,6 @@
  * which is used in both the ARM11MPCore and Cortex-A9MP.
  */
 
-#define MAX_CPUS 4
-
-/* State of a single timer or watchdog block */
-typedef struct {
-uint32_t count;
-uint32_t load;
-uint32_t control;
-uint32_t status;
-int64_t tick;
-QEMUTimer *timer;
-qemu_irq irq;
-MemoryRegion iomem;
-} TimerBlock;
-
-#define TYPE_ARM_MPTIMER "arm_mptimer"
-#define ARM_MPTIMER(obj) \
-OBJECT_CHECK(ARMMPTimerState, (obj), TYPE_ARM_MPTIMER)
-
-typedef struct {
-/*< private >*/
-SysBusDevice parent_obj;
-/*< public >*/
-
-uint32_t num_cpu;
-TimerBlock timerblock[MAX_CPUS];
-MemoryRegion iomem;
-} ARMMPTimerState;
-
 static inline int get_current_cpu(ARMMPTimerState *s)
 {
 if (current_cpu->cpu_index >= s->num_cpu) {
@@ -240,8 +212,9 @@ static void arm_mptimer_realize(DeviceState *dev, Error 
**errp)
 ARMMPTimerState *s = ARM_MPTIMER(dev);
 int i;
 
-if (s->num_cpu < 1 || s->num_cpu > MAX_CPUS) {
-hw_error("%s: num-cpu must be between 1 and %d\n", __func__, MAX_CPUS);
+if (s->num_cpu < 1 || s->num_cpu > ARM_MPTIMER_MAX_CPUS) {
+hw_error("%s: num-cpu must be between 1 and %d\n",
+ __func__, ARM_MPTIMER_MAX_CPUS);
 }
 /* We implement one timer block per CPU, and expose multiple MMIO regions:
  *  * region 0 is "timer for this core"
diff --git a/include/hw/timer/arm_mptimer.h b/include/hw/timer/arm_mptimer.h
new file mode 100644
index 000..b34cba0
--- /dev/null
+++ b/include/hw/timer/arm_mptimer.h
@@ -0,0 +1,54 @@
+/*
+ * Private peripheral timer/watchdog blocks for ARM 11MPCore and A9MP
+ *
+ * Copyright (c) 2006-2007 CodeSourcery.
+ * Copyright (c) 2011 Linaro Limited
+ * Written by Paul Brook, Peter Maydell
+ *
+ * This program is free software; you can redistribute it and/or
+

  1   2   3   >