Re: [Qemu-devel] [PATCH v2 6/6] monitor: convert do_cpu_set() to QObject, QError

2010-01-27 Thread Markus Armbruster
Anthony Liguori anth...@codemonkey.ws writes:

 On 01/20/2010 06:07 AM, Markus Armbruster wrote:
 Signed-off-by: Markus Armbrusterarm...@redhat.com
 ---
   monitor.c   |4 ++--
   qemu-monitor.hx |3 ++-
   2 files changed, 4 insertions(+), 3 deletions(-)

 diff --git a/monitor.c b/monitor.c
 index 816f6fd..b9166c3 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -808,11 +808,11 @@ static void do_info_cpus(Monitor *mon, QObject 
 **ret_data)
   *ret_data = QOBJECT(cpu_list);
   }

 -static void do_cpu_set(Monitor *mon, const QDict *qdict)
 +static void do_cpu_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
   {
   int index = qdict_get_int(qdict, index);
   if (mon_set_cpu(index)  0)
 -monitor_printf(mon, Invalid CPU index\n);
 +qemu_error_new(QERR_INVALID_CPU_INDEX);


 Just out of curiousity, why introduce a new error verses using
 (QERR_INVALID_PARAMETER, index)?

To avoid changing the non-QMP monitor.  If you don't care about that, I
can revert 5/6 and update 6/6.

Alternatively, here's a trick to reduce the number of client visible QMP
errors while still keeping the old diagnostic on the non-QMP monitor:

+#define QERR_INVALID_CPU_INDEX \
+{ 'class': 'InvalidParameter, 'data': { 'name': 'index' } }
+
 #define QERR_INVALID_PARAMETER \
 { 'class': 'InvalidParameter', 'data': { 'name': %s } }




Re: [Qemu-devel] [PATCH v2 01/10] qcow2: Fix error handling in qcow2_grow_l1_table

2010-01-27 Thread Kevin Wolf
Am 26.01.2010 22:37, schrieb Anthony Liguori:
 On 01/20/2010 08:02 AM, Kevin Wolf wrote:
 Return the appropriate error value instead of always using EIO. Don't free 
 the
 L1 table on errors, we still need it.

 Signed-off-by: Kevin Wolfkw...@redhat.com

 
 Applied all.  Thanks.
 
 Do you think this is stable-0.12 material?  Is there any reasonable 
 scenario where this could fix a user visible bug?

Yes, I think this is something for stable. Obviously the patches are
meant to only make a difference if something has gone wrong in the first
place, but in these cases it's expected to fix possible causes of
corruption (things like data written to clusters with refcount 0). Also
if someone relies on werror=enospc he'll need the right error codes.

Kevin




[Qemu-devel] Re: [PATCHv2] configure: verify stdio.h

2010-01-27 Thread Michael S. Tsirkin
On Tue, Jan 26, 2010 at 10:44:44PM +0100, Stefan Weil wrote:
 Michael S. Tsirkin schrieb:
  Verify that stdio.h supports %lld %zd.
  Some migw variants don't unless requested explicitly (see
 
 migw - mingw
 
 I don't know any ming32 variant which supports %lld, %zd.
 There is a new mingw-w64 were people are addressing the
 problem, 

Did you try with -D__USE_MINGW_ANSI_STDIO=1 ?
This is what the link below mentions.

 but that variant is unsupported by qemu.

What are the issues?

 
  http://www.mail-archive.com/mingw-w64-pub...@lists.sourceforge.net/msg00417.html)
  ), detect them early.
 
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
  Acked-by: Juan Quintela quint...@trasno.org
 
  ---
 
  changes from v1:
  removed leftover chunk
 
  configure | 20 
  1 files changed, 20 insertions(+), 0 deletions(-)
 
  diff --git a/configure b/configure
  index 5631bbb..6ba06d6 100755
  --- a/configure
  +++ b/configure
  @@ -123,6 +123,26 @@ else
  exit 1
  fi
 
  +# Check that stdio.h compiler is sane: some
  +# mingw variants do not support %z %l that we rely on
  +cat  $TMPC EOF
  +#include stddef.h
  +#include stdio.h
  +size_t z = 1;
  +long long ll = 2;
  +int main(void) {
  + printf(z=%zd;ll=%lld;\n, z, ll);
  + return 0;
  +}
  +EOF
  +
  +if compile_prog  ($TMPE | grep z=1;ll=2;  /dev/null); then
  + : C compiler works ok
  +else
  + echo ERROR: \$cc\ does not have a working stdio.h
  + exit 1
  +fi
  +
  check_define() {
  cat  $TMPC EOF
  #if !defined($1)
 
 
 Tests of %lld must use a 64 bit pattern (ll = 0x0123456789abcdefLL).
 Otherwise, %lld, %ld and %d with ll = 1 will all print 1 on little endian
 machines, and the %lld test won't detect missing support.
 
 The problem is now several years old, it can be avoided for really
 important output, so it seems acceptable to wait another period
 of time until a working mingw is supported by qemu.
 
 A test which prevents qemu builds on windows with current mingw32
 or cross builds with current debian cross mingw32 would not help.
 Both variants work for me even without full format support.
 
 Regards,
 Stefan Weil




[Qemu-devel] [RFC] gPXE fw_cfg file interface support

2010-01-27 Thread Stefan Hajnoczi
This patch makes it possible for gPXE under QEMU/KVM to fetch files from the
host using the fw_cfg file interface.  This means gPXE in the guest can fetch an
exposed file from the host without using networking.

I believe this feature will be useful to management software so that
network boot
configuration can be managed alongside with the virtual machine configuration,
not on a remote TFTP server.

Any interest in this feature?  I imagine libvirt could use this to set
up iSCSI or
other network boot settings.

Images are fetched from the hypervisor using the fw_cfg interface provided by
QEMU/KVM.  The URI syntax is as follows:

gPXE imgfetch fw_cfg:genroms/static.gpxe

where 'fw_cfg' is the new URI scheme this patch adds and 'genroms/static.gpxe'
is the filename exported from QEMU/KVM via the fw_cfg interface.

Note that the URI uses a single colon ':', not '://', since there is no
hostname.

Current QEMU/KVM builds can be (ab)used to expose arbitrary files
like this:

qemu -option-rom path/to/file [...]

The file will appear as 'genroms/file'.  Use the 'fw_cfg:genroms/file' URI to
reference it in gPXE.

The fw_cfg file interface is a recent addition to QEMU/KVM.  You may need to
build QEMU/KVM from source in order to get this feature.

Note that this patch only adds the fw_cfg file interface mechanism, it does not
automatically probe for a special file when gPXE starts.  You will
need to manually
chain fw_cfg:genroms/file.

Any comments?

Stefan
From 586b7502ebf3dcfe5ab315052446c6b10bb2637e Mon Sep 17 00:00:00 2001
From: Stefan Hajnoczi stefa...@gmail.com
Date: Thu, 14 Jan 2010 08:55:38 +
Subject: [PATCH] [fw_cfg] Support fetching files from QEMU fw_cfg

This patch adds support for fetching files from the QEMU fw_cfg file
interface, which exposes a set of files on the host into the guest.
Virtual machine netboot configuration can be maintained by a management
layer on the host.  This feature makes virtual machine deployment via
gPXE more flexible.

URIs are in the form fw_cfg:filename, where filename is the name
of the file exposed via fw_cfg.  Note that there are no double slashes
after the fw_cfg:.

Signed-off-by: Stefan Hajnoczi stefa...@gmail.com
---
 src/arch/i386/Makefile   |1 +
 src/arch/i386/firmware/qemu/fw_cfg.c |  300 ++
 src/arch/i386/include/bits/errfile.h |1 +
 src/config/config.c  |3 +
 src/config/general.h |1 +
 5 files changed, 306 insertions(+), 0 deletions(-)
 create mode 100644 src/arch/i386/firmware/qemu/fw_cfg.c

diff --git a/src/arch/i386/Makefile b/src/arch/i386/Makefile
index dd8da80..6ddb86a 100644
--- a/src/arch/i386/Makefile
+++ b/src/arch/i386/Makefile
@@ -75,6 +75,7 @@ ISOLINUX_BIN	= /usr/lib/syslinux/isolinux.bin
 #
 SRCDIRS		+= arch/i386/core arch/i386/transitions arch/i386/prefix
 SRCDIRS		+= arch/i386/firmware/pcbios
+SRCDIRS		+= arch/i386/firmware/qemu
 SRCDIRS		+= arch/i386/image
 SRCDIRS		+= arch/i386/drivers
 SRCDIRS		+= arch/i386/drivers/net
diff --git a/src/arch/i386/firmware/qemu/fw_cfg.c b/src/arch/i386/firmware/qemu/fw_cfg.c
new file mode 100644
index 000..de26ebe
--- /dev/null
+++ b/src/arch/i386/firmware/qemu/fw_cfg.c
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2010 Stefan Hajnoczi stefa...@gmail.com.
+ *
+ * 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 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include stdlib.h
+#include string.h
+#include errno.h
+#include byteswap.h
+#include gpxe/io.h
+#include gpxe/uri.h
+#include gpxe/xfer.h
+#include gpxe/open.h
+#include gpxe/process.h
+
+/** @file
+ *
+ * QEMU firmware configuration interface
+ *
+ * The QEMU firmware configuration interface allows boot firmware access to
+ * configuration key/value pairs in the hypervisor.  This can be used to pass
+ * boot commands when starting a virtual machine.
+ *
+ */
+
+#define FW_CFG_CTL		0x510	/** control I/O port */
+#define FW_CFG_DATA		0x511	/** data I/O port */
+#define FW_CFG_SIGNATURE	0x00	/** magic number */
+#define FW_CFG_ID		0x01	/** interface version */
+#define FW_CFG_FILE_DIR		0x19	/** file listing */
+#define FW_CFG_NO_KEY		0x	/** invalid key */
+
+/**
+ * File metadata, part of a dir listing
+ */
+struct fw_cfg_file {
+	uint32_t size;		/** length in bytes */
+	uint16_t select;	/** key */
+	uint16_t reserved;
+	char name[56];		/** 

Re: [Qemu-devel] [PATCH] vnc_refresh: calling vnc_update_client might free vs

2010-01-27 Thread Gerd Hoffmann

On 01/27/10 01:07, Anthony Liguori wrote:

On 01/25/2010 06:54 AM, Stefano Stabellini wrote:

Hi all,
this patch fixes another bug in vnc_refresh: calling vnc_update_client
might cause vs to be free()ed, in this case we cannot access vs-next
right after to examine the next item on the list.

Signed-off-by: Stefano Stabellinistefano.stabell...@eu.citrix.com


Applied. Thanks.


IMHO this should go to stable too.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 4/6] vnc.c: warn about ignored option

2010-01-27 Thread Gerd Hoffmann

On 01/27/10 03:10, Anthony Liguori wrote:

On 01/26/2010 05:14 PM, Paolo Bonzini wrote:

Signed-off-by: Paolo Bonzinipbonz...@redhat.com
---
vnc.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/vnc.c b/vnc.c
index cc2a26e..9ebee09 100644
--- a/vnc.c
+++ b/vnc.c
@@ -2563,6 +2563,7 @@ int vnc_display_open(DisplayState *ds, const
char *display)
reverse = 1;
} else if (strncmp(options, to=, 3) == 0) {
to_port = atoi(options+3) + 5900;
+ fprintf(stderr, qemu: warning: to= option for -vnc ignored\n);


If we're ignoring it, why even have the code? How did clang spot this?


to= isn't ignored.  The to= handling has been moved to qemu-socket.c 
though a while ago.  So clang spotted correctly that to_port variable is 
unused.  The whole 'if (...) {}' is a leftover which can go away now.


cheers,
  Gerd





Re: [Qemu-devel] [RFC] gPXE fw_cfg file interface support

2010-01-27 Thread Gerd Hoffmann

gPXE  imgfetch fw_cfg:genroms/static.gpxe


Neat idea.  On the qemu side we better shouldn't abuse the -option-rom 
switch though as seabios will try to load these files as option roms.



Note that this patch only adds the fw_cfg file interface mechanism, it does not
automatically probe for a special file when gPXE starts.  You will
need to manually
chain fw_cfg:genroms/file.


That should be changed too IMHO.  qemu needs some kind of new switch, so 
you can place the firmware file into some other virtual directory where 
gpxe could look by default, i.e. something like fw_cfg:gpxe/default. 
Then you can easily have qemu guests netboot from somewhere without any 
local pxe/tftp setup, like this:


  qemu -fw-file gpxe/default=bko.gpxe

with bko.gpxe being:

  #!gpxe
  dhcp net0
  set 209:string pxelinux.cfg/default
  set 210:string http://boot.kernel.org/bko/
  chain http://boot.kernel.org/bko/pxelinux.0

cheers,
  Gerd





[Qemu-devel] Re: [FOR 0.12 RESEND PATCH] fdc: fix drive property handling.

2010-01-27 Thread Gerd Hoffmann

On 01/06/10 15:23, Gerd Hoffmann wrote:

Fix the floppy controller init wrappers to set the drive properties
only in case the DriveInfo pointers passed in are non NULL.  This allows
to set the properties using -global.

Signed-off-by: Gerd Hoffmannkra...@redhat.com


Ping.  This patch seems to keep missing the boat ...

cheers,
  Gerd





[Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

2010-01-27 Thread Paolo Bonzini

On 01/27/2010 03:10 AM, Anthony Liguori wrote:

What did clang complain about?  It's not obvious to me.


It doesn't see that audio_bug returns cond, and gives quite a few false 
positive in its callers.


Paolo





[Qemu-devel] [PATCH 1/3] Check for sdl-config before calling it

2010-01-27 Thread Loïc Minier
Check whether sdl-config is available before calling it, otherwise
./configure triggers a warning:
./configure: 957: sdl-config: not found

If neither the .pc file not sdl-config are present, disable SDL support.

Signed-off-by: Loïc Minier l...@dooz.org
---
 configure |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 1f6de41..27ab724 100755
--- a/configure
+++ b/configure
@@ -997,9 +997,14 @@ fi
 if $pkgconfig sdl --modversion /dev/null 21; then
   sdlconfig=$pkgconfig sdl
   _sdlversion=`$sdlconfig --modversion 2/dev/null | sed 's/[^0-9]//g'`
-else
+elif which sdl-config /dev/null 21; then
   sdlconfig='sdl-config'
   _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
+else
+  if test $sdl = yes ; then
+feature_not_found sdl
+  fi
+  sdl=no
 fi
 
 sdl_too_old=no
-- 
1.6.5





[Qemu-devel] [PATCH 2/3] Add and use has() and path_of() funcs

2010-01-27 Thread Loïc Minier
Add has() and path_of() funcs and use them across configure; has()
will test whether a command or builtin is available; path_of() will
search the PATH for executables and return the full pathname if found.
---
 configure |   52 +++-
 1 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 27ab724..6bdd2b7 100755
--- a/configure
+++ b/configure
@@ -27,6 +27,42 @@ compile_prog() {
   $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags  
/dev/null 2 /dev/null
 }
 
+# check whether a command is available to this shell (may be either an
+# executable or a builtin)
+has() {
+type $1 /dev/null 21
+}
+
+# search for an executable in PATH
+path_of() {
+local_command=$1
+local_ifs=$IFS
+local_dir=
+
+# pathname has a dir component?
+if [ ${local_command#*/} != $local_command ]; then
+if [ -x $local_command ]  [ ! -d $local_command ]; then
+echo $local_command
+return 0
+fi
+fi
+if [ -z $local_command ]; then
+return 1
+fi
+
+IFS=:
+for local_dir in $PATH; do
+if [ -x $local_dir/$local_command ]  [ ! -d 
$local_dir/$local_command ]; then
+echo $local_dir/$local_command
+IFS=${local_ifs:-$(printf ' \t\n')}
+return 0
+fi
+done
+# not found
+IFS=${local_ifs:-$(printf ' \t\n')}
+return 1
+}
+
 # default parameters
 cpu=
 prefix=
@@ -767,7 +803,7 @@ fi
 # Solaris specific configure tool chain decisions
 #
 if test $solaris = yes ; then
-  solinst=`which $install 2 /dev/null | /usr/bin/grep -v no $install in`
+  solinst=`path_of $install`
   if test -z $solinst ; then
 echo Solaris install program not found. Use --install=/usr/ucb/install or
 echo install fileutils from www.blastwave.org using pkg-get -i fileutils
@@ -780,7 +816,7 @@ if test $solaris = yes ; then
 echo using pkg-get -i fileutils, or use --install=/usr/ucb/install
 exit 1
   fi
-  sol_ar=`which ar 2 /dev/null | /usr/bin/grep -v no ar in`
+  sol_ar=`path_of ar`
   if test -z $sol_ar ; then
 echo Error: No path includes ar
 if test -f /usr/ccs/bin/ar ; then
@@ -973,7 +1009,7 @@ fi
 # pkgconfig probe
 
 pkgconfig=${cross_prefix}pkg-config
-if ! test -x $(which $pkgconfig 2/dev/null); then
+if ! has $pkgconfig; then
   # likely not cross compiling, or hope for the best
   pkgconfig=pkg-config
 fi
@@ -981,7 +1017,7 @@ fi
 ##
 # Sparse probe
 if test $sparse != no ; then
-  if test -x $(which cgcc 2/dev/null); then
+  if has cgcc; then
 sparse=yes
   else
 if test $sparse = yes ; then
@@ -997,7 +1033,7 @@ fi
 if $pkgconfig sdl --modversion /dev/null 21; then
   sdlconfig=$pkgconfig sdl
   _sdlversion=`$sdlconfig --modversion 2/dev/null | sed 's/[^0-9]//g'`
-elif which sdl-config /dev/null 21; then
+elif has sdl-config; then
   sdlconfig='sdl-config'
   _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
 else
@@ -1428,8 +1464,7 @@ EOF
 fi
   else
 if test $kvm = yes ; then
-  if [ -x `which awk 2/dev/null` ]  \
- [ -x `which grep 2/dev/null` ]; then
+  if has awk  has grep; then
 kvmerr=`LANG=C $cc $QEMU_CFLAGS -o $TMPE $kvm_cflags $TMPC 21 \
| grep error:  \
| awk -F error:  '{if (NR1) printf(, ); printf(%s,$2);}'`
@@ -1698,8 +1733,7 @@ fi
 
 # Check if tools are available to build documentation.
 if test $docs != no ; then
-  if test -x `which texi2html 2/dev/null` -a \
-  -x `which pod2man 2/dev/null` ; then
+  if has texi2html  has pod2man; then
 docs=yes
   else
 if test $docs = yes ; then
-- 
1.6.5





[Qemu-devel] [PATCH 3/3] Solaris: test for presence of commands with has()

2010-01-27 Thread Loïc Minier
---
 configure |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 6bdd2b7..1d0915a 100755
--- a/configure
+++ b/configure
@@ -803,21 +803,19 @@ fi
 # Solaris specific configure tool chain decisions
 #
 if test $solaris = yes ; then
-  solinst=`path_of $install`
-  if test -z $solinst ; then
+  if ! has $install; then
 echo Solaris install program not found. Use --install=/usr/ucb/install or
 echo install fileutils from www.blastwave.org using pkg-get -i fileutils
 echo to get ginstall which is used by default (which lives in 
/opt/csw/bin)
 exit 1
   fi
-  if test $solinst = /usr/sbin/install ; then
+  if `path_of $install` = /usr/sbin/install ; then
 echo Error: Solaris /usr/sbin/install is not an appropriate install 
program.
 echo try ginstall from the GNU fileutils available from www.blastwave.org
 echo using pkg-get -i fileutils, or use --install=/usr/ucb/install
 exit 1
   fi
-  sol_ar=`path_of ar`
-  if test -z $sol_ar ; then
+  if ! has ar; then
 echo Error: No path includes ar
 if test -f /usr/ccs/bin/ar ; then
   echo Add /usr/ccs/bin to your path and rerun configure
-- 
1.6.5





[Qemu-devel] [PATCH 3/3] virtio-blk: Fix error cases which ignored rerror/werror

2010-01-27 Thread Kevin Wolf
If an I/O request fails right away instead of getting an error only in the
callback, we still need to consider rerror/werror.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/virtio-blk.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5a413b9..037a79c 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -269,7 +269,7 @@ static void do_multiwrite(BlockDriverState *bs, 
BlockRequest *blkreq,
 if (ret != 0) {
 for (i = 0; i  num_writes; i++) {
 if (blkreq[i].error) {
-virtio_blk_req_complete(blkreq[i].opaque, VIRTIO_BLK_S_IOERR);
+virtio_blk_rw_complete(blkreq[i].opaque, -EIO);
 }
 }
 }
@@ -313,7 +313,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
 acb = bdrv_aio_readv(req-dev-bs, req-out-sector, req-qiov,
  req-qiov.size / 512, virtio_blk_rw_complete, req);
 if (!acb) {
-virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
+virtio_blk_rw_complete(req, -EIO);
 }
 }
 
-- 
1.6.5.2





[Qemu-devel] [PATCH 2/3] virtio-blk: Fix restart after read error

2010-01-27 Thread Kevin Wolf
Current code assumes that only write requests are ever going to be restarted.
This is wrong since rerror=stop exists. Instead of directly starting writes,
use the same request processing as used for new requests.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/virtio-blk.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 82f96e5..5a413b9 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -384,6 +384,10 @@ static void virtio_blk_dma_restart_bh(void *opaque)
 {
 VirtIOBlock *s = opaque;
 VirtIOBlockReq *req = s-rq;
+MultiReqBuffer mrb = {
+.num_writes = 0,
+.old_bs = NULL,
+};
 
 qemu_bh_delete(s-bh);
 s-bh = NULL;
@@ -391,10 +395,13 @@ static void virtio_blk_dma_restart_bh(void *opaque)
 s-rq = NULL;
 
 while (req) {
-bdrv_aio_writev(req-dev-bs, req-out-sector, req-qiov,
-req-qiov.size / 512, virtio_blk_rw_complete, req);
+virtio_blk_handle_request(req, mrb);
 req = req-next;
 }
+
+if (mrb.num_writes  0) {
+do_multiwrite(mrb.old_bs, mrb.blkreq, mrb.num_writes);
+}
 }
 
 static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason)
-- 
1.6.5.2





[Qemu-devel] [PATCH 0/3] virtio-blk: rerror/werror fixes (including corruption fix)

2010-01-27 Thread Kevin Wolf
This fixes two bugs in the handling of rerror/werror in virtio-blk. First is a
fix for read requests morphing into write requests after the VM was stopped by
a read error. Second is to consider rerror/werror in places where virtio-blk
used to directly report errors back.

This series should be applied to stable as well.

Kevin Wolf (3):
  virtio_blk: Factor virtio_blk_handle_request out
  virtio-blk: Fix restart after read error
  virtio-blk: Fix error cases which ignored rerror/werror

 hw/virtio-blk.c |   93 +-
 1 files changed, 57 insertions(+), 36 deletions(-)





[Qemu-devel] [PATCH 1/3] virtio_blk: Factor virtio_blk_handle_request out

2010-01-27 Thread Kevin Wolf
We need a function that handles a single request. Create one by splitting out
code from virtio_blk_handle_output.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/virtio-blk.c |   78 --
 1 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 865352a..82f96e5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -317,46 +317,60 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
 }
 }
 
+typedef struct MultiReqBuffer {
+BlockRequestblkreq[32];
+int num_writes;
+BlockDriverState*old_bs;
+} MultiReqBuffer;
+
+static void virtio_blk_handle_request(VirtIOBlockReq *req,
+MultiReqBuffer *mrb)
+{
+if (req-elem.out_num  1 || req-elem.in_num  1) {
+fprintf(stderr, virtio-blk missing headers\n);
+exit(1);
+}
+
+if (req-elem.out_sg[0].iov_len  sizeof(*req-out) ||
+req-elem.in_sg[req-elem.in_num - 1].iov_len  sizeof(*req-in)) {
+fprintf(stderr, virtio-blk header not in correct element\n);
+exit(1);
+}
+
+req-out = (void *)req-elem.out_sg[0].iov_base;
+req-in = (void *)req-elem.in_sg[req-elem.in_num - 1].iov_base;
+
+if (req-out-type  VIRTIO_BLK_T_FLUSH) {
+virtio_blk_handle_flush(req);
+} else if (req-out-type  VIRTIO_BLK_T_SCSI_CMD) {
+virtio_blk_handle_scsi(req);
+} else if (req-out-type  VIRTIO_BLK_T_OUT) {
+qemu_iovec_init_external(req-qiov, req-elem.out_sg[1],
+ req-elem.out_num - 1);
+virtio_blk_handle_write(mrb-blkreq, mrb-num_writes,
+req, mrb-old_bs);
+} else {
+qemu_iovec_init_external(req-qiov, req-elem.in_sg[0],
+ req-elem.in_num - 1);
+virtio_blk_handle_read(req);
+}
+}
+
 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
 VirtIOBlock *s = to_virtio_blk(vdev);
 VirtIOBlockReq *req;
-BlockRequest blkreq[32];
-int num_writes = 0;
-BlockDriverState *old_bs = NULL;
+MultiReqBuffer mrb = {
+.num_writes = 0,
+.old_bs = NULL,
+};
 
 while ((req = virtio_blk_get_request(s))) {
-if (req-elem.out_num  1 || req-elem.in_num  1) {
-fprintf(stderr, virtio-blk missing headers\n);
-exit(1);
-}
-
-if (req-elem.out_sg[0].iov_len  sizeof(*req-out) ||
-req-elem.in_sg[req-elem.in_num - 1].iov_len  sizeof(*req-in)) {
-fprintf(stderr, virtio-blk header not in correct element\n);
-exit(1);
-}
-
-req-out = (void *)req-elem.out_sg[0].iov_base;
-req-in = (void *)req-elem.in_sg[req-elem.in_num - 1].iov_base;
-
-if (req-out-type  VIRTIO_BLK_T_FLUSH) {
-virtio_blk_handle_flush(req);
-} else if (req-out-type  VIRTIO_BLK_T_SCSI_CMD) {
-virtio_blk_handle_scsi(req);
-} else if (req-out-type  VIRTIO_BLK_T_OUT) {
-qemu_iovec_init_external(req-qiov, req-elem.out_sg[1],
- req-elem.out_num - 1);
-virtio_blk_handle_write(blkreq, num_writes, req, old_bs);
-} else {
-qemu_iovec_init_external(req-qiov, req-elem.in_sg[0],
- req-elem.in_num - 1);
-virtio_blk_handle_read(req);
-}
+virtio_blk_handle_request(req, mrb);
 }
 
-if (num_writes  0) {
-do_multiwrite(old_bs, blkreq, num_writes);
+if (mrb.num_writes  0) {
+do_multiwrite(mrb.old_bs, mrb.blkreq, mrb.num_writes);
 }
 
 /*
-- 
1.6.5.2





Re: [Qemu-devel] [PATCH] vnc_refresh: calling vnc_update_client might free vs

2010-01-27 Thread Stefano Stabellini
On Wed, 27 Jan 2010, Gerd Hoffmann wrote:
 On 01/27/10 01:07, Anthony Liguori wrote:
  On 01/25/2010 06:54 AM, Stefano Stabellini wrote:
  Hi all,
  this patch fixes another bug in vnc_refresh: calling vnc_update_client
  might cause vs to be free()ed, in this case we cannot access vs-next
  right after to examine the next item on the list.
 
  Signed-off-by: Stefano Stabellinistefano.stabell...@eu.citrix.com
 
  Applied. Thanks.
 
 IMHO this should go to stable too.
 

Yes, good idea.




Re: [Qemu-devel] Re: Stop using which in ./configure

2010-01-27 Thread Loïc Minier
On Tue, Jan 26, 2010, Blue Swirl wrote:
 The patches didn't apply. Also please send only one patch per message,
 git am can't handle multiple patches.

 They applied fine here, perhaps you didn't apply the sdl-config patch
 first?  I rebased them and resent them.

-- 
Loïc Minier




Re: [Qemu-devel] [PATCH 1/3] Check for sdl-config before calling it

2010-01-27 Thread Ben Taylor
On Wed, Jan 27, 2010 at 7:10 AM, Loïc Minier l...@dooz.org wrote:
 Check whether sdl-config is available before calling it, otherwise
 ./configure triggers a warning:
    ./configure: 957: sdl-config: not found

 If neither the .pc file not sdl-config are present, disable SDL support.

 Signed-off-by: Loïc Minier l...@dooz.org
 ---
  configure |    7 ++-
  1 files changed, 6 insertions(+), 1 deletions(-)

 diff --git a/configure b/configure
 index 1f6de41..27ab724 100755
 --- a/configure
 +++ b/configure
 @@ -997,9 +997,14 @@ fi
  if $pkgconfig sdl --modversion /dev/null 21; then
   sdlconfig=$pkgconfig sdl
   _sdlversion=`$sdlconfig --modversion 2/dev/null | sed 's/[^0-9]//g'`
 -else
 +elif which sdl-config /dev/null 21; then
   sdlconfig='sdl-config'
   _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
 +else
 +  if test $sdl = yes ; then
 +    feature_not_found sdl
 +  fi
 +  sdl=no
  fi

  sdl_too_old=no


Glad to see someone working on Solaris.  Wondering why you're using
the which command, when you just created a has function in the other
patch segments, and just replaced all the other instances of which.




[Qemu-devel] [PATCH 4/4] target-arm: refactor cp15.c13 register access

2010-01-27 Thread Riku Voipio
From: Riku Voipio riku.voi...@nokia.com

Access the cp15.c13 TLS registers directly with TCG ops instead of with
a slow helper. If the the cp15 read/write was not TLS register access,
fall back to the cp15 helper.

This makes accessing __thread variables in linux-user when apps are compiled
with -mtp=cp15 possible. legal cp15 register to acces from linux-user are
already checked in cp15_user_ok.

While at it, make the cp15.c13 Thread ID registers available only on
ARMv6K and newer.

Signed-off-by: Riku Voipio riku.voi...@nokia.com
---
 target-arm/helper.c|   16 --
 target-arm/translate.c |   55 
 2 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/target-arm/helper.c b/target-arm/helper.c
index b3aec99..27001e8 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -511,7 +511,6 @@ void HELPER(set_cp15)(CPUState *env, uint32_t insn, 
uint32_t val)
 uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)
 {
 cpu_abort(env, cp15 insn %08x\n, insn);
-return 0;
 }
 
 /* These should probably raise undefined insn exceptions.  */
@@ -1491,15 +1490,6 @@ void HELPER(set_cp15)(CPUState *env, uint32_t insn, 
uint32_t val)
   tlb_flush(env, 0);
 env-cp15.c13_context = val;
 break;
-case 2:
-env-cp15.c13_tls1 = val;
-break;
-case 3:
-env-cp15.c13_tls2 = val;
-break;
-case 4:
-env-cp15.c13_tls3 = val;
-break;
 default:
 goto bad_reg;
 }
@@ -1779,12 +1769,6 @@ uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)
 return env-cp15.c13_fcse;
 case 1:
 return env-cp15.c13_context;
-case 2:
-return env-cp15.c13_tls1;
-case 3:
-return env-cp15.c13_tls2;
-case 4:
-return env-cp15.c13_tls3;
 default:
 goto bad_reg;
 }
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 5cf3e06..786c329 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -2455,6 +2455,57 @@ static int cp15_user_ok(uint32_t insn)
 return 0;
 }
 
+static int cp15_tls_load_store(CPUState *env, DisasContext *s, uint32_t insn, 
uint32_t rd)
+{
+TCGv tmp;
+int cpn = (insn  16)  0xf;
+int cpm = insn  0xf;
+int op = ((insn  5)  7) | ((insn  18)  0x38);
+
+if (!arm_feature(env, ARM_FEATURE_V6K))
+return 0;
+
+if (!(cpn == 13  cpm == 0))
+return 0;
+
+if (insn  ARM_CP_RW_BIT) {
+tmp = new_tmp();
+switch (op) {
+case 2:
+tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls1));
+break;
+case 3:
+tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls2));
+break;
+case 4:
+tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls3));
+break;
+default:
+dead_tmp(tmp);
+return 0;
+}
+store_reg(s, rd, tmp);
+
+} else {
+tmp = load_reg(s, rd);
+switch (op) {
+case 2:
+tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls1));
+break;
+case 3:
+tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls2));
+break;
+case 4:
+tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, cp15.c13_tls3));
+break;
+default:
+return 0;
+}
+dead_tmp(tmp);
+}
+return 1;
+}
+
 /* Disassemble system coprocessor (cp15) instruction.  Return nonzero if
instruction is not defined.  */
 static int disas_cp15_insn(CPUState *env, DisasContext *s, uint32_t insn)
@@ -2489,6 +2540,10 @@ static int disas_cp15_insn(CPUState *env, DisasContext 
*s, uint32_t insn)
 return 0;
 }
 rd = (insn  12)  0xf;
+
+if (cp15_tls_load_store(env, s, insn, rd))
+return 0;
+
 tmp2 = tcg_const_i32(insn);
 if (insn  ARM_CP_RW_BIT) {
 tmp = new_tmp();
-- 
1.6.5





[Qemu-devel] [PATCH 0/4] linux-user-for-upstream patches

2010-01-27 Thread Riku Voipio
From: Riku Voipio riku.voi...@nokia.com

Some fixes to avoid hanging, make arm uname match selected
cpu, and fix cp15.c13 register for linux-user tls register
access.

Loïc Minier (1):
  linux-user: adapt uname machine to emulated CPU

Riku Voipio (3):
  fix locking error with current_tb
  linux-user: remove signal handler before calling abort()
  target-arm: refactor cp15.c13 register access

 Makefile.target|2 +-
 exec.c |   13 +++-
 linux-user/cpu-uname.c |   72 
 linux-user/cpu-uname.h |1 +
 linux-user/syscall.c   |3 +-
 target-arm/helper.c|   16 --
 target-arm/translate.c |   55 
 7 files changed, 142 insertions(+), 20 deletions(-)
 create mode 100644 linux-user/cpu-uname.c
 create mode 100644 linux-user/cpu-uname.h





[Qemu-devel] [PATCH 1/4] linux-user: adapt uname machine to emulated CPU

2010-01-27 Thread Riku Voipio
From: Loïc Minier l...@dooz.org

This patch for linux-user adapts the output of the emulated uname()
syscall to match the configured CPU.  Tested with x86, x86-64 and arm
emulation.

Signed-off-by: Riku Voipio riku.voi...@iki.fi
Signed-off-by: Loïc Minier l...@dooz.org
---
 Makefile.target|2 +-
 linux-user/cpu-uname.c |   72 
 linux-user/cpu-uname.h |1 +
 linux-user/syscall.c   |3 +-
 4 files changed, 76 insertions(+), 2 deletions(-)
 create mode 100644 linux-user/cpu-uname.c
 create mode 100644 linux-user/cpu-uname.h

diff --git a/Makefile.target b/Makefile.target
index 5c0ef1f..9dfc4c2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -95,7 +95,7 @@ $(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR
 
 QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user 
-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
 obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
-  elfload.o linuxload.o uaccess.o gdbstub.o
+  elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o
 
 obj-$(TARGET_HAS_BFLT) += flatload.o
 obj-$(TARGET_HAS_ELFLOAD32) += elfload32.o
diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c
new file mode 100644
index 000..23afede
--- /dev/null
+++ b/linux-user/cpu-uname.c
@@ -0,0 +1,72 @@
+/*
+ *  cpu to uname machine name map
+ *
+ *  Copyright (c) 2009 Lo�c Minier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see http://www.gnu.org/licenses/.
+ */
+
+#include stdio.h
+
+#include qemu.h
+//#include qemu-common.h
+#include cpu-uname.h
+
+/* return highest utsname machine name for emulated instruction set
+ *
+ * NB: the default emulated CPU (any) might not match any existing CPU, e.g.
+ * on ARM it has all features turned on, so there is no perfect arch string to
+ * return here */
+const char *cpu_to_uname_machine(void *cpu_env)
+{
+#ifdef TARGET_ARM
+/* utsname machine name on linux arm is CPU arch name + endianness, e.g.
+ * armv7l; to get a list of CPU arch names from the linux source, use:
+ * grep arch_name: -A1 linux/arch/arm/mm/proc-*.S
+ * see arch/arm/kernel/setup.c: setup_processor()
+ *
+ * to test by CPU id, compare cpu_env-cp15.c0_cpuid to ARM_CPUID_*
+ * defines and to test by CPU feature, use arm_feature(cpu_env,
+ * ARM_FEATURE_*) */
+
+/* in theory, endianness is configurable on some ARM CPUs, but this isn't
+ * used in user mode emulation */
+#ifdef TARGET_WORDS_BIGENDIAN
+#define utsname_suffix b
+#else
+#define utsname_suffix l
+#endif
+if (arm_feature(cpu_env, ARM_FEATURE_V7))
+return armv7 utsname_suffix;
+if (arm_feature(cpu_env, ARM_FEATURE_V6))
+return armv6 utsname_suffix;
+/* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its
+ * Jazelle support */
+return armv5te utsname_suffix;
+#elif defined(TARGET_X86_64)
+return x86-64;
+#elif defined(TARGET_I386)
+/* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */
+uint32_t cpuid_version = ((CPUX86State *)cpu_env)-cpuid_version;
+int family = ((cpuid_version  8)  0x0f) + ((cpuid_version  20)  
0xff);
+if (family == 4)
+return i486;
+if (family == 5)
+return i586;
+return i686;
+#else
+/* default is #define-d in each arch/ subdir */
+return UNAME_MACHINE;
+#endif
+}
diff --git a/linux-user/cpu-uname.h b/linux-user/cpu-uname.h
new file mode 100644
index 000..32492de
--- /dev/null
+++ b/linux-user/cpu-uname.h
@@ -0,0 +1 @@
+const char *cpu_to_uname_machine(void *cpu_env);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f2dd39e..9fb493f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -82,6 +82,7 @@
 #include linux/fb.h
 #include linux/vt.h
 #include linux_loop.h
+#include cpu-uname.h
 
 #include qemu.h
 #include qemu-common.h
@@ -5739,7 +5740,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 if (!is_error(ret)) {
 /* Overrite the native machine name with whatever is being
emulated. */
-strcpy (buf-machine, UNAME_MACHINE);
+strcpy (buf-machine, cpu_to_uname_machine(cpu_env));
 /* Allow the user to override the reported release.  */
 if (qemu_uname_release  *qemu_uname_release)
   strcpy (buf-release, 

[Qemu-devel] [PATCH 3/4] linux-user: remove signal handler before calling abort()

2010-01-27 Thread Riku Voipio
From: Riku Voipio riku.voi...@nokia.com

Qemu may hang in host_signal_handler after qemu has done a
seppuku with cpu_abort(). But at this stage we are not really
interested in target process coredump anymore, so unregister
host_signal_handler to die grafefully.

Signed-off-by: Riku Voipio riku.voi...@nokia.com
---
 exec.c |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/exec.c b/exec.c
index 431e104..eeb17d0 100644
--- a/exec.c
+++ b/exec.c
@@ -40,6 +40,7 @@
 #include kvm.h
 #if defined(CONFIG_USER_ONLY)
 #include qemu.h
+#include signal.h
 #endif
 
 //#define DEBUG_TB_INVALIDATE
@@ -1692,6 +1693,14 @@ void cpu_abort(CPUState *env, const char *fmt, ...)
 }
 va_end(ap2);
 va_end(ap);
+#if defined(CONFIG_USER_ONLY)
+{
+struct sigaction act;
+sigfillset(act.sa_mask);
+act.sa_handler = SIG_DFL;
+sigaction(SIGABRT, act, NULL);
+}
+#endif
 abort();
 }
 
-- 
1.6.5





[Qemu-devel] [PATCH 2/4] fix locking error with current_tb

2010-01-27 Thread Riku Voipio
From: Riku Voipio riku.voi...@nokia.com

Signed-off-by: Riku Voipio riku.voi...@nokia.com
---
 exec.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index 76831a1..431e104 100644
--- a/exec.c
+++ b/exec.c
@@ -1537,15 +1537,15 @@ static void cpu_unlink_tb(CPUState *env)
 TranslationBlock *tb;
 static spinlock_t interrupt_lock = SPIN_LOCK_UNLOCKED;
 
+spin_lock(interrupt_lock);
 tb = env-current_tb;
 /* if the cpu is currently executing code, we must unlink it and
all the potentially executing TB */
 if (tb) {
-spin_lock(interrupt_lock);
 env-current_tb = NULL;
 tb_reset_jump_recursive(tb);
-spin_unlock(interrupt_lock);
 }
+spin_unlock(interrupt_lock);
 }
 
 /* mask must never be zero, except for A20 change call */
-- 
1.6.5





[Qemu-devel] Re: [PATCH 1/3] Check for sdl-config before calling it

2010-01-27 Thread Paolo Bonzini



Glad to see someone working on Solaris.  Wondering why you're using
the which command, when you just created a has function in the other
patch segments, and just replaced all the other instances of which.


This is patch 1/3, patch 2/3 creates has and uses it here too.

Paolo





[Qemu-devel] [PATCH 1/6] remove two dead assignments in target-i386/translate.c

2010-01-27 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 target-i386/translate.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 8078112..a597e80 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -4692,8 +4692,6 @@ static target_ulong disas_insn(DisasContext *s, 
target_ulong pc_start)
 ot = dflag + OT_WORD;
 
 modrm = ldub_code(s-pc++);
-mod = (modrm  6)  3;
-rm = (modrm  7) | REX_B(s);
 reg = ((modrm  3)  7) | rex_r;
 
 gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
-- 
1.6.6






[Qemu-devel] [PATCH 0/6] fix a few clang warnings.

2010-01-27 Thread Paolo Bonzini
All of these should be quite uncontroversial.

I'll propose the second patch for 0.12 after a short while.

v1 - v2:
  redid vnc patch (4/6)

Paolo Bonzini (6):
  remove two dead assignments in target-i386/translate.c
  fix undefined shifts by 32
  exec.c: dead assignments
  vnc.c: remove dead code
  usb-linux.c: remove write-only variable
  fix audio_bug related clang false positives

 audio/audio.c   |   44 
 audio/audio_int.h   |3 ++-
 exec.c  |4 
 target-i386/translate.c |2 --
 usb-linux.c |2 --
 vl.c|4 ++--
 vnc.c   |3 ---
 7 files changed, 24 insertions(+), 38 deletions(-)





[Qemu-devel] [PATCH 2/6] fix undefined shifts by 32

2010-01-27 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 vl.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 5e8c775..d9f1ccb 100644
--- a/vl.c
+++ b/vl.c
@@ -2373,9 +2373,9 @@ static void numa_add(const char *optarg)
 fprintf(stderr,
 only 63 CPUs in NUMA mode supported.\n);
 }
-value = (1  (endvalue + 1)) - (1  value);
+value = (2ULL  endvalue) - (1ULL  value);
 } else {
-value = 1  value;
+value = 1ULL  value;
 }
 }
 node_cpumask[nodenr] = value;
-- 
1.6.6






[Qemu-devel] [PATCH 3/6] exec.c: dead assignments

2010-01-27 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 exec.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index 1190591..64109a7 100644
--- a/exec.c
+++ b/exec.c
@@ -2489,17 +2489,13 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
 ram_addr_t qemu_ram_addr_from_host(void *ptr)
 {
 RAMBlock *prev;
-RAMBlock **prevp;
 RAMBlock *block;
 uint8_t *host = ptr;
 
 prev = NULL;
-prevp = ram_blocks;
 block = ram_blocks;
 while (block  (block-host  host
  || block-host + block-length = host)) {
-if (prev)
-  prevp = prev-next;
 prev = block;
 block = block-next;
 }
-- 
1.6.6






[Qemu-devel] [PATCH 4/6] vnc.c: remove dead code

2010-01-27 Thread Paolo Bonzini
to= has always been handled by qemu-sockets.c's inet_listen, not by vnc.c.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 vnc.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/vnc.c b/vnc.c
index cc2a26e..69d6624 100644
--- a/vnc.c
+++ b/vnc.c
@@ -2535,7 +2535,6 @@ int vnc_display_open(DisplayState *ds, const char 
*display)
 const char *options;
 int password = 0;
 int reverse = 0;
-int to_port = 0;
 #ifdef CONFIG_VNC_TLS
 int tls = 0, x509 = 0;
 #endif
@@ -2561,8 +2560,6 @@ int vnc_display_open(DisplayState *ds, const char 
*display)
 password = 1; /* Require password auth */
 } else if (strncmp(options, reverse, 7) == 0) {
 reverse = 1;
-} else if (strncmp(options, to=, 3) == 0) {
-to_port = atoi(options+3) + 5900;
 #ifdef CONFIG_VNC_SASL
 } else if (strncmp(options, sasl, 4) == 0) {
 sasl = 1; /* Require SASL auth */
-- 
1.6.6






[Qemu-devel] [PATCH 5/6] usb-linux.c: remove write-only variable

2010-01-27 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 usb-linux.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 1aaa595..ba8facf 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1007,11 +1007,9 @@ USBDevice *usb_host_device_open(const char *devname)
 {
 struct USBAutoFilter filter;
 USBDevice *dev;
-USBHostDevice *s;
 char *p;
 
 dev = usb_create(NULL /* FIXME */, usb-host);
-s = DO_UPCAST(USBHostDevice, dev, dev);
 
 if (strstr(devname, auto:)) {
 if (parse_filter(devname, filter)  0)
-- 
1.6.6






[Qemu-devel] [PATCH 6/6] fix audio_bug related clang false positives

2010-01-27 Thread Paolo Bonzini
By making the abort condition visible in the caller, this fixes
several false positives in the audio code.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 audio/audio.c |   44 
 audio/audio_int.h |3 ++-
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 2a20e5b..7fce46c 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -118,42 +118,38 @@ struct mixeng_volume nominal_volume = {
 static void audio_print_options (const char *prefix,
  struct audio_option *opt);
 
-int audio_bug (const char *funcname, int cond)
+void audio_bug_found (const char *funcname)
 {
-if (cond) {
-static int shown;
-
-AUD_log (NULL, A bug was just triggered in %s\n, funcname);
-if (!shown) {
-struct audio_driver *d;
-
-shown = 1;
-AUD_log (NULL, Save all your work and restart without audio\n);
-AUD_log (NULL, Please send bug report to av1...@comtv.ru\n);
-AUD_log (NULL, I am sorry\n);
-d = glob_audio_state.drv;
-if (d) {
-audio_print_options (d-name, d-options);
-}
+static int shown;
+
+AUD_log (NULL, A bug was just triggered in %s\n, funcname);
+if (!shown) {
+struct audio_driver *d;
+
+shown = 1;
+AUD_log (NULL, Save all your work and restart without audio\n);
+AUD_log (NULL, Please send bug report to av1...@comtv.ru\n);
+AUD_log (NULL, I am sorry\n);
+d = glob_audio_state.drv;
+if (d) {
+audio_print_options (d-name, d-options);
 }
-AUD_log (NULL, Context:\n);
+}
+AUD_log (NULL, Context:\n);
 
 #if defined AUDIO_BREAKPOINT_ON_BUG
 #  if defined HOST_I386
 #if defined __GNUC__
-__asm__ (int3);
+__asm__ (int3);
 #elif defined _MSC_VER
-_asm _emit 0xcc;
+_asm _emit 0xcc;
 #else
-abort ();
+abort ();
 #endif
 #  else
-abort ();
+abort ();
 #  endif
 #endif
-}
-
-return cond;
 }
 #endif
 
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 06e313f..4244615 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -223,7 +223,8 @@ int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
 int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
int live, int pending);
 
-int audio_bug (const char *funcname, int cond);
+#define audio_bug(funcname, cond) ((cond) ? audio_bug_found (funcname), 1 : 0)
+void audio_bug_found (const char *funcname);
 void *audio_calloc (const char *funcname, int nmemb, size_t size);
 
 void audio_run (const char *msg);
-- 
1.6.6





Re: [Qemu-devel] [PATCH 4/4] target-arm: refactor cp15.c13 register access

2010-01-27 Thread Laurent Desnogues
On Wed, Jan 27, 2010 at 1:49 PM, Riku Voipio riku.voi...@iki.fi wrote:
 From: Riku Voipio riku.voi...@nokia.com

 Access the cp15.c13 TLS registers directly with TCG ops instead of with
 a slow helper. If the the cp15 read/write was not TLS register access,
 fall back to the cp15 helper.

 This makes accessing __thread variables in linux-user when apps are compiled
 with -mtp=cp15 possible. legal cp15 register to acces from linux-user are
 already checked in cp15_user_ok.

 While at it, make the cp15.c13 Thread ID registers available only on
 ARMv6K and newer.

 Signed-off-by: Riku Voipio riku.voi...@nokia.com

Acked-by: Laurent Desnogues laurent.desnog...@gmail.com


Laurent

 ---
  target-arm/helper.c    |   16 --
  target-arm/translate.c |   55 
 
  2 files changed, 55 insertions(+), 16 deletions(-)

 diff --git a/target-arm/helper.c b/target-arm/helper.c
 index b3aec99..27001e8 100644
 --- a/target-arm/helper.c
 +++ b/target-arm/helper.c
 @@ -511,7 +511,6 @@ void HELPER(set_cp15)(CPUState *env, uint32_t insn, 
 uint32_t val)
  uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)
  {
     cpu_abort(env, cp15 insn %08x\n, insn);
 -    return 0;
  }

  /* These should probably raise undefined insn exceptions.  */
 @@ -1491,15 +1490,6 @@ void HELPER(set_cp15)(CPUState *env, uint32_t insn, 
 uint32_t val)
               tlb_flush(env, 0);
             env-cp15.c13_context = val;
             break;
 -        case 2:
 -            env-cp15.c13_tls1 = val;
 -            break;
 -        case 3:
 -            env-cp15.c13_tls2 = val;
 -            break;
 -        case 4:
 -            env-cp15.c13_tls3 = val;
 -            break;
         default:
             goto bad_reg;
         }
 @@ -1779,12 +1769,6 @@ uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)
             return env-cp15.c13_fcse;
         case 1:
             return env-cp15.c13_context;
 -        case 2:
 -            return env-cp15.c13_tls1;
 -        case 3:
 -            return env-cp15.c13_tls2;
 -        case 4:
 -            return env-cp15.c13_tls3;
         default:
             goto bad_reg;
         }
 diff --git a/target-arm/translate.c b/target-arm/translate.c
 index 5cf3e06..786c329 100644
 --- a/target-arm/translate.c
 +++ b/target-arm/translate.c
 @@ -2455,6 +2455,57 @@ static int cp15_user_ok(uint32_t insn)
     return 0;
  }

 +static int cp15_tls_load_store(CPUState *env, DisasContext *s, uint32_t 
 insn, uint32_t rd)
 +{
 +    TCGv tmp;
 +    int cpn = (insn  16)  0xf;
 +    int cpm = insn  0xf;
 +    int op = ((insn  5)  7) | ((insn  18)  0x38);
 +
 +    if (!arm_feature(env, ARM_FEATURE_V6K))
 +        return 0;
 +
 +    if (!(cpn == 13  cpm == 0))
 +        return 0;
 +
 +    if (insn  ARM_CP_RW_BIT) {
 +        tmp = new_tmp();
 +        switch (op) {
 +        case 2:
 +            tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls1));
 +            break;
 +        case 3:
 +            tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls2));
 +            break;
 +        case 4:
 +            tcg_gen_ld_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls3));
 +            break;
 +        default:
 +            dead_tmp(tmp);
 +            return 0;
 +        }
 +        store_reg(s, rd, tmp);
 +
 +    } else {
 +        tmp = load_reg(s, rd);
 +        switch (op) {
 +        case 2:
 +            tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls1));
 +            break;
 +        case 3:
 +            tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls2));
 +            break;
 +        case 4:
 +            tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUARMState, 
 cp15.c13_tls3));
 +            break;
 +        default:
 +            return 0;
 +        }
 +        dead_tmp(tmp);
 +    }
 +    return 1;
 +}
 +
  /* Disassemble system coprocessor (cp15) instruction.  Return nonzero if
    instruction is not defined.  */
  static int disas_cp15_insn(CPUState *env, DisasContext *s, uint32_t insn)
 @@ -2489,6 +2540,10 @@ static int disas_cp15_insn(CPUState *env, DisasContext 
 *s, uint32_t insn)
         return 0;
     }
     rd = (insn  12)  0xf;
 +
 +    if (cp15_tls_load_store(env, s, insn, rd))
 +        return 0;
 +
     tmp2 = tcg_const_i32(insn);
     if (insn  ARM_CP_RW_BIT) {
         tmp = new_tmp();
 --
 1.6.5








Re: [Qemu-devel] [PATCH] vnc_refresh: calling vnc_update_client might free vs

2010-01-27 Thread Anthony Liguori

On 01/27/2010 06:29 AM, Stefano Stabellini wrote:

On Wed, 27 Jan 2010, Gerd Hoffmann wrote:
   

On 01/27/10 01:07, Anthony Liguori wrote:
 

On 01/25/2010 06:54 AM, Stefano Stabellini wrote:
   

Hi all,
this patch fixes another bug in vnc_refresh: calling vnc_update_client
might cause vs to be free()ed, in this case we cannot access vs-next
right after to examine the next item on the list.

Signed-off-by: Stefano Stabellinistefano.stabell...@eu.citrix.com
 

Applied. Thanks.
   

IMHO this should go to stable too.

 

Yes, good idea.
   


Already did.

Regards,

Anthony Liguori




Re: [Qemu-devel] Re: [PATCH qemu-kvm] Add raw(af_packet) network backend to qemu

2010-01-27 Thread Anthony Liguori

On 01/27/2010 12:52 AM, Arnd Bergmann wrote:

On Wednesday 27 January 2010, Anthony Liguori wrote:
   

The raw backend can be attached to a physical device
   

This is equivalent to bridging with tun/tap except that it has the
unexpected behaviour of unreliable host/guest networking (which is not
universally consistent across platforms either).  This is not a mode we
want to encourage users to use.
 

It's not the most common scenario, but I've seen systems (I remember
one on s/390 with z/VM) where you really want to isolate the guest
network as much as possible from the host network. Besides PCI
passthrough, giving the host device to a guest using a raw socket
is the next best approximation of that.
   


But if you care about isolation, it's the worst possible thing to do.  
If a guest breaks into qemu, it's one bind() away from accessing any 
other guests network.


Using a bridge with a single interface on it is much better from an 
isolation perspective.



   In general, what I would like to see for
this is something more user friendly that dealt specifically with this
use-case.  Although honestly, given the recent security concerns around
raw sockets, I'm very concerned about supporting raw sockets in qemu at all.

Essentially, you get worse security doing vhost-net + raw + VF then with
PCI passthrough + VF because at least in the later case you can run qemu
without privileges.  CAP_NET_RAW is a very big privilege.
 

It can be contained to a large degree with network namespaces. When you
run qemu in its own namespace and add the VF to that, CAP_NET_RAW
should ideally have no effect on other parts of the system (except
bugs in the namespace implementation).
   


That's a pretty big hammer to hit this problem with.  QEMU should not 
require CAP_NET_RAW and so far has been able to avoid it quite 
successfully.  So far, I haven't heard a compelling reason that to use 
raw other than bridging can be complicated to setup.


If we had the equivalent of a raw socket that could be bound to a socket 
and then locked such that it could be safely handed to a 
non-privileged process, then it would be a different story.


Regards,

Anthony Liguori




[Qemu-devel] [RFC][PATCH] KVM: Introduce modification context for cpu_synchronize_state

2010-01-27 Thread Jan Kiszka
This patch originates in the mp_state writeback issue: During runtime
and even on reset, we must not write the previously saved VCPU state
back into the kernel in an uncontrolled fashion. E.g mp_state should
only written on reset or on VCPU setup. Certain clocks (e.g. the TSC)
may only be written on setup or after vmload.

By introducing additional information about the context of the planned
vcpu state manipulation, we can simply skip sensitive states like
mp_state when updating the in-kernel state. The planned modifications
are defined when calling cpu_synchronize_state. They accumulate, ie.
once a full writeback was requested, it will stick until it was
performed.

This patch already fixes existing writeback issues in upstream KVM by
only selectively writing MSR_IA32_TSC, MSR_KVM_SYSTEM_TIME,
MSR_KVM_WALL_CLOCK, the mp_state and the vcpu_events.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

This patch is intentionally written against uq/master. As upstream is
less convoluted (yet :) ), it may help understanding the basic idea. An
add-on patch for qemu-kvm that both cleans up the current code and also
moves kvm_get/set_lapic into kvm_arch_get/put_registers (hmm, maybe also
renaming that services...) will follow soon if no one sees fundamental
problems of this approach.

 exec.c|4 ++--
 gdbstub.c |   10 +-
 hw/apic.c |2 +-
 hw/ppc_newworld.c |2 +-
 hw/ppc_oldworld.c |2 +-
 hw/s390-virtio.c  |2 +-
 kvm-all.c |   31 +++
 kvm.h |   13 +
 monitor.c |4 ++--
 target-i386/helper.c  |2 +-
 target-i386/kvm.c |   31 +++
 target-i386/machine.c |4 ++--
 target-ppc/kvm.c  |2 +-
 target-ppc/machine.c  |4 ++--
 target-s390x/kvm.c|   17 -
 15 files changed, 78 insertions(+), 52 deletions(-)

diff --git a/exec.c b/exec.c
index 6875370..5a83922 100644
--- a/exec.c
+++ b/exec.c
@@ -521,14 +521,14 @@ static void cpu_common_pre_save(void *opaque)
 {
 CPUState *env = opaque;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(env, CPU_MODIFY_NONE);
 }
 
 static int cpu_common_pre_load(void *opaque)
 {
 CPUState *env = opaque;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(env, CPU_MODIFY_INIT);
 return 0;
 }
 
diff --git a/gdbstub.c b/gdbstub.c
index 80477be..8caae15 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1653,7 +1653,7 @@ static void gdb_breakpoint_remove_all(void)
 static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
 {
 #if defined(TARGET_I386)
-cpu_synchronize_state(s-c_cpu);
+cpu_synchronize_state(s-c_cpu, CPU_MODIFY_RUNTIME);
 s-c_cpu-eip = pc;
 #elif defined (TARGET_PPC)
 s-c_cpu-nip = pc;
@@ -1678,7 +1678,7 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
 #elif defined (TARGET_ALPHA)
 s-c_cpu-pc = pc;
 #elif defined (TARGET_S390X)
-cpu_synchronize_state(s-c_cpu);
+cpu_synchronize_state(s-c_cpu, CPU_MODIFY_RUNTIME);
 s-c_cpu-psw.addr = pc;
 #endif
 }
@@ -1848,7 +1848,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 }
 break;
 case 'g':
-cpu_synchronize_state(s-g_cpu);
+cpu_synchronize_state(s-g_cpu, CPU_MODIFY_NONE);
 len = 0;
 for (addr = 0; addr  num_g_regs; addr++) {
 reg_size = gdb_read_register(s-g_cpu, mem_buf + len, addr);
@@ -1858,7 +1858,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 put_packet(s, buf);
 break;
 case 'G':
-cpu_synchronize_state(s-g_cpu);
+cpu_synchronize_state(s-g_cpu, CPU_MODIFY_RUNTIME);
 registers = mem_buf;
 len = strlen(p) / 2;
 hextomem((uint8_t *)registers, p, len);
@@ -2022,7 +2022,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 thread = strtoull(p+16, (char **)p, 16);
 env = find_cpu(thread);
 if (env != NULL) {
-cpu_synchronize_state(env);
+cpu_synchronize_state(env, CPU_MODIFY_NONE);
 len = snprintf((char *)mem_buf, sizeof(mem_buf),
CPU#%d [%s], env-cpu_index,
env-halted ? halted  : running);
diff --git a/hw/apic.c b/hw/apic.c
index 87e7dc0..3562ad5 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -938,7 +938,7 @@ static void apic_reset(void *opaque)
 APICState *s = opaque;
 int bsp;
 
-cpu_synchronize_state(s-cpu_env);
+cpu_synchronize_state(s-cpu_env, CPU_MODIFY_RESET);
 
 bsp = cpu_is_bsp(s-cpu_env);
 s-apicbase = 0xfee0 |
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index a4c714a..6e33c47 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -140,7 +140,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
 }
 
 /* Make sure all register sets take effect */
-

[Qemu-devel] [PATCH v4 2/8] QDict: New qdict_get_double()

2010-01-27 Thread Markus Armbruster
Helper function just like qdict_get_int(), just for QFloat/double.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 Makefile |2 +-
 qdict.c  |   24 
 qdict.h  |1 +
 3 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 60d5c66..3f02c66 100644
--- a/Makefile
+++ b/Makefile
@@ -147,7 +147,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
 
 check-qint: check-qint.o qint.o qemu-malloc.o
 check-qstring: check-qstring.o qstring.o qemu-malloc.o
-check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o 
qlist.o
+check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o 
qemu-malloc.o qlist.o
 check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o
 check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o
 check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o
diff --git a/qdict.c b/qdict.c
index ba8eef0..32119cf 100644
--- a/qdict.c
+++ b/qdict.c
@@ -11,6 +11,7 @@
  */
 
 #include qint.h
+#include qfloat.h
 #include qdict.h
 #include qbool.h
 #include qstring.h
@@ -175,6 +176,29 @@ static QObject *qdict_get_obj(const QDict *qdict, const 
char *key,
 }
 
 /**
+ * qdict_get_double(): Get an number mapped by 'key'
+ *
+ * This function assumes that 'key' exists and it stores a
+ * QFloat or QInt object.
+ *
+ * Return number mapped by 'key'.
+ */
+double qdict_get_double(const QDict *qdict, const char *key)
+{
+QObject *obj = qdict_get(qdict, key);
+
+assert(obj);
+switch (qobject_type(obj)) {
+case QTYPE_QFLOAT:
+return qfloat_get_double(qobject_to_qfloat(obj));
+case QTYPE_QINT:
+return qint_get_int(qobject_to_qint(obj));
+default:
+assert(0);
+}
+}
+
+/**
  * qdict_get_int(): Get an integer mapped by 'key'
  *
  * This function assumes that 'key' exists and it stores a
diff --git a/qdict.h b/qdict.h
index 5fef1ea..5649ccf 100644
--- a/qdict.h
+++ b/qdict.h
@@ -37,6 +37,7 @@ void qdict_iter(const QDict *qdict,
 qdict_put_obj(qdict, key, QOBJECT(obj))
 
 /* High level helpers */
+double qdict_get_double(const QDict *qdict, const char *key);
 int64_t qdict_get_int(const QDict *qdict, const char *key);
 int qdict_get_bool(const QDict *qdict, const char *key);
 QList *qdict_get_qlist(const QDict *qdict, const char *key);
-- 
1.6.6





[Qemu-devel] [PATCH] virtio-serial-bus: Fix bus initialisation and allow for bus identification

2010-01-27 Thread Amit Shah
This commit enables one to use multiple virtio-serial devices and to
assign ports to arbitrary devices like this:

  -device virtio-serial,id=foo -device virtio-serial,id=bar \
  -device virtserialport,bus=foo.0,name=foo \
  -device virtserialport,bus=bar.0,name=bar

Signed-off-by: Amit Shah amit.s...@redhat.com
---
 hw/virtio-serial-bus.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 403268f..ab456ea 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -445,8 +445,7 @@ static VirtIOSerialBus *virtser_bus_new(DeviceState *dev)
 {
 VirtIOSerialBus *bus;
 
-bus = FROM_QBUS(VirtIOSerialBus, qbus_create(virtser_bus_info, dev,
- virtio-serial-bus));
+bus = FROM_QBUS(VirtIOSerialBus, qbus_create(virtser_bus_info, dev, 
NULL));
 bus-qbus.allow_hotplug = 1;
 
 return bus;
-- 
1.6.2.5





[Qemu-devel] [PATCH] Fix regression in option parsing

2010-01-27 Thread Anthony Liguori
Commit ec229bbe7 broke invocation without a specific -hda.  IOW, qemu foo.img.
The lack of an optind update caused an infinite loop.

Reported-by: Amit Shah amit.s...@redhat.com
Signed-off-by: Anthony Liguori aligu...@us.ibm.com
---
 vl.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/vl.c b/vl.c
index 1cd355c..6f1e1ab 100644
--- a/vl.c
+++ b/vl.c
@@ -4819,6 +4819,7 @@ int main(int argc, char **argv, char **envp)
 while (optind  argc) {
 if (argv[optind][0] != '-') {
 /* disk image */
+optind++;
 continue;
 } else {
 const QEMUOption *popt;
-- 
1.6.5.2





Re: [Qemu-devel] [PATCH] sparc64: correct write extra bits to cwp

2010-01-27 Thread Blue Swirl
Thanks, applied.


On Tue, Jan 26, 2010 at 11:11 PM, Igor V. Kovalenko
igor.v.kovale...@gmail.com wrote:
 From: Igor V. Kovalenko igor.v.kovale...@gmail.com

 - correctly fit to cwp if provided window number is out of range

 Signed-off-by: Igor V. Kovalenko igor.v.kovale...@gmail.com
 ---
  target-sparc/cpu.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
 index 50859c7..842a2f4 100644
 --- a/target-sparc/cpu.h
 +++ b/target-sparc/cpu.h
 @@ -519,7 +519,7 @@ static inline void PUT_PSR(CPUSPARCState *env1, 
 target_ulong val)
  static inline void PUT_CWP64(CPUSPARCState *env1, int cwp)
  {
     if (unlikely(cwp = env1-nwindows || cwp  0))
 -        cwp = 0;
 +        cwp %= env1-nwindows;
     cpu_set_cwp(env1, env1-nwindows - 1 - cwp);
  }
  #endif








Re: [Qemu-devel] Re: Stop using which in ./configure

2010-01-27 Thread Blue Swirl
On Wed, Jan 27, 2010 at 12:41 PM, Loïc Minier l...@dooz.org wrote:
 On Tue, Jan 26, 2010, Blue Swirl wrote:
 The patches didn't apply. Also please send only one patch per message,
 git am can't handle multiple patches.

  They applied fine here, perhaps you didn't apply the sdl-config patch
  first?  I rebased them and resent them.

That must've been it. But I get this on Milax:

config-host.mak is out-of-date, running configure
/bin/ginstall: cannot stat `=': No such file or directory

Configuration and build succeeds though.




[Qemu-devel] Re: sparc solaris guest, hsfs_putpage: dirty HSFS page

2010-01-27 Thread Blue Swirl
On Tue, Jan 26, 2010 at 10:42 PM, Artyom Tarasenko
atar4q...@googlemail.com wrote:
 2010/1/26 Blue Swirl blauwir...@gmail.com:
 On Tue, Jan 26, 2010 at 7:03 PM, Artyom Tarasenko
 atar4q...@googlemail.com wrote:
 2010/1/24 Blue Swirl blauwir...@gmail.com:
 On Sun, Jan 24, 2010 at 2:02 AM, Artyom Tarasenko
 atar4q...@googlemail.com wrote:
 All solaris versions which currently boot (from cd) regularly produce 
 buckets of
 hsfs_putpage: dirty HSFS page messages.

 High Sierra is a pretty old and stable stuff, so it is possible that
 the code is similar to OpenSolaris.
 I looked in debugger, and the function calls hierarchy looks pretty 
 similar.

 Now in the OpenSolaris source code there is a nice comment:
 http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/fs/hsfs/hsfs_vnops.c#1758
 /*
 * Normally pvn_getdirty() should return 0, which
 * impies that it has done the job for us.
 * The shouldn't-happen scenario is when it returns 1.
 * This means that the page has been modified and
 * needs to be put back.
 * Since we can't write on a CD, we fake a failed
 * I/O and force pvn_write_done() to destroy the page.
 */
 if (pvn_getdirty(pp, flags) == 1) {
                cmn_err(CE_NOTE,
                            hsfs_putpage: dirty HSFS page);

 Now the question: does the problem have to do with qemu caches 
 (non-)emulation?
 Can it be that we mark non-dirty pages dirty? Or does qemu always mark
 pages dirty exactly to avoid cache emulation?

 Otherwise it means something else goes astray and Solaris guest really
 modifies the pages it shouldn't.

 Just wonder what to dig first, MMU or IRQ emulation (the two most
 obvious suspects).

 Maybe the stores via MMU bypass ASIs

 why bypass stores? What about the non-bypass ones?

 Because their use should update the PTE dirty bits.

 update !=always set. Where is it implemented? I guess the code is
 shared between multiple architectures.
 Is there a way to trace at what point certain page is getting dirty?

 Since it's not the bypass ASIs it must be something else.

target-sparc/helper.c:193 for the page table dirtiness (this is
probably what Solaris can detect).

There is other kind of dirtiness in exec.c, grep for phys_ram_dirty
uses. But this should not be visible to guest.




Re: [Qemu-devel] [PATCH] sparc64: reimplement tick timers v3

2010-01-27 Thread Blue Swirl
On Tue, Jan 26, 2010 at 11:09 PM, Igor Kovalenko
igor.v.kovale...@gmail.com wrote:
 On Fri, Jan 22, 2010 at 11:32 PM, Blue Swirl blauwir...@gmail.com wrote:
 On Tue, Jan 19, 2010 at 10:25 PM, Igor V. Kovalenko
 igor.v.kovale...@gmail.com wrote:
 From: Igor V. Kovalenko igor.v.kovale...@gmail.com

 sparc64 timer has tick counter which can be set and read,
 and tick compare value used as deadline to fire timer interrupt.
 The timer is not used as periodic timer, instead deadline
 is set each time new timer interrupt is needed.

 v2 - v3:
 - added missing timer debug output macro
 - CPUTimer struct and typedef moved to cpu.h
 - change CPU_SAVE_VERSION to 6, older save formats not supported

 v1 - v2:
 - new conversion helpers cpu_to_timer_ticks and timer_to_cpu_ticks
 - save offset from clock source to implement cpu_tick_set_count
 - renamed struct sun4u_timer to CPUTimer
 - load and save cpu timers

 v0 - v1:
 - coding style

 My debugging of Linux panic has not been very fruitful. Once I got the
 panic triggered while single stepping calibrate_delay() with GDB and
 keeping enter key pressed. Then I missed the fault though.

 One possible problem is that 4dc28134f3d7db0033c6b3c5bc4be9a91adb3e2b
 added interrupt checks to the helpers which means that they can cause
 faults, but translation of the instructions was not changed to take
 this into account. But when I added calls to save_state() in
 translate.c, it didn't change anything.

 The issue is with PUT_CWP64 - linux kernel does read cwp which
 happens to be zero, decrements it and writes the result to cwp.
 Expected value is max window id but we store zero cwp,
 and return path from trap handler does restore wrong window.

 I'll post the fix now, and then try to clean up the rest of timer patch.

Excellent analysis! I await your patch anxiously.




[Qemu-devel] Re: [PATCH 1/3] virtio_blk: Factor virtio_blk_handle_request out

2010-01-27 Thread Christoph Hellwig
On Wed, Jan 27, 2010 at 01:12:34PM +0100, Kevin Wolf wrote:
 We need a function that handles a single request. Create one by splitting out
 code from virtio_blk_handle_output.

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de





[Qemu-devel] Re: [PATCH 2/3] virtio-blk: Fix restart after read error

2010-01-27 Thread Christoph Hellwig
On Wed, Jan 27, 2010 at 01:12:35PM +0100, Kevin Wolf wrote:
 Current code assumes that only write requests are ever going to be restarted.
 This is wrong since rerror=stop exists. Instead of directly starting writes,
 use the same request processing as used for new requests.

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de





[Qemu-devel] Re: [PATCH 3/3] virtio-blk: Fix error cases which ignored rerror/werror

2010-01-27 Thread Christoph Hellwig
On Wed, Jan 27, 2010 at 01:12:36PM +0100, Kevin Wolf wrote:
 If an I/O request fails right away instead of getting an error only in the
 callback, we still need to consider rerror/werror.

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de





[Qemu-devel] Re: [PATCHv2] configure: verify stdio.h

2010-01-27 Thread Stefan Weil
Michael S. Tsirkin schrieb:
 On Tue, Jan 26, 2010 at 10:44:44PM +0100, Stefan Weil wrote:
 Michael S. Tsirkin schrieb:
 Verify that stdio.h supports %lld %zd.
 Some migw variants don't unless requested explicitly (see
 migw - mingw

 I don't know any ming32 variant which supports %lld, %zd.
 There is a new mingw-w64 were people are addressing the
 problem,

 Did you try with -D__USE_MINGW_ANSI_STDIO=1 ?
 This is what the link below mentions.


New information on this issue:

mingw-runtime 3.15 (2008-09-07) added support for
standard format conversion:

http://sourceforge.net/project/shownotes.php?release_id=24832

The release note also says how to select MS or C99/POSIX
format strings.

Debian still does not include that version:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498529

Maybe someone knows how we can help to get the new release
for debian. It's needed for cross compilation (at least for
users who don't want to install it manually).


 but that variant is unsupported by qemu.

 What are the issues?


Good question. I don't know because I did not try it.
It was only a guess that qemu would not work with
mingw-w64 without modifications.





[Qemu-devel] Re: [PATCHv2] configure: verify stdio.h

2010-01-27 Thread Michael S. Tsirkin
On Wed, Jan 27, 2010 at 08:02:26PM +0100, Stefan Weil wrote:
 Michael S. Tsirkin schrieb:
  On Tue, Jan 26, 2010 at 10:44:44PM +0100, Stefan Weil wrote:
  Michael S. Tsirkin schrieb:
  Verify that stdio.h supports %lld %zd.
  Some migw variants don't unless requested explicitly (see
  migw - mingw
 
  I don't know any ming32 variant which supports %lld, %zd.
  There is a new mingw-w64 were people are addressing the
  problem,
 
  Did you try with -D__USE_MINGW_ANSI_STDIO=1 ?
  This is what the link below mentions.
 
 
 New information on this issue:
 
 mingw-runtime 3.15 (2008-09-07) added support for
 standard format conversion:
 
 http://sourceforge.net/project/shownotes.php?release_id=24832
 
 The release note also says how to select MS or C99/POSIX
 format strings.
 
 Debian still does not include that version:
 
 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498529
 
 Maybe someone knows how we can help to get the new release
 for debian. It's needed for cross compilation (at least for
 users who don't want to install it manually).

Heh, configure script runs the program it's built
in a couple of places. This probably does not
work for cross-builds:

if compile_prog   ; then
$TMPE  bigendian=yes
else
echo big/little test failed
fi

likely works by luck for build to intel, because error
is interpreted as little-endian.

 
  but that variant is unsupported by qemu.
 
  What are the issues?
 
 
 Good question. I don't know because I did not try it.
 It was only a guess that qemu would not work with
 mingw-w64 without modifications.




Re: [Qemu-devel] [PATCHv2-repost 1/3] qemu: memory notifiers

2010-01-27 Thread Michael S. Tsirkin
On Tue, Jan 26, 2010 at 05:07:43PM -0600, Anthony Liguori wrote:
 On 01/25/2010 08:29 AM, Michael S. Tsirkin wrote:
 This adds notifiers for phys memory changes: a set of callbacks that
 vhost can register and update kernel accordingly.  Down the road, kvm
 code can be switched to use these as well, instead of calling kvm code
 directly from exec.c as is done now.

 Signed-off-by: Michael S. Tsirkinm...@redhat.com
 Acked-by: Avi Kivitya...@redhat.com


 This breaks the linux-user build (exec.o: cpu_notify_set_memory defined  
 but not used).

 Regards,

 Anthony Liguori

Ugh, this will fix it. Want me to repost the series?

diff --git a/exec.c b/exec.c
index 63caca0..2e7434e 100644
--- a/exec.c
+++ b/exec.c
@@ -1623,6 +1623,7 @@ const CPULogItem cpu_log_items[] = {
 { 0, NULL, NULL },
 };
 
+#ifndef CONFIG_USER_ONLY
 static QLIST_HEAD(memory_client_list, CPUPhysMemoryClient) memory_client_list
 = QLIST_HEAD_INITIALIZER(memory_client_list);
 
@@ -1715,6 +1716,7 @@ void 
cpu_unregister_phys_memory_client(CPUPhysMemoryClient *client)
 {
 QLIST_REMOVE(client, list);
 }
+#endif
 
 static int cmp1(const char *s1, int n, const char *s2)
 {




Re: [Qemu-devel] [PATCHv2-repost 1/3] qemu: memory notifiers

2010-01-27 Thread Anthony Liguori

On 01/27/2010 01:47 PM, Michael S. Tsirkin wrote:

Ugh, this will fix it. Want me to repost the series?


Please do.

Regards,

Anthony Liguori


diff --git a/exec.c b/exec.c
index 63caca0..2e7434e 100644
--- a/exec.c
+++ b/exec.c
@@ -1623,6 +1623,7 @@ const CPULogItem cpu_log_items[] = {
  { 0, NULL, NULL },
  };

+#ifndef CONFIG_USER_ONLY
  static QLIST_HEAD(memory_client_list, CPUPhysMemoryClient) memory_client_list
  = QLIST_HEAD_INITIALIZER(memory_client_list);

@@ -1715,6 +1716,7 @@ void 
cpu_unregister_phys_memory_client(CPUPhysMemoryClient *client)
  {
  QLIST_REMOVE(client, list);
  }
+#endif

  static int cmp1(const char *s1, int n, const char *s2)
  {
   






[Qemu-devel] [PATCH] Monitor: Fix command execution regression

2010-01-27 Thread Luiz Capitulino

Function is_async_return() added by commit 940cc30d0d4 assumes
that 'data', which is returned by handlers, is always a QDict.

This is not true, as QLists can also be returned, in this case
we'll get a segfault.

Fix that by checking if 'data' is a QDict.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
---
 monitor.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/monitor.c b/monitor.c
index fbae5ce..fb7c572 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3700,7 +3700,11 @@ static void monitor_print_error(Monitor *mon)
 
 static int is_async_return(const QObject *data)
 {
-return data  qdict_haskey(qobject_to_qdict(data), __mon_async);
+if (data  qobject_type(data) == QTYPE_QDICT) {
+return qdict_haskey(qobject_to_qdict(data), __mon_async);
+}
+
+return 0;
 }
 
 static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd,
-- 
1.6.6





[Qemu-devel] [PATCHv3 0/3] qemu: memory notifiers

2010-01-27 Thread Michael S. Tsirkin
This patch against qemu upstream adds notifiers hook which lets backends
get notified on memory changes, and converts kvm to use it.  It survived
light testing.


Michael S. Tsirkin (3):
  qemu: memory notifiers
  kvm: move kvm_set_phys_mem around
  kvm: move kvm to use memory notifiers

 cpu-common.h |   19 
 exec.c   |  110 +++--
 kvm-all.c|  310 +++--
 kvm.h|8 --
 4 files changed, 289 insertions(+), 158 deletions(-)




[Qemu-devel] [PATCHv3 1/3] qemu: memory notifiers

2010-01-27 Thread Michael S. Tsirkin
This adds notifiers for phys memory changes: a set of callbacks that
vhost can register and update kernel accordingly.  Down the road, kvm
code can be switched to use these as well, instead of calling kvm code
directly from exec.c as is done now.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 cpu-common.h |   19 ++
 exec.c   |  113 --
 2 files changed, 129 insertions(+), 3 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index 6302372..0ec9b72 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -8,6 +8,7 @@
 #endif
 
 #include bswap.h
+#include qemu-queue.h
 
 /* address in the RAM (different from a physical address) */
 typedef unsigned long ram_addr_t;
@@ -61,6 +62,24 @@ void cpu_physical_memory_unmap(void *buffer, 
target_phys_addr_t len,
 void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque));
 void cpu_unregister_map_client(void *cookie);
 
+struct CPUPhysMemoryClient;
+typedef struct CPUPhysMemoryClient CPUPhysMemoryClient;
+struct CPUPhysMemoryClient {
+void (*set_memory)(struct CPUPhysMemoryClient *client,
+   target_phys_addr_t start_addr,
+   ram_addr_t size,
+   ram_addr_t phys_offset);
+int (*sync_dirty_bitmap)(struct CPUPhysMemoryClient *client,
+ target_phys_addr_t start_addr,
+ target_phys_addr_t end_addr);
+int (*migration_log)(struct CPUPhysMemoryClient *client,
+ int enable);
+QLIST_ENTRY(CPUPhysMemoryClient) list;
+};
+
+void cpu_register_phys_memory_client(CPUPhysMemoryClient *);
+void cpu_unregister_phys_memory_client(CPUPhysMemoryClient *);
+
 uint32_t ldub_phys(target_phys_addr_t addr);
 uint32_t lduw_phys(target_phys_addr_t addr);
 uint32_t ldl_phys(target_phys_addr_t addr);
diff --git a/exec.c b/exec.c
index 76831a1..d713b72 100644
--- a/exec.c
+++ b/exec.c
@@ -1623,6 +1623,101 @@ const CPULogItem cpu_log_items[] = {
 { 0, NULL, NULL },
 };
 
+#ifndef CONFIG_USER_ONLY
+static QLIST_HEAD(memory_client_list, CPUPhysMemoryClient) memory_client_list
+= QLIST_HEAD_INITIALIZER(memory_client_list);
+
+static void cpu_notify_set_memory(target_phys_addr_t start_addr,
+ ram_addr_t size,
+ ram_addr_t phys_offset)
+{
+CPUPhysMemoryClient *client;
+QLIST_FOREACH(client, memory_client_list, list) {
+client-set_memory(client, start_addr, size, phys_offset);
+}
+}
+
+static int cpu_notify_sync_dirty_bitmap(target_phys_addr_t start,
+   target_phys_addr_t end)
+{
+CPUPhysMemoryClient *client;
+QLIST_FOREACH(client, memory_client_list, list) {
+int r = client-sync_dirty_bitmap(client, start, end);
+if (r  0)
+return r;
+}
+return 0;
+}
+
+static int cpu_notify_migration_log(int enable)
+{
+CPUPhysMemoryClient *client;
+QLIST_FOREACH(client, memory_client_list, list) {
+int r = client-migration_log(client, enable);
+if (r  0)
+return r;
+}
+return 0;
+}
+
+static void phys_page_for_each_in_l1_map(PhysPageDesc **phys_map,
+ CPUPhysMemoryClient *client)
+{
+PhysPageDesc *pd;
+int l1, l2;
+
+for (l1 = 0; l1  L1_SIZE; ++l1) {
+pd = phys_map[l1];
+if (!pd) {
+continue;
+}
+for (l2 = 0; l2  L2_SIZE; ++l2) {
+if (pd[l2].phys_offset == IO_MEM_UNASSIGNED) {
+continue;
+}
+client-set_memory(client, pd[l2].region_offset,
+   TARGET_PAGE_SIZE, pd[l2].phys_offset);
+}
+}
+}
+
+static void phys_page_for_each(CPUPhysMemoryClient *client)
+{
+#if TARGET_PHYS_ADDR_SPACE_BITS  32
+
+#if TARGET_PHYS_ADDR_SPACE_BITS  (32 + L1_BITS)
+#error unsupported TARGET_PHYS_ADDR_SPACE_BITS
+#endif
+void **phys_map = (void **)l1_phys_map;
+int l1;
+if (!l1_phys_map) {
+return;
+}
+for (l1 = 0; l1  L1_SIZE; ++l1) {
+if (phys_map[l1]) {
+phys_page_for_each_in_l1_map(phys_map[l1], client);
+}
+}
+#else
+if (!l1_phys_map) {
+return;
+}
+phys_page_for_each_in_l1_map(l1_phys_map, client);
+#endif
+}
+
+void cpu_register_phys_memory_client(CPUPhysMemoryClient *client)
+{
+QLIST_INSERT_HEAD(memory_client_list, client, list);
+phys_page_for_each(client);
+}
+
+void cpu_unregister_phys_memory_client(CPUPhysMemoryClient *client)
+{
+QLIST_REMOVE(client, list);
+}
+#endif
+
 static int cmp1(const char *s1, int n, const char *s2)
 {
 if (strlen(s2) != n)
@@ -1882,11 +1977,16 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, 
ram_addr_t end,
 
 int cpu_physical_memory_set_dirty_tracking(int enable)
 {
+int ret = 0;
 in_migration = enable;
 if (kvm_enabled()) {
-return 

[Qemu-devel] [PATCHv3 2/3] kvm: move kvm_set_phys_mem around

2010-01-27 Thread Michael S. Tsirkin
move kvm_set_phys_mem so that it will
be later available earlier in the file.
needed for next patch using memory notifiers.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
Acked-by: Avi Kivity a...@redhat.com
---
 kvm-all.c |  276 ++--
 1 files changed, 138 insertions(+), 138 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 15ec38e..4efb653 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -394,6 +394,144 @@ int kvm_check_extension(KVMState *s, unsigned int 
extension)
 return ret;
 }
 
+void kvm_set_phys_mem(target_phys_addr_t start_addr,
+  ram_addr_t size,
+  ram_addr_t phys_offset)
+{
+KVMState *s = kvm_state;
+ram_addr_t flags = phys_offset  ~TARGET_PAGE_MASK;
+KVMSlot *mem, old;
+int err;
+
+if (start_addr  ~TARGET_PAGE_MASK) {
+if (flags = IO_MEM_UNASSIGNED) {
+if (!kvm_lookup_overlapping_slot(s, start_addr,
+ start_addr + size)) {
+return;
+}
+fprintf(stderr, Unaligned split of a KVM memory slot\n);
+} else {
+fprintf(stderr, Only page-aligned memory slots supported\n);
+}
+abort();
+}
+
+/* KVM does not support read-only slots */
+phys_offset = ~IO_MEM_ROM;
+
+while (1) {
+mem = kvm_lookup_overlapping_slot(s, start_addr, start_addr + size);
+if (!mem) {
+break;
+}
+
+if (flags  IO_MEM_UNASSIGNED  start_addr = mem-start_addr 
+(start_addr + size = mem-start_addr + mem-memory_size) 
+(phys_offset - start_addr == mem-phys_offset - mem-start_addr)) {
+/* The new slot fits into the existing one and comes with
+ * identical parameters - nothing to be done. */
+return;
+}
+
+old = *mem;
+
+/* unregister the overlapping slot */
+mem-memory_size = 0;
+err = kvm_set_user_memory_region(s, mem);
+if (err) {
+fprintf(stderr, %s: error unregistering overlapping slot: %s\n,
+__func__, strerror(-err));
+abort();
+}
+
+/* Workaround for older KVM versions: we can't join slots, even not by
+ * unregistering the previous ones and then registering the larger
+ * slot. We have to maintain the existing fragmentation. Sigh.
+ *
+ * This workaround assumes that the new slot starts at the same
+ * address as the first existing one. If not or if some overlapping
+ * slot comes around later, we will fail (not seen in practice so far)
+ * - and actually require a recent KVM version. */
+if (s-broken_set_mem_region 
+old.start_addr == start_addr  old.memory_size  size 
+flags  IO_MEM_UNASSIGNED) {
+mem = kvm_alloc_slot(s);
+mem-memory_size = old.memory_size;
+mem-start_addr = old.start_addr;
+mem-phys_offset = old.phys_offset;
+mem-flags = 0;
+
+err = kvm_set_user_memory_region(s, mem);
+if (err) {
+fprintf(stderr, %s: error updating slot: %s\n, __func__,
+strerror(-err));
+abort();
+}
+
+start_addr += old.memory_size;
+phys_offset += old.memory_size;
+size -= old.memory_size;
+continue;
+}
+
+/* register prefix slot */
+if (old.start_addr  start_addr) {
+mem = kvm_alloc_slot(s);
+mem-memory_size = start_addr - old.start_addr;
+mem-start_addr = old.start_addr;
+mem-phys_offset = old.phys_offset;
+mem-flags = 0;
+
+err = kvm_set_user_memory_region(s, mem);
+if (err) {
+fprintf(stderr, %s: error registering prefix slot: %s\n,
+__func__, strerror(-err));
+abort();
+}
+}
+
+/* register suffix slot */
+if (old.start_addr + old.memory_size  start_addr + size) {
+ram_addr_t size_delta;
+
+mem = kvm_alloc_slot(s);
+mem-start_addr = start_addr + size;
+size_delta = mem-start_addr - old.start_addr;
+mem-memory_size = old.memory_size - size_delta;
+mem-phys_offset = old.phys_offset + size_delta;
+mem-flags = 0;
+
+err = kvm_set_user_memory_region(s, mem);
+if (err) {
+fprintf(stderr, %s: error registering suffix slot: %s\n,
+__func__, strerror(-err));
+abort();
+}
+}
+}
+
+/* in case the KVM bug workaround already consumed the new slot */
+if (!size)
+return;
+
+/* KVM does not need to know about this memory */
+if (flags = IO_MEM_UNASSIGNED)
+return;
+
+mem 

[Qemu-devel] [PATCHv3 3/3] kvm: move kvm to use memory notifiers

2010-01-27 Thread Michael S. Tsirkin
remove direct kvm calls from exec.c, make
kvm use memory notifiers framework instead.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
Acked-by: Avi Kivity a...@redhat.com
---
 exec.c|   17 +
 kvm-all.c |   40 ++--
 kvm.h |8 
 3 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/exec.c b/exec.c
index d713b72..2e7434e 100644
--- a/exec.c
+++ b/exec.c
@@ -1979,12 +1979,6 @@ int cpu_physical_memory_set_dirty_tracking(int enable)
 {
 int ret = 0;
 in_migration = enable;
-if (kvm_enabled()) {
-ret = kvm_set_migration_log(enable);
-}
-if (ret  0) {
-return ret;
-}
 ret = cpu_notify_migration_log(!!enable);
 return ret;
 }
@@ -1997,14 +1991,8 @@ int cpu_physical_memory_get_dirty_tracking(void)
 int cpu_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
target_phys_addr_t end_addr)
 {
-int ret = 0;
+int ret;
 
-if (kvm_enabled()) {
-ret = kvm_physical_sync_dirty_bitmap(start_addr, end_addr);
-}
-if (ret  0) {
-return ret;
-}
 ret = cpu_notify_sync_dirty_bitmap(start_addr, end_addr);
 return ret;
 }
@@ -2417,9 +2405,6 @@ void 
cpu_register_physical_memory_offset(target_phys_addr_t start_addr,
 ram_addr_t orig_size = size;
 void *subpage;
 
-if (kvm_enabled())
-kvm_set_phys_mem(start_addr, size, phys_offset);
-
 cpu_notify_set_memory(start_addr, size, phys_offset);
 
 if (phys_offset == IO_MEM_UNASSIGNED) {
diff --git a/kvm-all.c b/kvm-all.c
index 4efb653..a312654 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -257,7 +257,7 @@ int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t 
size)
   KVM_MEM_LOG_DIRTY_PAGES);
 }
 
-int kvm_set_migration_log(int enable)
+static int kvm_set_migration_log(int enable)
 {
 KVMState *s = kvm_state;
 KVMSlot *mem;
@@ -292,8 +292,8 @@ static int test_le_bit(unsigned long nr, unsigned char 
*addr)
  * @start_add: start of logged region.
  * @end_addr: end of logged region.
  */
-int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
-   target_phys_addr_t end_addr)
+static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
+ target_phys_addr_t end_addr)
 {
 KVMState *s = kvm_state;
 unsigned long size, allocated_size = 0;
@@ -394,9 +394,9 @@ int kvm_check_extension(KVMState *s, unsigned int extension)
 return ret;
 }
 
-void kvm_set_phys_mem(target_phys_addr_t start_addr,
-  ram_addr_t size,
-  ram_addr_t phys_offset)
+static void kvm_set_phys_mem(target_phys_addr_t start_addr,
+ram_addr_t size,
+ram_addr_t phys_offset)
 {
 KVMState *s = kvm_state;
 ram_addr_t flags = phys_offset  ~TARGET_PAGE_MASK;
@@ -532,6 +532,33 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr,
 }
 }
 
+static void kvm_client_set_memory(struct CPUPhysMemoryClient *client,
+ target_phys_addr_t start_addr,
+ ram_addr_t size,
+ ram_addr_t phys_offset)
+{
+   kvm_set_phys_mem(start_addr, size, phys_offset);
+}
+
+static int kvm_client_sync_dirty_bitmap(struct CPUPhysMemoryClient *client,
+   target_phys_addr_t start_addr,
+   target_phys_addr_t end_addr)
+{
+   return kvm_physical_sync_dirty_bitmap(start_addr, end_addr);
+}
+
+static int kvm_client_migration_log(struct CPUPhysMemoryClient *client,
+   int enable)
+{
+   return kvm_set_migration_log(enable);
+}
+
+static CPUPhysMemoryClient kvm_cpu_phys_memory_client = {
+   .set_memory = kvm_client_set_memory,
+   .sync_dirty_bitmap = kvm_client_sync_dirty_bitmap,
+   .migration_log = kvm_client_migration_log,
+};
+
 int kvm_init(int smp_cpus)
 {
 static const char upgrade_note[] =
@@ -628,6 +655,7 @@ int kvm_init(int smp_cpus)
 goto err;
 
 kvm_state = s;
+cpu_register_phys_memory_client(kvm_cpu_phys_memory_client);
 
 return 0;
 
diff --git a/kvm.h b/kvm.h
index 1c93ac5..672d511 100644
--- a/kvm.h
+++ b/kvm.h
@@ -35,16 +35,8 @@ int kvm_init_vcpu(CPUState *env);
 
 int kvm_cpu_exec(CPUState *env);
 
-void kvm_set_phys_mem(target_phys_addr_t start_addr,
-  ram_addr_t size,
-  ram_addr_t phys_offset);
-
-int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
-   target_phys_addr_t end_addr);
-
 int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size);
 int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size);
-int kvm_set_migration_log(int enable);
 
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
-- 

Re: [Qemu-devel] qemu-0.12.2 compiling error (on ppc32/ppc64): kvm.c:50: error: 'struct kvm_sregs' has no member named 'pvr'

2010-01-27 Thread acrux
On Mon, 25 Jan 2010 10:25:30 +0100
Alexander Graf ag...@suse.de wrote:

_omissis__
 
 Ugh. Please use --disable-kvm on such old kernel versions. KVM
 doesn't work on G4s (yet) anyway. I guess I'll need to add a minimum
 version check for KVM on ppc.
 
_cut__

thanks, it now compiles fine on both ppc32 and ppc64.

I've encuntered two issues under my quick test with CRUX PPC 2.6
(32bit) as host. This was my start command:

$ qemu-system-ppc -m 256 -localtime -hda 25a_qcow.img -cdrom
crux-ppc-2.5a.iso -boot d

The apple32 boot kernel on that iso image is linux-2.6.29.4
 
1) with -M g3beige it boots fine but segfaults loading the system.
2) with -M mac99 it boots but seems to be unable to find a proper IDE
device.

No problems, instead, with qemu-system-x86_64 when i
tried to install a guest linux x86 os on my ppc32 host.

greetings,
-- 
GNU/Linux on Power Architecture
CRUX PPC - http://cruxppc.org/



pgpO7l1Yr1cUd.pgp
Description: PGP signature


[Qemu-devel] Re: [RFC][PATCH] KVM: Introduce modification context for cpu_synchronize_state

2010-01-27 Thread Marcelo Tosatti
On Wed, Jan 27, 2010 at 03:54:08PM +0100, Jan Kiszka wrote:
 This patch originates in the mp_state writeback issue: During runtime
 and even on reset, we must not write the previously saved VCPU state
 back into the kernel in an uncontrolled fashion. E.g mp_state should
 only written on reset or on VCPU setup. Certain clocks (e.g. the TSC)
 may only be written on setup or after vmload.
 
 By introducing additional information about the context of the planned
 vcpu state manipulation, we can simply skip sensitive states like
 mp_state when updating the in-kernel state. The planned modifications
 are defined when calling cpu_synchronize_state. They accumulate, ie.
 once a full writeback was requested, it will stick until it was
 performed.
 
 This patch already fixes existing writeback issues in upstream KVM by
 only selectively writing MSR_IA32_TSC, MSR_KVM_SYSTEM_TIME,
 MSR_KVM_WALL_CLOCK, the mp_state and the vcpu_events.
 
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
 
 This patch is intentionally written against uq/master. As upstream is
 less convoluted (yet :) ), it may help understanding the basic idea. An
 add-on patch for qemu-kvm that both cleans up the current code and also
 moves kvm_get/set_lapic into kvm_arch_get/put_registers (hmm, maybe also
 renaming that services...) will follow soon if no one sees fundamental
 problems of this approach.
 
  exec.c|4 ++--
  gdbstub.c |   10 +-
  hw/apic.c |2 +-
  hw/ppc_newworld.c |2 +-
  hw/ppc_oldworld.c |2 +-
  hw/s390-virtio.c  |2 +-
  kvm-all.c |   31 +++
  kvm.h |   13 +
  monitor.c |4 ++--
  target-i386/helper.c  |2 +-
  target-i386/kvm.c |   31 +++
  target-i386/machine.c |4 ++--
  target-ppc/kvm.c  |2 +-
  target-ppc/machine.c  |4 ++--
  target-s390x/kvm.c|   17 -
  15 files changed, 78 insertions(+), 52 deletions(-)

 diff --git a/kvm-all.c b/kvm-all.c
 index f8350c9..8595cd9 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -57,7 +57,8 @@ struct KVMState
  KVMSlot slots[32];
  int fd;
  int vmfd;
 -int regs_modified;
 +int synchronized;
 +int pending_modifications;
  int coalesced_mmio;
  #ifdef KVM_CAP_COALESCED_MMIO
  struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;

Should be per-vcpu.

 @@ -155,10 +156,12 @@ static void kvm_reset_vcpu(void *opaque)
  CPUState *env = opaque;
  
  kvm_arch_reset_vcpu(env);
 -if (kvm_arch_put_registers(env)) {
 +if (kvm_arch_put_registers(env, env-kvm_state-pending_modifications
 +| CPU_MODIFY_RESET)) {
  fprintf(stderr, Fatal: kvm vcpu reset failed\n);
  abort();
  }
 +env-kvm_state-pending_modifications = CPU_MODIFY_NONE;

Can't the writeback here happen at exec_cpu?

 @@ -946,9 +953,9 @@ static void kvm_invoke_set_guest_debug(void *data)
  struct kvm_set_guest_debug_data *dbg_data = data;
  CPUState *env = dbg_data-env;
  
 -if (env-kvm_state-regs_modified) {
 -kvm_arch_put_registers(env);
 -env-kvm_state-regs_modified = 0;
 +if (env-kvm_state-pending_modifications) {
 +kvm_arch_put_registers(env, env-kvm_state-pending_modifications);
 +env-kvm_state-pending_modifications = CPU_MODIFY_NONE;
  }

Why's synchronous writeback needed here?

Otherwise seems fine.





[Qemu-devel] [PATCH] sparc64: reimplement tick timers v4

2010-01-27 Thread Igor V. Kovalenko
From: Igor V. Kovalenko igor.v.kovale...@gmail.com

sparc64 timer has tick counter which can be set and read,
and tick compare value used as deadline to fire timer interrupt.
The timer is not used as periodic timer, instead deadline
is set each time new timer interrupt is needed.

v3 - v4:
- coding style

v2 - v3:
- added missing timer debug output macro
- CPUTimer struct and typedef moved to cpu.h
- change CPU_SAVE_VERSION to 6, older save formats not supported

v1 - v2:
- new conversion helpers cpu_to_timer_ticks and timer_to_cpu_ticks
- save offset from clock source to implement cpu_tick_set_count
- renamed struct sun4u_timer to CPUTimer
- load and save cpu timers

v0 - v1:
- coding style

Signed-off-by: Igor V. Kovalenko igor.v.kovale...@gmail.com
---
 hw/sun4u.c |  206 
 target-sparc/cpu.h |   28 +--
 target-sparc/machine.c |   14 ++-
 3 files changed, 202 insertions(+), 46 deletions(-)

diff --git a/hw/sun4u.c b/hw/sun4u.c
index c1530a6..1e01123 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -40,6 +40,7 @@
 
 //#define DEBUG_IRQ
 //#define DEBUG_EBUS
+//#define DEBUG_TIMER
 
 #ifdef DEBUG_IRQ
 #define CPUIRQ_DPRINTF(fmt, ...)\
@@ -55,6 +56,13 @@
 #define EBUS_DPRINTF(fmt, ...)
 #endif
 
+#ifdef DEBUG_TIMER
+#define TIMER_DPRINTF(fmt, ...)  \
+do { printf(TIMER:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define TIMER_DPRINTF(fmt, ...)
+#endif
+
 #define KERNEL_LOAD_ADDR 0x00404000
 #define CMDLINE_ADDR 0x003ff000
 #define INITRD_LOAD_ADDR 0x0030
@@ -282,6 +290,12 @@ void cpu_check_irqs(CPUState *env)
 }
 }
 
+static void cpu_kick_irq(CPUState *env)
+{
+env-halted = 0;
+cpu_check_irqs(env);
+}
+
 static void cpu_set_irq(void *opaque, int irq, int level)
 {
 CPUState *env = opaque;
@@ -303,6 +317,52 @@ typedef struct ResetData {
 uint64_t prom_addr;
 } ResetData;
 
+void cpu_put_timer(QEMUFile *f, CPUTimer *s)
+{
+qemu_put_be32s(f, s-frequency);
+qemu_put_be32s(f, s-disabled);
+qemu_put_be64s(f, s-disabled_mask);
+qemu_put_sbe64s(f, s-clock_offset);
+
+qemu_put_timer(f, s-qtimer);
+}
+
+void cpu_get_timer(QEMUFile *f, CPUTimer *s)
+{
+qemu_get_be32s(f, s-frequency);
+qemu_get_be32s(f, s-disabled);
+qemu_get_be64s(f, s-disabled_mask);
+qemu_get_sbe64s(f, s-clock_offset);
+
+qemu_get_timer(f, s-qtimer);
+}
+
+static CPUTimer* cpu_timer_create(const char* name, CPUState *env,
+  QEMUBHFunc *cb, uint32_t frequency,
+  uint64_t disabled_mask)
+{
+CPUTimer *timer = qemu_mallocz(sizeof (CPUTimer));
+
+timer-name = name;
+timer-frequency = frequency;
+timer-disabled_mask = disabled_mask;
+
+timer-disabled = 1;
+timer-clock_offset = qemu_get_clock(vm_clock);
+
+timer-qtimer = qemu_new_timer(vm_clock, cb, env);
+
+return timer;
+}
+
+static void cpu_timer_reset(CPUTimer *timer)
+{
+timer-disabled = 1;
+timer-clock_offset = qemu_get_clock(vm_clock);
+
+qemu_del_timer(timer-qtimer);
+}
+
 static void main_cpu_reset(void *opaque)
 {
 ResetData *s = (ResetData *)opaque;
@@ -310,15 +370,11 @@ static void main_cpu_reset(void *opaque)
 static unsigned int nr_resets;
 
 cpu_reset(env);
-env-tick_cmpr = TICK_INT_DIS | 0;
-ptimer_set_limit(env-tick, TICK_MAX, 1);
-ptimer_run(env-tick, 1);
-env-stick_cmpr = TICK_INT_DIS | 0;
-ptimer_set_limit(env-stick, TICK_MAX, 1);
-ptimer_run(env-stick, 1);
-env-hstick_cmpr = TICK_INT_DIS | 0;
-ptimer_set_limit(env-hstick, TICK_MAX, 1);
-ptimer_run(env-hstick, 1);
+
+cpu_timer_reset(env-tick);
+cpu_timer_reset(env-stick);
+cpu_timer_reset(env-hstick);
+
 env-gregs[1] = 0; // Memory start
 env-gregs[2] = ram_size; // Memory size
 env-gregs[3] = 0; // Machine description XXX
@@ -335,44 +391,127 @@ static void tick_irq(void *opaque)
 {
 CPUState *env = opaque;
 
-if (!(env-tick_cmpr  TICK_INT_DIS)) {
-env-softint |= SOFTINT_TIMER;
-cpu_interrupt(env, CPU_INTERRUPT_TIMER);
+CPUTimer* timer = env-tick;
+
+if (timer-disabled) {
+CPUIRQ_DPRINTF(tick_irq: softint disabled\n);
+return;
+} else {
+CPUIRQ_DPRINTF(tick: fire\n);
 }
+
+env-softint |= SOFTINT_TIMER;
+cpu_kick_irq(env);
 }
 
 static void stick_irq(void *opaque)
 {
 CPUState *env = opaque;
 
-if (!(env-stick_cmpr  TICK_INT_DIS)) {
-env-softint |= SOFTINT_STIMER;
-cpu_interrupt(env, CPU_INTERRUPT_TIMER);
+CPUTimer* timer = env-stick;
+
+if (timer-disabled) {
+CPUIRQ_DPRINTF(stick_irq: softint disabled\n);
+return;
+} else {
+CPUIRQ_DPRINTF(stick: fire\n);
 }
+
+env-softint |= SOFTINT_STIMER;
+cpu_kick_irq(env);
 }
 
 static void hstick_irq(void *opaque)
 {
 CPUState *env = opaque;
 
-if 

Re: [Qemu-devel] [Patch] Support translating Guest physical address to Host virtual address.

2010-01-27 Thread Anthony Liguori

On 01/26/2010 09:25 PM, Zheng, Jiajia wrote:

Add command p2v to translate Guest physical address to Host virtual address.
   


For what purpose?


Signed-off-by: Max Asbockmasb...@linux.vnet.ibm.com
Jiajia Zhengjiajia.zh...@intel.com
---
diff --git a/monitor.c b/monitor.c
index b33b01f..83d9ac7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -668,6 +668,11 @@ static void do_info_uuid(Monitor *mon, QObject **ret_data)
  *ret_data = qobject_from_jsonf({ 'UUID': %s }, uuid);
  }

+static void do_info_p2v(Monitor *mon)
+{
+monitor_printf(mon, p2v implemented\n);
+}
   


These should be implemented as QMP commands.


  /* get the current CPU defined by the user */
  static int mon_set_cpu(int cpu_index)
  {
@@ -2283,6 +2288,14 @@ static void do_inject_mce(Monitor *mon, const QDict 
*qdict)
  break;
  }
  }
+static void do_p2v(Monitor *mon, const QDict *qdict)
+{
+target_long size = 4096;
+target_long addr = qdict_get_int(qdict, addr);
+
+monitor_printf(mon, Guest physical address %p is mapped at host virtual address 
%p\n, (void *)addr, cpu_physical_memory_map( (target_phys_addr_t)addr, 
(target_phys_addr_t *)size, 0));
   


This isn't quite right.  It assumes TARGET_PAGE_SIZE is 4k which is 
certainly not always true.  It also assumes that 
cpu_physical_memory_map() something that has some meaning which isn't 
necessarily the case.  It could be a pointer to a bounce buffer.


Could you give an end-to-end description of how you expect this 
mechanism to be used so we can work out a more appropriate set of 
interfaces.  I assume this is MCE related.


Regards,

Anthony Liguori




Re: [Qemu-devel] [PATCH] sparc64: reimplement tick timers v4

2010-01-27 Thread Blue Swirl
Thanks, applied.


On Wed, Jan 27, 2010 at 9:00 PM, Igor V. Kovalenko
igor.v.kovale...@gmail.com wrote:
 From: Igor V. Kovalenko igor.v.kovale...@gmail.com

 sparc64 timer has tick counter which can be set and read,
 and tick compare value used as deadline to fire timer interrupt.
 The timer is not used as periodic timer, instead deadline
 is set each time new timer interrupt is needed.

 v3 - v4:
 - coding style

 v2 - v3:
 - added missing timer debug output macro
 - CPUTimer struct and typedef moved to cpu.h
 - change CPU_SAVE_VERSION to 6, older save formats not supported

 v1 - v2:
 - new conversion helpers cpu_to_timer_ticks and timer_to_cpu_ticks
 - save offset from clock source to implement cpu_tick_set_count
 - renamed struct sun4u_timer to CPUTimer
 - load and save cpu timers

 v0 - v1:
 - coding style

 Signed-off-by: Igor V. Kovalenko igor.v.kovale...@gmail.com
 ---
  hw/sun4u.c             |  206 
 
  target-sparc/cpu.h     |   28 +--
  target-sparc/machine.c |   14 ++-
  3 files changed, 202 insertions(+), 46 deletions(-)

 diff --git a/hw/sun4u.c b/hw/sun4u.c
 index c1530a6..1e01123 100644
 --- a/hw/sun4u.c
 +++ b/hw/sun4u.c
 @@ -40,6 +40,7 @@

  //#define DEBUG_IRQ
  //#define DEBUG_EBUS
 +//#define DEBUG_TIMER

  #ifdef DEBUG_IRQ
  #define CPUIRQ_DPRINTF(fmt, ...)                                \
 @@ -55,6 +56,13 @@
  #define EBUS_DPRINTF(fmt, ...)
  #endif

 +#ifdef DEBUG_TIMER
 +#define TIMER_DPRINTF(fmt, ...)                                  \
 +    do { printf(TIMER:  fmt , ## __VA_ARGS__); } while (0)
 +#else
 +#define TIMER_DPRINTF(fmt, ...)
 +#endif
 +
  #define KERNEL_LOAD_ADDR     0x00404000
  #define CMDLINE_ADDR         0x003ff000
  #define INITRD_LOAD_ADDR     0x0030
 @@ -282,6 +290,12 @@ void cpu_check_irqs(CPUState *env)
     }
  }

 +static void cpu_kick_irq(CPUState *env)
 +{
 +    env-halted = 0;
 +    cpu_check_irqs(env);
 +}
 +
  static void cpu_set_irq(void *opaque, int irq, int level)
  {
     CPUState *env = opaque;
 @@ -303,6 +317,52 @@ typedef struct ResetData {
     uint64_t prom_addr;
  } ResetData;

 +void cpu_put_timer(QEMUFile *f, CPUTimer *s)
 +{
 +    qemu_put_be32s(f, s-frequency);
 +    qemu_put_be32s(f, s-disabled);
 +    qemu_put_be64s(f, s-disabled_mask);
 +    qemu_put_sbe64s(f, s-clock_offset);
 +
 +    qemu_put_timer(f, s-qtimer);
 +}
 +
 +void cpu_get_timer(QEMUFile *f, CPUTimer *s)
 +{
 +    qemu_get_be32s(f, s-frequency);
 +    qemu_get_be32s(f, s-disabled);
 +    qemu_get_be64s(f, s-disabled_mask);
 +    qemu_get_sbe64s(f, s-clock_offset);
 +
 +    qemu_get_timer(f, s-qtimer);
 +}
 +
 +static CPUTimer* cpu_timer_create(const char* name, CPUState *env,
 +                                  QEMUBHFunc *cb, uint32_t frequency,
 +                                  uint64_t disabled_mask)
 +{
 +    CPUTimer *timer = qemu_mallocz(sizeof (CPUTimer));
 +
 +    timer-name = name;
 +    timer-frequency = frequency;
 +    timer-disabled_mask = disabled_mask;
 +
 +    timer-disabled = 1;
 +    timer-clock_offset = qemu_get_clock(vm_clock);
 +
 +    timer-qtimer = qemu_new_timer(vm_clock, cb, env);
 +
 +    return timer;
 +}
 +
 +static void cpu_timer_reset(CPUTimer *timer)
 +{
 +    timer-disabled = 1;
 +    timer-clock_offset = qemu_get_clock(vm_clock);
 +
 +    qemu_del_timer(timer-qtimer);
 +}
 +
  static void main_cpu_reset(void *opaque)
  {
     ResetData *s = (ResetData *)opaque;
 @@ -310,15 +370,11 @@ static void main_cpu_reset(void *opaque)
     static unsigned int nr_resets;

     cpu_reset(env);
 -    env-tick_cmpr = TICK_INT_DIS | 0;
 -    ptimer_set_limit(env-tick, TICK_MAX, 1);
 -    ptimer_run(env-tick, 1);
 -    env-stick_cmpr = TICK_INT_DIS | 0;
 -    ptimer_set_limit(env-stick, TICK_MAX, 1);
 -    ptimer_run(env-stick, 1);
 -    env-hstick_cmpr = TICK_INT_DIS | 0;
 -    ptimer_set_limit(env-hstick, TICK_MAX, 1);
 -    ptimer_run(env-hstick, 1);
 +
 +    cpu_timer_reset(env-tick);
 +    cpu_timer_reset(env-stick);
 +    cpu_timer_reset(env-hstick);
 +
     env-gregs[1] = 0; // Memory start
     env-gregs[2] = ram_size; // Memory size
     env-gregs[3] = 0; // Machine description XXX
 @@ -335,44 +391,127 @@ static void tick_irq(void *opaque)
  {
     CPUState *env = opaque;

 -    if (!(env-tick_cmpr  TICK_INT_DIS)) {
 -        env-softint |= SOFTINT_TIMER;
 -        cpu_interrupt(env, CPU_INTERRUPT_TIMER);
 +    CPUTimer* timer = env-tick;
 +
 +    if (timer-disabled) {
 +        CPUIRQ_DPRINTF(tick_irq: softint disabled\n);
 +        return;
 +    } else {
 +        CPUIRQ_DPRINTF(tick: fire\n);
     }
 +
 +    env-softint |= SOFTINT_TIMER;
 +    cpu_kick_irq(env);
  }

  static void stick_irq(void *opaque)
  {
     CPUState *env = opaque;

 -    if (!(env-stick_cmpr  TICK_INT_DIS)) {
 -        env-softint |= SOFTINT_STIMER;
 -        cpu_interrupt(env, CPU_INTERRUPT_TIMER);
 +    CPUTimer* timer = env-stick;
 +
 +    if (timer-disabled) {
 +        CPUIRQ_DPRINTF(stick_irq: softint 

Re: [Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

2010-01-27 Thread Anthony Liguori

On 01/27/2010 05:56 AM, Paolo Bonzini wrote:

On 01/27/2010 03:10 AM, Anthony Liguori wrote:

What did clang complain about?  It's not obvious to me.


It doesn't see that audio_bug returns cond, and gives quite a few 
false positive in its callers.


Ah, this is a clang issue.  I'll have to defer to malc on this one.

Regards,

Anthony Liguori


Paolo










[Qemu-devel] Re: [PATCHv2] configure: verify stdio.h

2010-01-27 Thread Måns Rullgård
Michael S. Tsirkin m...@redhat.com writes:

 Heh, configure script runs the program it's built
 in a couple of places. This probably does not
 work for cross-builds:

   if compile_prog   ; then
   $TMPE  bigendian=yes
   else
   echo big/little test failed
   fi

 likely works by luck for build to intel, because error
 is interpreted as little-endian.

In FFmpeg we check the endianness like this:

check_cc EOF || die endian test failed
unsigned int endian = 'B'  24 | 'I'  16 | 'G'  8 | 'E';
EOF
od -t x1 $TMPO | grep -q '42 *49 *47 *45'  enable bigendian

This works on every combination of build and target system we use.

-- 
Måns Rullgård
m...@mansr.com





Re: [Qemu-devel] [PATCH] sparc64: reimplement tick timers v4

2010-01-27 Thread Blue Swirl
On Wed, Jan 27, 2010 at 9:00 PM, Igor V. Kovalenko
igor.v.kovale...@gmail.com wrote:
 From: Igor V. Kovalenko igor.v.kovale...@gmail.com

 sparc64 timer has tick counter which can be set and read,
 and tick compare value used as deadline to fire timer interrupt.
 The timer is not used as periodic timer, instead deadline
 is set each time new timer interrupt is needed.

Now also IDE probe succeeds, almost:

cmd64x :00:05.0: IDE controller (0x1095:0x0646 rev 0x07)
cmd64x :00:05.0: 100% native mode on irq 1
ide0: BM-DMA at 0x1fe02000700-0x1fe02000707
ide1: BM-DMA at 0x1fe02000708-0x1fe0200070f
hdc: EQUMD DVR-MO, ATAPI cdrom or floppy?, assuming FLOPPY drive
ide0 at 0x1fe02000500-0x1fe02000507,0x1fe02000582 on irq 1 (serialized)
ide1 at 0x1fe02000600-0x1fe02000607,0x1fe02000682 on irq 1 (serialized)
ide-gd driver 1.18




Re: [Qemu-devel] qemu-0.12.2 compiling error (on ppc32/ppc64): kvm.c:50: error: 'struct kvm_sregs' has no member named 'pvr'

2010-01-27 Thread Alexander Graf


Am 27.01.2010 um 20:17 schrieb acrux acrux...@libero.it:


On Mon, 25 Jan 2010 10:25:30 +0100
Alexander Graf ag...@suse.de wrote:

_omissis__


Ugh. Please use --disable-kvm on such old kernel versions. KVM
doesn't work on G4s (yet) anyway. I guess I'll need to add a minimum
version check for KVM on ppc.


_cut__

thanks, it now compiles fine on both ppc32 and ppc64.

I've encuntered two issues under my quick test with CRUX PPC 2.6
(32bit) as host. This was my start command:

$ qemu-system-ppc -m 256 -localtime -hda 25a_qcow.img -cdrom
crux-ppc-2.5a.iso -boot d

The apple32 boot kernel on that iso image is linux-2.6.29.4

1) with -M g3beige it boots fine but segfaults loading the system.


Please use gdb's backtrace feature to find out why/where it breaks.


2) with -M mac99 it boots but seems to be unable to find a proper IDE
device.


Yeah, that's because your guest kernel doesn't have cmd64x support  
compiled in.


Alex




Re: [Qemu-devel] qemu-0.12.2 compiling error (on ppc32/ppc64): kvm.c:50: error: 'struct kvm_sregs' has no member named 'pvr'

2010-01-27 Thread acrux
On Thu, 28 Jan 2010 00:30:23 +0100
Alexander Graf ag...@suse.de wrote:

_omissis__
  I've encuntered two issues under my quick test with CRUX PPC 2.6
  (32bit) as host. This was my start command:
 
  $ qemu-system-ppc -m 256 -localtime -hda 25a_qcow.img -cdrom
  crux-ppc-2.5a.iso -boot d
 
  The apple32 boot kernel on that iso image is linux-2.6.29.4
 
  1) with -M g3beige it boots fine but segfaults loading the system.
 
 Please use gdb's backtrace feature to find out why/where it breaks.
 

ok, i'll give a try

  2) with -M mac99 it boots but seems to be unable to find a proper
  IDE device.
 
 Yeah, that's because your guest kernel doesn't have cmd64x support  
 compiled in.
 

it's the same bootkernel as above with cmd64x module builtin therefore
it's an unexpected error.

--acrux
-- 
GNU/Linux on Power Architecture
CRUX PPC - http://cruxppc.org/



pgpcXeoH1FDmh.pgp
Description: PGP signature


Re: [Qemu-devel] [Patch] Support translating Guest physical address to Host virtual address.

2010-01-27 Thread Max Asbock
On Wed, 2010-01-27 at 15:39 -0600, Anthony Liguori wrote:
 On 01/26/2010 09:25 PM, Zheng, Jiajia wrote:
  Add command p2v to translate Guest physical address to Host virtual address.
 
 
 For what purpose?
 
  Signed-off-by: Max Asbockmasb...@linux.vnet.ibm.com
  Jiajia Zhengjiajia.zh...@intel.com
  ---
  diff --git a/monitor.c b/monitor.c
  index b33b01f..83d9ac7 100644
  --- a/monitor.c
  +++ b/monitor.c
  @@ -668,6 +668,11 @@ static void do_info_uuid(Monitor *mon, QObject 
  **ret_data)
*ret_data = qobject_from_jsonf({ 'UUID': %s }, uuid);
}
 
  +static void do_info_p2v(Monitor *mon)
  +{
  +monitor_printf(mon, p2v implemented\n);
  +}
 
 
 These should be implemented as QMP commands.
 
/* get the current CPU defined by the user */
static int mon_set_cpu(int cpu_index)
{
  @@ -2283,6 +2288,14 @@ static void do_inject_mce(Monitor *mon, const QDict 
  *qdict)
break;
}
}
  +static void do_p2v(Monitor *mon, const QDict *qdict)
  +{
  +target_long size = 4096;
  +target_long addr = qdict_get_int(qdict, addr);
  +
  +monitor_printf(mon, Guest physical address %p is mapped at host 
  virtual address %p\n, (void *)addr, cpu_physical_memory_map( 
  (target_phys_addr_t)addr, (target_phys_addr_t *)size, 0));
 
 
 This isn't quite right.  It assumes TARGET_PAGE_SIZE is 4k which is 
 certainly not always true.  It also assumes that 
 cpu_physical_memory_map() something that has some meaning which isn't 
 necessarily the case.  It could be a pointer to a bounce buffer.
 
 Could you give an end-to-end description of how you expect this 
 mechanism to be used so we can work out a more appropriate set of 
 interfaces.  I assume this is MCE related.
 

The purpose of this is to translate a guest physical address to a host
virtual address. 
This was indeed used for MCE testing. The p2v command provides one step
in a chain of translations from guest virtual to guest physical to host
virtual to host physical. Host physical is then used to inject a machine
check error. As a consequence the HPOISON code on the host and the MCE
injection code in qemu are exercised.
I was always assuming that this implementation perhaps isn't the most
optimal, but it simply worked for our test case.

What would an appropriate method be to get a host virtual address for
guest physical address that represents a page of RAM?

thanks,
Max





[Qemu-devel] Re: [PATCH] Seabios - read e820 table from qemu_cfg

2010-01-27 Thread Kevin O'Connor
On Tue, Jan 26, 2010 at 10:52:12PM +0100, Jes Sorensen wrote:
 Read optional table of e820 entries from qemu_cfg
[...]
 --- seabios.orig/src/paravirt.c
 +++ seabios/src/paravirt.c
 @@ -132,6 +132,23 @@ u16 qemu_cfg_smbios_entries(void)
  return cnt;
  }
  
 +u32 qemu_cfg_e820_entries(void)
 +{
 +u32 cnt;
 +
 +if (!qemu_cfg_present)
 +return 0;
 +
 +qemu_cfg_read_entry(cnt, QEMU_CFG_E820_TABLE, sizeof(cnt));
 +return cnt;
 +}
 +
 +void* qemu_cfg_e820_load_next(void *addr)
 +{
 +qemu_cfg_read(addr, sizeof(struct e820_entry));
 +return addr;
 +}

I think defining accessor functions for every piece of data passed
through qemu-cfg interface is going to get tiring.  I'd prefer to
extend the existing qemu-cfg file interface for new content.

For example, add a helper with something like:

int qemu_cfg_get_file(const char *name, void *dest, int maxsize);

 -if (kvm_para_available())
 -// 4 pages before the bios, 3 pages for vmx tss pages, the
 -// other page for EPT real mode pagetable
 -add_e820(0xfffbc000, 4*4096, E820_RESERVED);
 +if (kvm_para_available()) {
 +u32 count;
 +
 +count = qemu_cfg_e820_entries();
 +if (count) {
 +struct e820_entry entry;
 +int i;
 +
 +for (i = 0; i  count; i++) {
 +qemu_cfg_e820_load_next(entry);
 +add_e820(entry.address, entry.length, entry.type);
 +}

and then this becomes:

struct e820entry map[128];
int len = qemu_cfg_get_file(e820map, map, sizeof(map));
if (len = 0)
for (i=0; ilen / sizeof(map[0]); i++)
add_e820(map[i].start, map[i].size, map[i].type);

The advantage being that it should be possible to write one set of
helper functions in both qemu and seabios that can then be used to
pass arbitrary content.

As a side note, it should probably do the e820 map check even for qemu
users (ie, not just kvm).

-Kevin




[Qemu-devel] [PATCH] Fix qemu-img can't create qcow image based on read-only image

2010-01-27 Thread Sheng Yang
Commit 03cbdac7 Disable fall-back to read-only when cannot open drive's
file for read-write result in read-only image can't be used as backed
image in qemu-img.

CC: Naphtali Sprei nsp...@redhat.com
Signed-off-by: Sheng Yang sh...@linux.intel.com
---

This issue blocked our QA's KVM nightly test. But in fact, I don't like this
patch, feeling uncomfortable to change long existed interface... Any
alternative? Add a readonly command line would change the default behavior(I
don't think fall back to readonly looks like a bug); or even revert the
commit? What's the story behind it?

 qemu-img.c |   15 ++-
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 3cea8ce..f8be5cb 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -188,11 +188,13 @@ static int read_password(char *buf, int buf_size)
 #endif
 
 static BlockDriverState *bdrv_new_open(const char *filename,
-   const char *fmt)
+   const char *fmt,
+   int readonly)
 {
 BlockDriverState *bs;
 BlockDriver *drv;
 char password[256];
+int flags = BRDV_O_FLAGS;
 
 bs = bdrv_new();
 if (!bs)
@@ -204,7 +206,10 @@ static BlockDriverState *bdrv_new_open(const char 
*filename,
 } else {
 drv = NULL;
 }
-if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv)  0) {
+if (!readonly) {
+flags |= BDRV_O_RDWR;
+}
+if (bdrv_open2(bs, filename, flags, drv)  0) {
 error(Could not open '%s', filename);
 }
 if (bdrv_is_encrypted(bs)) {
@@ -343,7 +348,7 @@ static int img_create(int argc, char **argv)
 }
 }
 
-bs = bdrv_new_open(backing_file-value.s, fmt);
+bs = bdrv_new_open(backing_file-value.s, fmt, 1);
 bdrv_get_geometry(bs, size);
 size *= 512;
 bdrv_delete(bs);
@@ -627,7 +632,7 @@ static int img_convert(int argc, char **argv)
 
 total_sectors = 0;
 for (bs_i = 0; bs_i  bs_n; bs_i++) {
-bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
+bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 0);
 if (!bs[bs_i])
 error(Could not open '%s', argv[optind + bs_i]);
 bdrv_get_geometry(bs[bs_i], bs_sectors);
@@ -685,7 +690,7 @@ static int img_convert(int argc, char **argv)
 }
 }
 
-out_bs = bdrv_new_open(out_filename, out_fmt);
+out_bs = bdrv_new_open(out_filename, out_fmt, 0);
 
 bs_i = 0;
 bs_offset = 0;
-- 
1.5.4.5